sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
| 1 | # 2023 May 13 |
| 2 | # |
| 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
| 5 | # |
| 6 | # May you do good and not evil. |
| 7 | # May you find forgiveness for yourself and forgive others. |
| 8 | # May you share freely, never taking more than you give. |
| 9 | # |
| 10 | #*********************************************************************** |
| 11 | # |
| 12 | |
| 13 | set testdir [file dirname $argv0] |
| 14 | |
| 15 | source $testdir/tester.tcl |
| 16 | source $testdir/lock_common.tcl |
| 17 | if {[run_thread_tests]==0} { finish_test ; return } |
| 18 | |
| 19 | set testprefix thread3 |
| 20 | |
| 21 | do_execsql_test 1.0 { |
| 22 | CREATE TABLE t1(a, b); |
| 23 | PRAGMA journal_mode = DELETE; |
| 24 | } {delete} |
| 25 | |
| 26 | proc wait_for_var {varname} { |
| 27 | if {0==[uplevel [list info exists $varname]]} { |
| 28 | uplevel [list vwait $varname] |
| 29 | } |
| 30 | uplevel [list set $varname] |
| 31 | } |
| 32 | |
| 33 | set nAttempt 250 |
| 34 | |
| 35 | do_test 1.1 { |
| 36 | for {set i 0} {$i < $nAttempt} {incr i} { |
| 37 | unset -nocomplain X |
| 38 | unset -nocomplain Y |
| 39 | |
| 40 | sqlthread spawn X { |
| 41 | sqlite3 dbI test.db |
| 42 | dbI timeout 100 |
| 43 | set rc 1 |
| 44 | set nBusy 0 |
| 45 | while {$rc} { |
| 46 | set rc [catch { |
| 47 | dbI eval { INSERT INTO t1 VALUES(203, 'message') RETURNING a; } |
| 48 | } msg] |
| 49 | if {$rc} { incr nBusy } |
| 50 | } |
| 51 | dbI close |
| 52 | set nBusy |
| 53 | } |
| 54 | |
| 55 | sqlthread spawn Y { |
| 56 | sqlite3 dbR test.db |
| 57 | catch { |
| 58 | dbR eval { SELECT count(*) FROM t1 } |
| 59 | } msg |
| 60 | dbR close |
| 61 | set msg |
| 62 | } |
| 63 | |
| 64 | wait_for_var X |
| 65 | wait_for_var Y |
| 66 | incr nTotalBusy $X |
| 67 | } |
| 68 | |
| 69 | execsql { SELECT count(*) FROM t1 } |
| 70 | set {} {} |
| 71 | } {} |
| 72 | |
| 73 | do_execsql_test "1.Total BUSY errors: $nTotalBusy .2" { |
| 74 | SELECT count(*) FROM t1; |
| 75 | } $nAttempt |
| 76 | |
| 77 | finish_test |