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 #***********************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 source $testdir/lock_common.tcl
16 set testprefix walsetlk
18 ifcapable !wal {finish_test ; return }
21 #-------------------------------------------------------------------------
22 # 1.*: Test that nothing goes wrong if recovery is forced while opening
23 # a write transaction or performing a checkpoint with blocking locks.
27 CREATE TABLE t1(x, y);
28 PRAGMA journal_mode = wal;
29 INSERT INTO t1 VALUES(1, 2);
30 INSERT INTO t1 VALUES(3, 4);
31 INSERT INTO t1 VALUES(5, 6);
32 INSERT INTO t1 VALUES(7, 8);
38 do_execsql_test -db db2 1.1 {
42 set fd [open test.db-shm r+]
43 puts $fd "blahblahblahblah"
48 INSERT INTO t1 VALUES(9, 10);
51 do_execsql_test -db db2 1.3 {
56 list [catch {db2 eval { BEGIN EXCLUSIVE }} msg] $msg
57 } {1 {database is locked}}
59 do_execsql_test 1.5 { COMMIT }
60 do_execsql_test -db db2 1.6 {
62 } {1 2 3 4 5 6 7 8 9 10}
64 puts $fd "blahblahblahblah"
67 do_execsql_test -db db2 1.7 {
68 PRAGMA wal_checkpoint = TRUNCATE
78 #-------------------------------------------------------------------------
80 do_multiclient_test tn {
83 PRAGMA journal_mode = wal;
84 CREATE TABLE t1(s, v);
85 INSERT INTO t1 VALUES(1, 2);
86 INSERT INTO t1 VALUES(3, 4);
87 INSERT INTO t1 VALUES(5, 6);
89 code1 { db timeout 2000 }
95 INSERT INTO t1 VALUES(7, 8);
100 set us [lindex [time { catch {db eval "BEGIN EXCLUSIVE"} }] 0]
101 expr $us>1000000 && $us<4000000
106 sql1 { SELECT * FROM t1 }
112 INSERT INTO t1 VALUES(9, 10);
117 set us [lindex [time { catch {db eval "PRAGMA wal_checkpoint=RESTART"} }] 0]
118 expr $us>1000000 && $us<4000000
127 } {1 2 3 4 5 6 7 8 9 10}
130 set us [lindex [time { catch {db eval "PRAGMA wal_checkpoint=RESTART"} }] 0]
131 expr $us>1000000 && $us<4000000
136 INSERT INTO t1 VALUES(11, 12);
144 INSERT INTO t1 VALUES(13, 14);
149 set us [lindex [time { catch {db eval "PRAGMA wal_checkpoint=RESTART"} }] 0]
150 expr $us>1000000 && $us<4000000
158 sql1 { INSERT INTO t1 VALUES(15, 16); }
162 set us [lindex [time { catch {db eval "PRAGMA wal_checkpoint=RESTART"} }] 0]
163 expr $us>1000000 && $us<4000000
172 sql1 { INSERT INTO t1 VALUES(17, 18); }
176 set us [lindex [time { catch {db eval "PRAGMA wal_checkpoint=RESTART"} }] 0]
177 expr $us>1000000 && $us<4000000
182 #-------------------------------------------------------------------------
186 do_execsql_test 3.0 {
187 PRAGMA journal_mode = wal;
188 CREATE TABLE x1(x, y);
190 INSERT INTO x1 VALUES(1, 2);
194 list [catch { db2 eval {BEGIN EXCLUSIVE} } msg] $msg
195 } {1 {database is locked}}