OLD | NEW |
1 # 2007 March 24 | 1 # 2007 March 24 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
11 # This file implements regression tests for SQLite library. | 11 # This file implements regression tests for SQLite library. |
12 # | 12 # |
13 # $Id: exclusive2.test,v 1.10 2008/11/27 02:22:11 drh Exp $ | 13 # $Id: exclusive2.test,v 1.10 2008/11/27 02:22:11 drh Exp $ |
14 | 14 |
15 set testdir [file dirname $argv0] | 15 set testdir [file dirname $argv0] |
16 source $testdir/tester.tcl | 16 source $testdir/tester.tcl |
17 | 17 |
| 18 # Do not use a codec for tests in this file, as the database file is |
| 19 # manipulated directly using tcl scripts (using the [hexio_write] command). |
| 20 # |
| 21 do_not_use_codec |
| 22 |
18 ifcapable {!pager_pragmas} { | 23 ifcapable {!pager_pragmas} { |
19 finish_test | 24 finish_test |
20 return | 25 return |
21 } | 26 } |
22 | 27 |
23 # This module does not work right if the cache spills at unexpected | 28 # This module does not work right if the cache spills at unexpected |
24 # moments. So disable the soft-heap-limit. | 29 # moments. So disable the soft-heap-limit. |
25 # | 30 # |
26 sqlite3_soft_heap_limit 0 | 31 sqlite3_soft_heap_limit 0 |
27 | 32 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 execsql {SELECT count(*), md5sum(a) FROM t1} $db | 81 execsql {SELECT count(*), md5sum(a) FROM t1} $db |
77 } | 82 } |
78 do_test exclusive2-1.0 { | 83 do_test exclusive2-1.0 { |
79 readPagerChangeCounter test.db | 84 readPagerChangeCounter test.db |
80 } {0} | 85 } {0} |
81 | 86 |
82 #----------------------------------------------------------------------- | 87 #----------------------------------------------------------------------- |
83 # The following tests - exclusive2-1.X - check that: | 88 # The following tests - exclusive2-1.X - check that: |
84 # | 89 # |
85 # 1-3: Build a database with connection 1, calculate a signature. | 90 # 1-3: Build a database with connection 1, calculate a signature. |
86 # 4-9: Modify the database using a second connection in a way that | 91 # 4-7: Modify the database using a second connection in a way that |
87 # does not modify the freelist, then reset the pager change-counter | 92 # does not modify the freelist, then reset the pager change-counter |
88 # to the value it had before the modifications. | 93 # to the value it had before the modifications. |
89 # 8: Check that using the first connection, the database signature | 94 # 8: Check that using the first connection, the database signature |
90 # is still the same. This is because it uses the in-memory cache. | 95 # is still the same. This is because it uses the in-memory cache. |
91 # It can't tell the db has changed because we reset the change-counter. | 96 # It can't tell the db has changed because we reset the change-counter. |
92 # 9: Increment the change-counter. | 97 # 9: Increment the change-counter. |
93 # 10: Ensure that the first connection now sees the updated database. It | 98 # 10: Ensure that the first connection now sees the updated database. It |
94 # sees the change-counter has been incremented and discards the | 99 # sees the change-counter has been incremented and discards the |
95 # invalid in-memory cache. | 100 # invalid in-memory cache. |
96 # | 101 # |
97 # This will only work if the database cache is large enough to hold | 102 # This will only work if the database cache is large enough to hold |
98 # the entire database. In the case of 1024 byte pages, this means | 103 # the entire database. In the case of 1024 byte pages, this means |
99 # the cache size must be at least 17. Otherwise, some pages will be | 104 # the cache size must be at least 17. Otherwise, some pages will be |
100 # loaded from the database file in step 8. | 105 # loaded from the database file in step 8. |
101 # | 106 # |
| 107 # For similar reasons, this test does not work with the memsubsys1 permutation. |
| 108 # Permutation memsubsys1 configures the pcache subsystem to use a static |
| 109 # allocation of 24 pages (shared between all pagers). This is not enough for |
| 110 # this test. |
| 111 # |
102 do_test exclusive2-1.1 { | 112 do_test exclusive2-1.1 { |
103 execsql { | 113 execsql { |
104 BEGIN; | 114 BEGIN; |
105 CREATE TABLE t1(a, b); | 115 CREATE TABLE t1(a, b); |
106 INSERT INTO t1(a) VALUES(randstr(10, 400)); | 116 INSERT INTO t1(a) VALUES(randstr(10, 400)); |
107 INSERT INTO t1(a) VALUES(randstr(10, 400)); | 117 INSERT INTO t1(a) VALUES(randstr(10, 400)); |
108 INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; | 118 INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; |
109 INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; | 119 INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; |
110 INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; | 120 INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; |
111 INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; | 121 INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; |
(...skipping 27 matching lines...) Expand all Loading... |
139 UPDATE t1 SET b=a, a=NULL; | 149 UPDATE t1 SET b=a, a=NULL; |
140 } db2 | 150 } db2 |
141 expr {[t1sig db2] eq $::sig} | 151 expr {[t1sig db2] eq $::sig} |
142 } 0 | 152 } 0 |
143 do_test exclusive2-1.6 { | 153 do_test exclusive2-1.6 { |
144 readPagerChangeCounter test.db | 154 readPagerChangeCounter test.db |
145 } {2} | 155 } {2} |
146 do_test exclusive2-1.7 { | 156 do_test exclusive2-1.7 { |
147 pagerChangeCounter test.db 1 | 157 pagerChangeCounter test.db 1 |
148 } {1} | 158 } {1} |
149 do_test exclusive2-1.9 { | 159 if {[permutation] != "memsubsys1"} { |
150 t1sig | 160 do_test exclusive2-1.9 { |
151 expr {[t1sig] eq $::sig} | 161 t1sig |
152 } {1} | 162 expr {[t1sig] eq $::sig} |
| 163 } {1} |
| 164 } |
153 do_test exclusive2-1.10 { | 165 do_test exclusive2-1.10 { |
154 pagerChangeCounter test.db 2 | 166 pagerChangeCounter test.db 2 |
155 } {2} | 167 } {2} |
156 do_test exclusive2-1.11 { | 168 do_test exclusive2-1.11 { |
157 expr {[t1sig] eq $::sig} | 169 expr {[t1sig] eq $::sig} |
158 } {0} | 170 } {0} |
| 171 db2 close |
159 | 172 |
160 #-------------------------------------------------------------------- | 173 #-------------------------------------------------------------------- |
161 # These tests - exclusive2-2.X - are similar to exclusive2-1.X, | 174 # These tests - exclusive2-2.X - are similar to exclusive2-1.X, |
162 # except that they are run with locking_mode=EXCLUSIVE. | 175 # except that they are run with locking_mode=EXCLUSIVE. |
163 # | 176 # |
164 # 1-3: Build a database with exclusive-access connection 1, | 177 # 1-3: Build a database with exclusive-access connection 1, |
165 # calculate a signature. | 178 # calculate a signature. |
166 # 4: Corrupt the database by writing 10000 bytes of garbage | 179 # 4: Corrupt the database by writing 10000 bytes of garbage |
167 # starting at the beginning of page 2. Check that connection 1 | 180 # starting at the beginning of page 2. Check that connection 1 |
168 # still works. It should be accessing the in-memory cache. | 181 # still works. It should be accessing the in-memory cache. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } {1 {database disk image is malformed}} | 251 } {1 {database disk image is malformed}} |
239 | 252 |
240 #-------------------------------------------------------------------- | 253 #-------------------------------------------------------------------- |
241 # These tests - exclusive2-3.X - verify that the pager change-counter | 254 # These tests - exclusive2-3.X - verify that the pager change-counter |
242 # is only incremented by the first change when in exclusive access | 255 # is only incremented by the first change when in exclusive access |
243 # mode. In normal mode, the change-counter is incremented once | 256 # mode. In normal mode, the change-counter is incremented once |
244 # per write-transaction. | 257 # per write-transaction. |
245 # | 258 # |
246 | 259 |
247 db close | 260 db close |
248 db2 close | |
249 catch {close $::fd} | 261 catch {close $::fd} |
250 file delete -force test.db | 262 file delete -force test.db |
251 file delete -force test.db-journal | 263 file delete -force test.db-journal |
252 | 264 |
253 do_test exclusive2-3.0 { | 265 do_test exclusive2-3.0 { |
254 sqlite3 db test.db | 266 sqlite3 db test.db |
255 execsql { | 267 execsql { |
256 BEGIN; | 268 BEGIN; |
257 CREATE TABLE t1(a UNIQUE); | 269 CREATE TABLE t1(a UNIQUE); |
258 INSERT INTO t1 VALUES(randstr(10, 400)); | 270 INSERT INTO t1 VALUES(randstr(200, 200)); |
259 INSERT INTO t1 VALUES(randstr(10, 400)); | 271 INSERT INTO t1 VALUES(randstr(200, 200)); |
260 COMMIT; | 272 COMMIT; |
261 } | 273 } |
262 readPagerChangeCounter test.db | 274 readPagerChangeCounter test.db |
263 } {1} | 275 } {1} |
264 do_test exclusive2-3.1 { | 276 do_test exclusive2-3.1 { |
265 execsql { | 277 execsql { |
266 INSERT INTO t1 VALUES(randstr(10, 400)); | 278 INSERT INTO t1 VALUES(randstr(200, 200)); |
267 } | 279 } |
268 readPagerChangeCounter test.db | 280 readPagerChangeCounter test.db |
269 } {2} | 281 } {2} |
270 do_test exclusive2-3.2 { | 282 do_test exclusive2-3.2 { |
271 execsql { | 283 execsql { |
272 INSERT INTO t1 VALUES(randstr(10, 400)); | 284 INSERT INTO t1 VALUES(randstr(200, 200)); |
273 } | 285 } |
274 readPagerChangeCounter test.db | 286 readPagerChangeCounter test.db |
275 } {3} | 287 } {3} |
276 do_test exclusive2-3.3 { | 288 do_test exclusive2-3.3 { |
277 execsql { | 289 execsql { |
278 PRAGMA locking_mode = exclusive; | 290 PRAGMA locking_mode = exclusive; |
279 INSERT INTO t1 VALUES(randstr(10, 400)); | 291 INSERT INTO t1 VALUES(randstr(200, 200)); |
280 } | 292 } |
281 readPagerChangeCounter test.db | 293 readPagerChangeCounter test.db |
282 } {4} | 294 } {4} |
283 do_test exclusive2-3.4 { | 295 do_test exclusive2-3.4 { |
| 296 breakpoint |
284 execsql { | 297 execsql { |
285 INSERT INTO t1 VALUES(randstr(10, 400)); | 298 INSERT INTO t1 VALUES(randstr(200, 200)); |
286 } | 299 } |
287 readPagerChangeCounter test.db | 300 readPagerChangeCounter test.db |
288 } {4} | 301 } {4} |
289 do_test exclusive2-3.5 { | 302 do_test exclusive2-3.5 { |
290 execsql { | 303 execsql { |
291 PRAGMA locking_mode = normal; | 304 PRAGMA locking_mode = normal; |
292 INSERT INTO t1 VALUES(randstr(10, 400)); | 305 INSERT INTO t1 VALUES(randstr(200, 200)); |
293 } | 306 } |
294 readPagerChangeCounter test.db | 307 readPagerChangeCounter test.db |
295 } {4} | 308 } {4} |
296 do_test exclusive2-3.6 { | 309 do_test exclusive2-3.6 { |
297 execsql { | 310 execsql { |
298 INSERT INTO t1 VALUES(randstr(10, 400)); | 311 INSERT INTO t1 VALUES(randstr(200, 200)); |
299 } | 312 } |
300 readPagerChangeCounter test.db | 313 readPagerChangeCounter test.db |
301 } {5} | 314 } {5} |
302 sqlite3_soft_heap_limit $soft_limit | 315 sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) |
303 | 316 |
304 finish_test | 317 finish_test |
OLD | NEW |