diff options
author | dan <dan@noemail.net> | 2010-06-21 07:45:47 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2010-06-21 07:45:47 +0000 |
commit | 153eda0aa469406a29a532735afc8bcae0b51a6b (patch) | |
tree | cbb771eb74ebc9307f08f5a4e82d00fb2fa5fe17 /test/pager1.test | |
parent | 248af428ea6e49970ea66b2dacb7ec3f7c060e73 (diff) | |
download | sqlite-153eda0aa469406a29a532735afc8bcae0b51a6b.tar.gz sqlite-153eda0aa469406a29a532735afc8bcae0b51a6b.zip |
Add further pager tests.
FossilOrigin-Name: 4104b175a8c3560a7680f3d2b54416821bb2e19d
Diffstat (limited to 'test/pager1.test')
-rw-r--r-- | test/pager1.test | 182 |
1 files changed, 77 insertions, 105 deletions
diff --git a/test/pager1.test b/test/pager1.test index 33b5c2ae0..313c0f36e 100644 --- a/test/pager1.test +++ b/test/pager1.test @@ -14,6 +14,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl source $testdir/lock_common.tcl source $testdir/malloc_common.tcl +source $testdir/wal_common.tcl # # pager1-1.*: Test inter-process locking (clients in multiple processes). @@ -28,13 +29,8 @@ source $testdir/malloc_common.tcl # # pager1-6.*: Cases related to "PRAGMA max_page_count" # - -proc do_execsql_test {testname sql result} { - uplevel do_test $testname [list "execsql {$sql}"] [list $result] -} -proc do_catchsql_test {testname sql result} { - uplevel do_test $testname [list "catchsql {$sql}"] [list $result] -} +# pager1-7.*: Cases specific to "PRAGMA journal_mode=TRUNCATE" +# set a_string_counter 1 proc a_string {n} { @@ -216,104 +212,6 @@ do_execsql_test pager1-3.4 { SELECT * FROM counter } {3 0} do_execsql_test pager1-3.5 { SELECT a FROM t1 } {1 2 3} do_execsql_test pager1-3.6 { COMMIT } {} -set otn 0 -testvfs tv -default 1 -foreach code [list { - set s 512 -} { - set s 1024 - set sql { PRAGMA journal_mode = memory } -} { - set s 1024 - set sql { - PRAGMA journal_mode = memory; - PRAGMA locking_mode = exclusive; - } -} { - set s 2048 - tv devchar safe_append -} { - set s 4096 -} { - set s 4096 - set sql { PRAGMA journal_mode = WAL } -} { - set s 8192 - set sql { PRAGMA synchronous = off } -}] { - - incr otn - set sql "" - tv devchar {} - eval $code - tv sectorsize $s - - do_test pager1-3.7.$otn.0 { - faultsim_delete_and_reopen - execsql $sql - execsql { - PRAGMA cache_size = 10; - CREATE TABLE t1(i INTEGER PRIMARY KEY, j blob); - } - } {} - - set tn 0 - set lowpoint 0 - foreach x { - 100 x 0 100 - x - 70 22 96 59 96 50 22 56 21 16 37 64 43 40 0 38 22 38 55 0 6 - 43 62 32 93 54 18 13 29 45 66 29 25 61 31 53 82 75 25 96 86 10 69 - 2 29 6 60 80 95 42 82 85 50 68 96 90 39 78 69 87 97 48 74 65 43 - x - 86 34 26 50 41 85 58 44 89 22 6 51 45 46 58 32 97 6 1 12 32 2 - 69 39 48 71 33 31 5 58 90 43 24 54 12 9 18 57 4 38 91 42 27 45 - 50 38 56 29 10 0 26 37 83 1 78 15 47 30 75 62 46 29 68 5 30 4 - 27 96 33 95 79 75 56 10 29 70 32 75 52 88 5 36 50 57 46 63 88 65 - x - 44 95 64 20 24 35 69 61 61 2 35 92 42 46 23 98 78 1 38 72 79 35 - 94 37 13 59 5 93 27 58 80 75 58 7 67 13 10 76 84 4 8 70 81 45 - 8 41 98 5 60 26 92 29 91 90 2 62 40 4 5 22 80 15 83 76 52 88 - 29 5 68 73 72 7 54 17 89 32 81 94 51 28 53 71 8 42 54 59 70 79 - x - } { - incr tn - set now [db one {SELECT count(i) FROM t1}] - if {$x == "x"} { - execsql { COMMIT ; BEGIN } - set lowpoint $now - do_test pager1.3.7.$otn.$tn { - sqlite3 db2 test.db - execsql { - SELECT COALESCE(max(i), 0) FROM t1; - PRAGMA integrity_check; - } - } [list $lowpoint ok] - db2 close - } else { - if {$now > $x } { - if { $x>=$lowpoint } { - execsql "ROLLBACK TO sp_$x" - } else { - execsql "DELETE FROM t1 WHERE i>$x" - set lowpoint $x - } - } elseif {$now < $x} { - for {set k $now} {$k < $x} {incr k} { - execsql "SAVEPOINT sp_$k" - execsql { INSERT INTO t1(j) VALUES(randomblob(1500)) } - } - } - do_execsql_test pager1.3.7.$otn.$tn { - SELECT COALESCE(max(i), 0) FROM t1; - PRAGMA integrity_check; - } [list $x ok] - } - } -} -db close -tv delete - #------------------------------------------------------------------------- # Hot journal rollback related test cases. # @@ -620,5 +518,79 @@ do_test pager1-6.2 { } } {1 {database or disk is full}} + +#------------------------------------------------------------------------- +# The following tests work with "PRAGMA journal_mode=TRUNCATE" and +# "PRAGMA locking_mode=EXCLUSIVE". +# +# Each test is specified with 5 variables. As follows: +# +# $tn: Test Number. Used as part of the [do_test] test names. +# $sql: SQL to execute. +# $res: Expected result of executing $sql. +# $js: The expected size of the journal file, in bytes, after executing +# the SQL script. Or -1 if the journal is not expected to exist. +# $ws: The expected size of the WAL file, in bytes, after executing +# the SQL script. Or -1 if the WAL is not expected to exist. +# +faultsim_delete_and_reopen +foreach {tn sql res js ws} [subst { + + 1 { + CREATE TABLE t1(a, b); + PRAGMA auto_vacuum=OFF; + PRAGMA synchronous=NORMAL; + PRAGMA page_size=1024; + PRAGMA locking_mode=EXCLUSIVE; + PRAGMA journal_mode=TRUNCATE; + INSERT INTO t1 VALUES(1, 2); + } {exclusive truncate} 0 -1 + + 2 { + BEGIN IMMEDIATE; + SELECT * FROM t1; + COMMIT; + } {1 2} 0 -1 + + 3 { + BEGIN; + SELECT * FROM t1; + COMMIT; + } {1 2} 0 -1 + + 4 { PRAGMA journal_mode = WAL } wal -1 -1 + 5 { INSERT INTO t1 VALUES(3, 4) } {} -1 [wal_file_size 1 1024] + 6 { PRAGMA locking_mode = NORMAL } normal -1 [wal_file_size 1 1024] + 7 { INSERT INTO t1 VALUES(5, 6); } {} -1 [wal_file_size 2 1024] + + 8 { PRAGMA journal_mode = TRUNCATE } truncate 0 -1 + 9 { INSERT INTO t1 VALUES(7, 8) } {} 0 -1 + 10 { SELECT * FROM t1 } {1 2 3 4 5 6 7 8} 0 -1 + +}] { + do_execsql_test pager1-7.1.$tn.1 $sql $res + catch { set J -1 ; set J [file size test.db-journal] } + catch { set W -1 ; set W [file size test.db-wal] } + do_test pager1-7.1.$tn.2 { list $J $W } [list $js $ws] +} + +do_test pager1-8.1 { + faultsim_delete_and_reopen + db close + sqlite3 db :memory: + execsql { + CREATE TABLE x1(x); + INSERT INTO x1 VALUES('Charles'); + INSERT INTO x1 VALUES('James'); + INSERT INTO x1 VALUES('Mary'); + SELECT * FROM x1; + } +} {Charles James Mary} +do_test pager1-8.2 { + db close + sqlite3 db :memory: + catchsql { SELECT * FROM x1 } +} {1 {no such table: x1}} + finish_test |