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
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 source $testdir/lock_common.tcl
20 do_multiclient_test tn {
23 CREATE TABLE t1(a, b);
24 PRAGMA journal_mode = wal;
25 INSERT INTO t1 VALUES('A', 'B');
30 code1 { db timeout 1000 }
31 sql1 { SELECT * FROM t1 }
37 INSERT INTO t1 VALUES('C', 'D');
42 set us [lindex [time { catch { sql1 { BEGIN EXCLUSIVE } } }] 0]
43 expr {$us>950000 && $us<1500000}
53 #-------------------------------------------------------------------------
55 do_multiclient_test tn {
56 # Make the db a WAL mode db. And add a table and a row to it. Then open
57 # a second connection within process 1. Process 1 now has connections
58 # [db] and [db1.2], process 2 has connection [db2] only.
60 # Configure all connections to use a 1000 ms timeout.
67 PRAGMA auto_vacuum = off;
68 PRAGMA journal_mode = wal;
69 CREATE TABLE t1(a, b);
70 INSERT INTO t1 VALUES(1, 2);
78 db1.2 eval {SELECT * FROM t1}
82 # Take a read lock with [db] in process 1.
91 # Insert a row using [db2] in process 2. Then try a passive checkpoint.
92 # It fails to checkpoint the final frame (due to the readlock taken by
93 # [db]), and returns in less than 250ms.
95 sql2 { INSERT INTO t1 VALUES(3, 4) }
96 set us [lindex [time {
97 set res [code2 { db2 eval { PRAGMA wal_checkpoint } }]
99 list [expr $us < 250000] $res
102 # Now try a FULL checkpoint with [db2]. It returns SQLITE_BUSY. And takes
103 # over 950ms to do so.
105 set us [lindex [time {
106 set res [code2 { db2 eval { PRAGMA wal_checkpoint = FULL } }]
108 list [expr $us > 950000] $res
111 # Passive checkpoint with [db1.2] (process 1). No SQLITE_BUSY, returns
114 set us [lindex [time {
115 set res [code1 { db1.2 eval { PRAGMA wal_checkpoint } }]
117 list [expr $us < 250000] $res
120 # Full checkpoint with [db1.2] (process 1). SQLITE_BUSY returned in
123 set us [lindex [time {
124 set res [code1 { db1.2 eval { PRAGMA wal_checkpoint = FULL } }]
126 list [expr $us > 950000] $res
134 #-------------------------------------------------------------------------
135 # Check that even if the busy-handler fails (returns zero) within a
136 # call to sqlite3_prepare() (or _v2(), or _v3()), it is still invoked
137 # the next time an SQLITE_BUSY is encountered.
139 do_multiclient_test tn {
143 if {$::busy_called} { return 1 }
154 INSERT INTO t1 VALUES('x');
160 list [catch { sql1 { SELECT * FROM t1 } } msg] $::busy_called
165 list [catch { sql1 { SELECT * FROM t1 } } msg] $::busy_called