3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file test the busy handler
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 source $testdir/lock_common.tcl
21 do_multiclient_test tn {
24 CREATE TABLE t1(a, b);
25 PRAGMA journal_mode = wal;
26 INSERT INTO t1 VALUES('A', 'B');
31 code1 { db timeout 1000 }
32 sql1 { SELECT * FROM t1 }
38 INSERT INTO t1 VALUES('C', 'D');
43 set us [lindex [time { catch { sql1 { BEGIN EXCLUSIVE } } }] 0]
44 expr {$us>950000 && $us<1500000}
54 #-------------------------------------------------------------------------
56 do_multiclient_test tn {
57 # Make the db a WAL mode db. And add a table and a row to it. Then open
58 # a second connection within process 1. Process 1 now has connections
59 # [db] and [db1.2], process 2 has connection [db2] only.
61 # Configure all connections to use a 1000 ms timeout.
68 PRAGMA auto_vacuum = off;
69 PRAGMA journal_mode = wal;
70 CREATE TABLE t1(a, b);
71 INSERT INTO t1 VALUES(1, 2);
79 db1.2 eval {SELECT * FROM t1}
83 # Take a read lock with [db] in process 1.
92 # Insert a row using [db2] in process 2. Then try a passive checkpoint.
93 # It fails to checkpoint the final frame (due to the readlock taken by
94 # [db]), and returns in less than 250ms.
96 sql2 { INSERT INTO t1 VALUES(3, 4) }
97 set us [lindex [time {
98 set res [code2 { db2 eval { PRAGMA wal_checkpoint } }]
100 list [expr $us < 250000] $res
103 # Now try a FULL checkpoint with [db2]. It returns SQLITE_BUSY. And takes
104 # over 950ms to do so.
106 set us [lindex [time {
107 set res [code2 { db2 eval { PRAGMA wal_checkpoint = FULL } }]
109 list [expr $us > 950000] $res
112 # Passive checkpoint with [db1.2] (process 1). No SQLITE_BUSY, returns
115 set us [lindex [time {
116 set res [code1 { db1.2 eval { PRAGMA wal_checkpoint } }]
118 list [expr $us < 250000] $res
121 # Full checkpoint with [db1.2] (process 1). SQLITE_BUSY returned in
124 set us [lindex [time {
125 set res [code1 { db1.2 eval { PRAGMA wal_checkpoint = FULL } }]
127 list [expr $us > 950000] $res
135 #-------------------------------------------------------------------------
136 # Check that even if the busy-handler fails (returns zero) within a
137 # call to sqlite3_prepare() (or _v2(), or _v3()), it is still invoked
138 # the next time an SQLITE_BUSY is encountered.
140 do_multiclient_test tn {
144 if {$::busy_called} { return 1 }
155 INSERT INTO t1 VALUES('x');
161 list [catch { sql1 { SELECT * FROM t1 } } msg] $::busy_called
166 list [catch { sql1 { SELECT * FROM t1 } } msg] $::busy_called