Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: third_party/sqlite/src/test/wal3.test

Issue 2765553002: [sql] Import SQLite 3.17.0. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # 2010 April 13 1 # 2010 April 13
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 #***********************************************************************
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 INSERT INTO t1 SELECT a_string(800) FROM t1; /* 128*/ 54 INSERT INTO t1 SELECT a_string(800) FROM t1; /* 128*/
55 INSERT INTO t1 SELECT a_string(800) FROM t1; /* 256 */ 55 INSERT INTO t1 SELECT a_string(800) FROM t1; /* 256 */
56 INSERT INTO t1 SELECT a_string(800) FROM t1; /* 512 */ 56 INSERT INTO t1 SELECT a_string(800) FROM t1; /* 512 */
57 INSERT INTO t1 SELECT a_string(800) FROM t1; /* 1024 */ 57 INSERT INTO t1 SELECT a_string(800) FROM t1; /* 1024 */
58 INSERT INTO t1 SELECT a_string(800) FROM t1; /* 2048 */ 58 INSERT INTO t1 SELECT a_string(800) FROM t1; /* 2048 */
59 INSERT INTO t1 SELECT a_string(800) FROM t1 LIMIT 1970; /* 4018 */ 59 INSERT INTO t1 SELECT a_string(800) FROM t1 LIMIT 1970; /* 4018 */
60 COMMIT; 60 COMMIT;
61 PRAGMA cache_size = 10; 61 PRAGMA cache_size = 10;
62 } 62 }
63 set x [wal_frame_count test.db-wal 1024] 63 set x [wal_frame_count test.db-wal 1024]
64 if {$::G(perm:name)=="memsubsys1"} { 64 if {[permutation]=="memsubsys1"} {
65 if {$x==4251 || $x==4290} {set x 4056} 65 if {$x==4251 || $x==4290} {set x 4056}
66 } 66 }
67 set x 67 set x
68 } 4056 68 } 4056
69 69
70 for {set i 1} {$i < 50} {incr i} { 70 for {set i 1} {$i < 50} {incr i} {
71 71
72 do_test wal3-1.$i.1 { 72 do_test wal3-1.$i.1 {
73 set str [a_string 800] 73 set str [a_string 800]
74 execsql { UPDATE t1 SET x = $str WHERE rowid = $i } 74 execsql { UPDATE t1 SET x = $str WHERE rowid = $i }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 213 }
214 do_test wal3-3.$tn { 214 do_test wal3-3.$tn {
215 forcedelete test.db test.db-wal test.db-journal 215 forcedelete test.db test.db-wal test.db-journal
216 216
217 testvfs T 217 testvfs T
218 T filter {} 218 T filter {}
219 T script sync_counter 219 T script sync_counter
220 sqlite3 db test.db -vfs T 220 sqlite3 db test.db -vfs T
221 221
222 execsql "PRAGMA synchronous = $syncmode" 222 execsql "PRAGMA synchronous = $syncmode"
223 execsql "PRAGMA checkpoint_fullfsync = 0"
223 execsql { PRAGMA journal_mode = WAL } 224 execsql { PRAGMA journal_mode = WAL }
224 execsql { CREATE TABLE filler(a,b,c); } 225 execsql { CREATE TABLE filler(a,b,c); }
225 226
226 set ::syncs [list] 227 set ::syncs [list]
227 T filter xSync 228 T filter xSync
228 execsql { 229 execsql {
229 CREATE TABLE x(y); 230 CREATE TABLE x(y);
230 INSERT INTO x VALUES('z'); 231 INSERT INTO x VALUES('z');
231 PRAGMA wal_checkpoint; 232 PRAGMA wal_checkpoint;
232 } 233 }
233 T filter {} 234 T filter {}
234 set ::syncs 235 set ::syncs
235 } $synccount 236 } $synccount
236 237
237 db close 238 db close
238 T delete 239 T delete
239 } 240 }
240 241
241 #-------------------------------------------------------------------------
242 # When recovering the contents of a WAL file, a process obtains the WRITER
243 # lock, then locks all other bytes before commencing recovery. If it fails
244 # to lock all other bytes (because some other process is holding a read
245 # lock) it should retry up to 100 times. Then return SQLITE_PROTOCOL to the
246 # caller. Test this (test case wal3-4.3).
247 #
248 # Also test the effect of hitting an SQLITE_BUSY while attempting to obtain
249 # the WRITER lock (should be the same). Test case wal3-4.4.
250 #
251 proc lock_callback {method filename handle lock} {
252 lappend ::locks $lock
253 }
254 do_test wal3-4.1 {
255 testvfs T
256 T filter xShmLock
257 T script lock_callback
258 set ::locks [list]
259 sqlite3 db test.db -vfs T
260 execsql { SELECT * FROM x }
261 lrange $::locks 0 3
262 } [list {0 1 lock exclusive} {1 7 lock exclusive} \
263 {1 7 unlock exclusive} {0 1 unlock exclusive} \
264 ]
265 do_test wal3-4.2 {
266 db close
267 set ::locks [list]
268 sqlite3 db test.db -vfs T
269 execsql { SELECT * FROM x }
270 lrange $::locks 0 3
271 } [list {0 1 lock exclusive} {1 7 lock exclusive} \
272 {1 7 unlock exclusive} {0 1 unlock exclusive} \
273 ]
274 proc lock_callback {method filename handle lock} {
275 if {$lock == "1 7 lock exclusive"} { return SQLITE_BUSY }
276 return SQLITE_OK
277 }
278 puts "# Warning: This next test case causes SQLite to call xSleep(1) 100 times."
279 puts "# Normally this equates to a 100ms delay, but if SQLite is built on unix"
280 puts "# without HAVE_USLEEP defined, it may be 100 seconds."
281 do_test wal3-4.3 {
282 db close
283 set ::locks [list]
284 sqlite3 db test.db -vfs T
285 catchsql { SELECT * FROM x }
286 } {1 {locking protocol}}
287
288 puts "# Warning: Same again!"
289 proc lock_callback {method filename handle lock} {
290 if {$lock == "0 1 lock exclusive"} { return SQLITE_BUSY }
291 return SQLITE_OK
292 }
293 do_test wal3-4.4 {
294 db close
295 set ::locks [list]
296 sqlite3 db test.db -vfs T
297 catchsql { SELECT * FROM x }
298 } {1 {locking protocol}}
299 db close
300 T delete
301
302 242
303 #------------------------------------------------------------------------- 243 #-------------------------------------------------------------------------
304 # Only one client may run recovery at a time. Test this mechanism. 244 # Only one client may run recovery at a time. Test this mechanism.
305 # 245 #
306 # When client-2 tries to open a read transaction while client-1 is 246 # When client-2 tries to open a read transaction while client-1 is
307 # running recovery, it fails to obtain a lock on an aReadMark[] slot 247 # running recovery, it fails to obtain a lock on an aReadMark[] slot
308 # (because they are all locked by recovery). It then tries to obtain 248 # (because they are all locked by recovery). It then tries to obtain
309 # a shared lock on the RECOVER lock to see if there really is a 249 # a shared lock on the RECOVER lock to see if there really is a
310 # recovery running or not. 250 # recovery running or not.
311 # 251 #
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 execsql { SELECT * FROM blue } db2 550 execsql { SELECT * FROM blue } db2
611 } {1 2 3 4 5 6} 551 } {1 2 3 4 5 6}
612 do_test wal3-7.2.2 { 552 do_test wal3-7.2.2 {
613 set ::locks 553 set ::locks
614 } {{5 1 lock shared} {5 1 unlock shared} {4 1 lock shared} {4 1 unlock shared}} 554 } {{5 1 lock shared} {5 1 unlock shared} {4 1 lock shared} {4 1 unlock shared}}
615 555
616 db close 556 db close
617 db2 close 557 db2 close
618 T delete 558 T delete
619 559
620 #-------------------------------------------------------------------------
621 #
622 do_test wal3-8.1 {
623 forcedelete test.db test.db-journal test.db wal
624 sqlite3 db test.db
625 sqlite3 db2 test.db
626 execsql {
627 PRAGMA auto_vacuum = off;
628 PRAGMA journal_mode = WAL;
629 CREATE TABLE b(c);
630 INSERT INTO b VALUES('Tehran');
631 INSERT INTO b VALUES('Qom');
632 INSERT INTO b VALUES('Markazi');
633 PRAGMA wal_checkpoint;
634 }
635 } {wal 0 5 5}
636 do_test wal3-8.2 {
637 execsql { SELECT * FROM b }
638 } {Tehran Qom Markazi}
639 do_test wal3-8.3 {
640 db eval { SELECT * FROM b } {
641 db eval { INSERT INTO b VALUES('Qazvin') }
642 set r [db2 eval { SELECT * FROM b }]
643 break
644 }
645 set r
646 } {Tehran Qom Markazi Qazvin}
647 do_test wal3-8.4 {
648 execsql {
649 INSERT INTO b VALUES('Gilan');
650 INSERT INTO b VALUES('Ardabil');
651 }
652 } {}
653 db2 close
654
655 faultsim_save_and_close
656 testvfs T -default 1
657 faultsim_restore_and_reopen
658 T filter xShmLock
659 T script lock_callback
660
661 proc lock_callback {method file handle spec} {
662 if {$spec == "1 7 unlock exclusive"} {
663 T filter {}
664 set ::r [catchsql { SELECT * FROM b } db2]
665 }
666 }
667 sqlite3 db test.db
668 sqlite3 db2 test.db
669 do_test wal3-8.5 {
670 execsql { SELECT * FROM b }
671 } {Tehran Qom Markazi Qazvin Gilan Ardabil}
672 do_test wal3-8.6 {
673 set ::r
674 } {1 {locking protocol}}
675
676 db close
677 db2 close
678
679 faultsim_restore_and_reopen
680 sqlite3 db2 test.db
681 T filter xShmLock
682 T script lock_callback
683 proc lock_callback {method file handle spec} {
684 if {$spec == "1 7 unlock exclusive"} {
685 T filter {}
686 set ::r [catchsql { SELECT * FROM b } db2]
687 }
688 }
689 unset ::r
690 do_test wal3-8.5 {
691 execsql { SELECT * FROM b }
692 } {Tehran Qom Markazi Qazvin Gilan Ardabil}
693 do_test wal3-8.6 {
694 set ::r
695 } {1 {locking protocol}}
696
697 db close
698 db2 close
699 T delete
700 560
701 #------------------------------------------------------------------------- 561 #-------------------------------------------------------------------------
702 # When a connection opens a read-lock on the database, it searches for 562 # When a connection opens a read-lock on the database, it searches for
703 # an aReadMark[] slot that is already set to the mxFrame value for the 563 # an aReadMark[] slot that is already set to the mxFrame value for the
704 # new transaction. If it cannot find one, it attempts to obtain an 564 # new transaction. If it cannot find one, it attempts to obtain an
705 # exclusive lock on an aReadMark[] slot for the purposes of modifying 565 # exclusive lock on an aReadMark[] slot for the purposes of modifying
706 # the value, then drops back to a shared-lock for the duration of the 566 # the value, then drops back to a shared-lock for the duration of the
707 # transaction. 567 # transaction.
708 # 568 #
709 # This test case verifies that if an exclusive lock cannot be obtained 569 # This test case verifies that if an exclusive lock cannot be obtained
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 642
783 expr {[file size test.db-wal] > [expr 1032*9000]} 643 expr {[file size test.db-wal] > [expr 1032*9000]}
784 } 1 644 } 1
785 645
786 do_test wal3-10.$tn.2 { 646 do_test wal3-10.$tn.2 {
787 sql2 {PRAGMA integrity_check} 647 sql2 {PRAGMA integrity_check}
788 } {ok} 648 } {ok}
789 } 649 }
790 650
791 finish_test 651 finish_test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698