1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
# 2020 May 06
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
# TESTRUNNER: slow
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/lock_common.tcl
set testprefix walsetlk
ifcapable !wal {finish_test ; return }
db timeout 1000
#-------------------------------------------------------------------------
# 1.*: Test that nothing goes wrong if recovery is forced while opening
# a write transaction or performing a checkpoint with blocking locks.
#
do_execsql_test 1.0 {
CREATE TABLE t1(x, y);
PRAGMA journal_mode = wal;
INSERT INTO t1 VALUES(1, 2);
INSERT INTO t1 VALUES(3, 4);
INSERT INTO t1 VALUES(5, 6);
INSERT INTO t1 VALUES(7, 8);
} {wal}
sqlite3 db2 test.db
db2 timeout 1000
do_execsql_test -db db2 1.1 {
SELECT * FROM t1
} {1 2 3 4 5 6 7 8}
set fd [open test.db-shm r+]
puts $fd "blahblahblahblah"
flush $fd
do_execsql_test 1.2 {
BEGIN;
INSERT INTO t1 VALUES(9, 10);
}
do_execsql_test -db db2 1.3 {
SELECT * FROM t1
} {1 2 3 4 5 6 7 8}
do_test 1.4 {
list [catch {db2 eval { BEGIN EXCLUSIVE }} msg] $msg
} {1 {database is locked}}
do_execsql_test 1.5 { COMMIT }
do_execsql_test -db db2 1.6 {
SELECT * FROM t1
} {1 2 3 4 5 6 7 8 9 10}
puts $fd "blahblahblahblah"
flush $fd
do_execsql_test -db db2 1.7 {
PRAGMA wal_checkpoint = TRUNCATE
} {0 0 0}
do_test 1.8 {
file size test.db-wal
} 0
close $fd
db close
db2 close
#-------------------------------------------------------------------------
do_multiclient_test tn {
do_test 2.$tn.1 {
sql1 {
PRAGMA journal_mode = wal;
CREATE TABLE t1(s, v);
INSERT INTO t1 VALUES(1, 2);
INSERT INTO t1 VALUES(3, 4);
INSERT INTO t1 VALUES(5, 6);
}
code1 { db timeout 1100 }
} {}
do_test 2.$tn.2 {
sql2 {
BEGIN;
INSERT INTO t1 VALUES(7, 8);
}
} {}
do_test 2.$tn.3 {
set us [lindex [time { catch {db eval "BEGIN EXCLUSIVE"} }] 0]
expr $us>1000000 && $us<4000000
} {1}
do_test 2.$tn.4 {
sql2 { COMMIT }
sql1 { SELECT * FROM t1 }
} {1 2 3 4 5 6 7 8}
do_test 2.$tn.5 {
sql2 {
BEGIN;
INSERT INTO t1 VALUES(9, 10);
}
} {}
do_test 2.$tn.6 {
set us [lindex [time { catch {db eval "PRAGMA wal_checkpoint=RESTART"} }] 0]
expr $us>1000000 && $us<4000000
} {1}
do_test 2.$tn.7 {
sql2 {
COMMIT;
BEGIN;
SELECT * FROM t1;
}
} {1 2 3 4 5 6 7 8 9 10}
do_test 2.$tn.8 {
set us [lindex [time { catch {db eval "PRAGMA wal_checkpoint=RESTART"} }] 0]
expr $us>1000000 && $us<4000000
} {1}
do_test 2.$tn.9 {
sql3 {
INSERT INTO t1 VALUES(11, 12);
}
sql2 {
COMMIT;
BEGIN;
SELECT * FROM t1;
}
sql3 {
INSERT INTO t1 VALUES(13, 14);
}
} {}
do_test 2.$tn.10 {
set us [lindex [time { catch {db eval "PRAGMA wal_checkpoint=RESTART"} }] 0]
expr $us>1000000 && $us<4000000
} {1}
do_test 2.$tn.11 {
sql3 {
BEGIN;
SELECT * FROM t1;
}
sql1 { INSERT INTO t1 VALUES(15, 16); }
} {}
do_test 2.$tn.12 {
set us [lindex [time { catch {db eval "PRAGMA wal_checkpoint=RESTART"} }] 0]
expr $us>1000000 && $us<4000000
} {1}
do_test 2.$tn.13 {
sql2 {
COMMIT;
BEGIN;
SELECT * FROM t1;
}
sql1 { INSERT INTO t1 VALUES(17, 18); }
} {}
do_test 2.$tn.14 {
set us [lindex [time { catch {db eval "PRAGMA wal_checkpoint=RESTART"} }] 0]
expr $us>1000000 && $us<4000000
} {1}
}
#-------------------------------------------------------------------------
reset_db
sqlite3 db2 test.db
db2 timeout 1000
do_execsql_test 3.0 {
PRAGMA journal_mode = wal;
CREATE TABLE x1(x, y);
BEGIN;
INSERT INTO x1 VALUES(1, 2);
} {wal}
do_test 3.1 {
list [catch { db2 eval {BEGIN EXCLUSIVE} } msg] $msg
} {1 {database is locked}}
finish_test
|