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 #***********************************************************************
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 source $testdir/lock_common.tcl
18 set testprefix walsetlk
20 ifcapable !wal {finish_test ; return }
23 #-------------------------------------------------------------------------
24 # 1.*: Test that nothing goes wrong if recovery is forced while opening
25 # a write transaction or performing a checkpoint with blocking locks.
29 CREATE TABLE t1(x, y);
30 PRAGMA journal_mode = wal;
31 INSERT INTO t1 VALUES(1, 2);
32 INSERT INTO t1 VALUES(3, 4);
33 INSERT INTO t1 VALUES(5, 6);
34 INSERT INTO t1 VALUES(7, 8);
40 do_execsql_test -db db2 1.1 {
44 set fd [open test.db-shm r+]
45 puts $fd "blahblahblahblah"
50 INSERT INTO t1 VALUES(9, 10);
53 do_execsql_test -db db2 1.3 {
58 list [catch {db2 eval { BEGIN EXCLUSIVE }} msg] $msg
59 } {1 {database is locked}}
61 do_execsql_test 1.5 { COMMIT }
62 do_execsql_test -db db2 1.6 {
64 } {1 2 3 4 5 6 7 8 9 10}
66 puts $fd "blahblahblahblah"
69 do_execsql_test -db db2 1.7 {
70 PRAGMA wal_checkpoint = TRUNCATE
80 #-------------------------------------------------------------------------
82 do_multiclient_test tn {
85 PRAGMA journal_mode = wal;
86 CREATE TABLE t1(s, v);
87 INSERT INTO t1 VALUES(1, 2);
88 INSERT INTO t1 VALUES(3, 4);
89 INSERT INTO t1 VALUES(5, 6);
91 code1 { db timeout 1100 }
97 INSERT INTO t1 VALUES(7, 8);
102 set us [lindex [time { catch {db eval "BEGIN EXCLUSIVE"} }] 0]
103 expr $us>1000000 && $us<4000000
108 sql1 { SELECT * FROM t1 }
114 INSERT INTO t1 VALUES(9, 10);
119 set us [lindex [time { catch {db eval "PRAGMA wal_checkpoint=RESTART"} }] 0]
120 expr $us>1000000 && $us<4000000
129 } {1 2 3 4 5 6 7 8 9 10}
132 set us [lindex [time { catch {db eval "PRAGMA wal_checkpoint=RESTART"} }] 0]
133 expr $us>1000000 && $us<4000000
138 INSERT INTO t1 VALUES(11, 12);
146 INSERT INTO t1 VALUES(13, 14);
151 set us [lindex [time { catch {db eval "PRAGMA wal_checkpoint=RESTART"} }] 0]
152 expr $us>1000000 && $us<4000000
160 sql1 { INSERT INTO t1 VALUES(15, 16); }
164 set us [lindex [time { catch {db eval "PRAGMA wal_checkpoint=RESTART"} }] 0]
165 expr $us>1000000 && $us<4000000
174 sql1 { INSERT INTO t1 VALUES(17, 18); }
178 set us [lindex [time { catch {db eval "PRAGMA wal_checkpoint=RESTART"} }] 0]
179 expr $us>1000000 && $us<4000000
184 #-------------------------------------------------------------------------
188 do_execsql_test 3.0 {
189 PRAGMA journal_mode = wal;
190 CREATE TABLE x1(x, y);
192 INSERT INTO x1 VALUES(1, 2);
196 list [catch { db2 eval {BEGIN EXCLUSIVE} } msg] $msg
197 } {1 {database is locked}}