From 1b5ba8e022836fa8ab93bc90df1b34a29ea6e134 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 17 Jan 2013 14:18:26 -0500 Subject: Imported Upstream version 2.1.1 --- test/walro.test | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) (limited to 'test/walro.test') diff --git a/test/walro.test b/test/walro.test index 3ae7d53..465ce83 100644 --- a/test/walro.test +++ b/test/walro.test @@ -56,6 +56,7 @@ do_multiclient_test tn { do_test 1.1.1 { code2 { sqlite3 db2 test.db } sql2 { + PRAGMA auto_vacuum = 0; PRAGMA journal_mode = WAL; CREATE TABLE t1(x, y); INSERT INTO t1 VALUES('a', 'b'); @@ -163,6 +164,132 @@ do_multiclient_test tn { do_test 1.3.2.4 { code1 { sqlite3_extended_errcode db } } {SQLITE_READONLY_RECOVERY} + + #----------------------------------------------------------------------- + # Test cases 1.4.* check that checkpoints and log wraps don't prevent + # read-only connections from reading the database. + do_test 1.4.1 { + code1 { db close } + forcedelete test.db-shm + file exists test.db-shm + } {0} + + # Open one read-only and one read-write connection. Write some data + # and then run a checkpoint using the read-write connection. Then + # check the read-only connection can still read. + do_test 1.4.2 { + code1 { sqlite3 db file:test.db?readonly_shm=1 } + code2 { sqlite3 db2 test.db } + csql2 { + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(3, 4); + INSERT INTO t1 VALUES(5, 6); + PRAGMA wal_checkpoint; + } + } {0 {0 3 3}} + do_test 1.4.3 { + csql1 { SELECT * FROM t1 } + } {0 {a b c d e f g h i j k l 1 2 3 4 5 6}} + + # Using the read-write connection, open a transaction and write lots + # of data - causing a cache spill and a log wrap. Then check that the + # read-only connection can still read the database. + do_test 1.4.4.1 { + csql2 { + PRAGMA cache_size = 10; + BEGIN; + CREATE TABLE t2(x, y); + INSERT INTO t2 VALUES('abc', 'xyz'); + INSERT INTO t2 SELECT x||y, y||x FROM t2; + INSERT INTO t2 SELECT x||y, y||x FROM t2; + INSERT INTO t2 SELECT x||y, y||x FROM t2; + INSERT INTO t2 SELECT x||y, y||x FROM t2; + INSERT INTO t2 SELECT x||y, y||x FROM t2; + INSERT INTO t2 SELECT x||y, y||x FROM t2; + INSERT INTO t2 SELECT x||y, y||x FROM t2; + INSERT INTO t2 SELECT x||y, y||x FROM t2; + INSERT INTO t2 SELECT x||y, y||x FROM t2; + } + file size test.db-wal + } {147800} + do_test 1.4.4.2 { + csql1 { SELECT * FROM t1 } + } {0 {a b c d e f g h i j k l 1 2 3 4 5 6}} + do_test 1.4.4.3 { + csql2 COMMIT + csql1 { SELECT count(*) FROM t2 } + } {0 512} + do_test 1.4.5 { + code2 { db2 close } + code1 { db close } + } {} +} + +forcedelete test.db + +#----------------------------------------------------------------------- +# Test cases 2.* check that a read-only connection may read the +# database file while a checkpoint operation is ongoing. +# +do_multiclient_test tn { + # Do not run tests with the connections in the same process. + # + if {$tn==2} continue + + # Close all connections and delete the database. + # + code1 { db close } + code2 { db2 close } + code3 { db3 close } + forcedelete test.db + forcedelete walro + + foreach c {code1 code2 code3} { + $c { + sqlite3_shutdown + sqlite3_config_uri 1 + } + } + + proc tv_hook {x file args} { + if {[file tail $file]=="test.db-wal"} { + do_test 2.1.2 { + code2 { sqlite3 db2 file:test.db?readonly_shm=1 } + csql2 { SELECT count(*) FROM t2 } + } {0 4} + do_test 2.1.3 { + code2 { db2 close } + } {} + } + } + + do_test 2.1.1 { + testvfs tv -default 1 -fullshm 1 + tv script tv_hook + tv filter {} + code1 { sqlite3 db test.db } + csql1 { + PRAGMA auto_vacuum = 0; + PRAGMA journal_mode = WAL; + BEGIN; + CREATE TABLE t2(x, y); + INSERT INTO t2 VALUES('abc', 'xyz'); + INSERT INTO t2 SELECT x||y, y||x FROM t2; + INSERT INTO t2 SELECT x||y, y||x FROM t2; + COMMIT; + } + } {0 wal} + + tv filter xSync + set res [csql1 { PRAGMA wal_checkpoint }] + do_test 2.1.4 { set res } {0 {0 2 2}} + + do_test 2.1.5 { + code1 { db close } + code1 { tv delete } + } {} } finish_test + + -- cgit v1.2.3