]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add extra pager tests.
authordan <dan@noemail.net>
Mon, 28 Jun 2010 19:04:02 +0000 (19:04 +0000)
committerdan <dan@noemail.net>
Mon, 28 Jun 2010 19:04:02 +0000 (19:04 +0000)
FossilOrigin-Name: 6b7e419ddc241f457dd69878f09f5c51c70aa379

manifest
manifest.uuid
test/pager1.test
test/pagerfault.test

index 3d9f9472701570c0b4c509fd3689372f1651f62a..83e4629fb20198f2060742bb16550d5de733a6e6 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\ssome\serrors\swhen\scompiling\swith\sSQLITE_OMIT_WAL.
-D 2010-06-28T11:23:10
+C Add\sextra\spager\stests.
+D 2010-06-28T19:04:02
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in a5cad1f8f3e021356bfcc6c77dc16f6f1952bbc3
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -534,9 +534,9 @@ F test/notify2.test 195a467e021f74197be2c4fb02d6dee644b8d8db
 F test/notnull.test cc7c78340328e6112a13c3e311a9ab3127114347
 F test/null.test a8b09b8ed87852742343b33441a9240022108993
 F test/openv2.test af02ed0a9cbc0d2a61b8f35171d4d117e588e4ec
-F test/pager1.test d8dfe2f8a641f5f7960f7a071f0c84f7ba23cc01
+F test/pager1.test 634c62f8c321fb5b72b4c8fa27340bd8e9db9089
 F test/pager2.test f5c757c271ce642d36a393ecbfb3aef1c240dcef
-F test/pagerfault.test a6b0ef0f9e678aea5a649c78efee284516abaf83
+F test/pagerfault.test 210fae669249a06ef0c08da1e75b9bda7e9bf66b
 F test/pagerfault2.test 1287f123bd5d20452113739ed7755fd254e502f1
 F test/pageropt.test 8146bf448cf09e87bb1867c2217b921fb5857806
 F test/pagesize.test 76aa9f23ecb0741a4ed9d2e16c5fa82671f28efb
@@ -828,7 +828,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P a85ae33246226801f88c1e377725c192711797cc
-R c039a24618e8fbf1e98f4efbf1b986ad
+P 3b68cb9c656db8c5c481199919a98f5764f7ebfa
+R 3cf749e0c461e6688a0dd44d86bc37c3
 U dan
-Z 0199b159e4b296798119a8a04c398a43
+Z cd8f9170613084e79dc0108e44d902f9
index 67ea4eeed3b55ff473cc0b8cf2e1ec8695b86661..838f2c482b12ebd9061649711436454f3519a5cd 100644 (file)
@@ -1 +1 @@
-3b68cb9c656db8c5c481199919a98f5764f7ebfa
\ No newline at end of file
+6b7e419ddc241f457dd69878f09f5c51c70aa379
\ No newline at end of file
index aa48cd5d3aeaa4770954cf16bf916a00bb6b6906..aa9b2d5b46f1b9257ec10c24542d372022e5ee41 100644 (file)
@@ -42,7 +42,12 @@ do_not_use_codec
 #
 # pager1-10.*: Test that the assumed file-system sector-size is limited to
 #              64KB.
-#              
+#
+# pager1-12.*: Tests involving "PRAGMA page_size"
+#
+# pager1-13.*: Cases specific to "PRAGMA journal_mode=PERSIST"
+#
+# pager1-14.*: Cases specific to "PRAGMA journal_mode=OFF"
 #
 
 set a_string_counter 1
@@ -62,8 +67,7 @@ do_multiclient_test tn {
     sql1 {
       CREATE TABLE t1(a PRIMARY KEY, b);
       CREATE INDEX i1 ON t1(b);
-      INSERT INTO t1 VALUES(1, 'one');
-      INSERT INTO t1 VALUES(2, 'two');
+      INSERT INTO t1 VALUES(1, 'one'); INSERT INTO t1 VALUES(2, 'two');
     }
   } {}
   do_test pager1-$tn.2 { sql2 { SELECT * FROM t1 } } {1 one 2 two}
@@ -187,6 +191,25 @@ do_multiclient_test tn {
   do_test pager1-$tn.27 { sql1 { SELECT * FROM t1 } } {21 one 22 two 23 three}
   do_test pager1-$tn.27 { sql2 { SELECT * FROM t1 } } {21 one 22 two 23 three}
   do_test pager1-$tn.28 { sql3 { SELECT * FROM t1 } } {21 one 22 two 23 three}
+
+  # Install a busy-handler for connection [db].
+  #
+  set ::nbusy [list]
+  proc busy {n} {
+    lappend ::nbusy $n
+    if {$n>5} { sql2 COMMIT }
+    return 0
+  }
+  db busy busy
+
+  do_test pager1-$tn.29 { 
+    sql1 { BEGIN ; INSERT INTO t1 VALUES('x', 'y') } 
+  } {}
+  do_test pager1-$tn.30 { 
+    sql2 { BEGIN ; SELECT * FROM t1 } 
+  } {21 one 22 two 23 three}
+  do_test pager1-$tn.31 { sql1 COMMIT } {}
+  do_test pager1-$tn.32 { set ::nbusy } {0 1 2 3 4 5 6}
 }
 
 #-------------------------------------------------------------------------
@@ -218,6 +241,7 @@ do_test pager1-3.1.1 {
 } {0 0}
 
 do_execsql_test pager1-3.1.2 {
+  PRAGMA cache_size = 10;
   BEGIN;
     INSERT INTO t1 VALUES(1, randomblob(1500));
     INSERT INTO t1 VALUES(2, randomblob(1500));
@@ -232,15 +256,22 @@ do_execsql_test pager1-3.5 { SELECT a FROM t1 } {1 2 3}
 do_execsql_test pager1-3.6 { COMMIT } {}
 
 foreach {tn sql tcl} {
-  9  { PRAGMA synchronous = NORMAL } { }
-
-  7  { PRAGMA synchronous = NORMAL } {
+  7  { PRAGMA synchronous = NORMAL ; PRAGMA temp_store = 0 } {
     testvfs tv -default 1
     tv devchar safe_append
   }
-  8  { PRAGMA synchronous = FULL } { }
-  10 { PRAGMA synchronous = OFF } { }
-  11 { PRAGMA synchronous = FULL ; PRAGMA fullfsync = 1 } { }
+  8  { PRAGMA synchronous = NORMAL ; PRAGMA temp_store = 2 } {
+    testvfs tv -default 1
+    tv devchar sequential
+  }
+  9  { PRAGMA synchronous = FULL } { }
+  10 { PRAGMA synchronous = NORMAL } { }
+  11 { PRAGMA synchronous = OFF } { }
+  12 { PRAGMA synchronous = FULL ; PRAGMA fullfsync = 1 } { }
+  13 { PRAGMA synchronous = FULL } {
+    testvfs tv -default 1
+    tv devchar sequential
+  }
 } {
   do_test pager1-3.$tn.1 {
     eval $tcl
@@ -936,11 +967,22 @@ do_test pager1-6.1 {
     CREATE TABLE t10(a, b);
   }
 } {10}
-do_test pager1-6.2 {
-  catchsql {
-    CREATE TABLE t11(a, b);
-  }
+do_catchsql_test pager1-6.2 {
+  CREATE TABLE t11(a, b)
 } {1 {database or disk is full}}
+do_execsql_test pager1-6.4 { PRAGMA max_page_count      } {10}
+do_execsql_test pager1-6.5 { PRAGMA max_page_count = 15 } {15}
+do_execsql_test pager1-6.6 { CREATE TABLE t11(a, b)     } {}
+do_execsql_test pager1-6.7 {
+  BEGIN;
+    INSERT INTO t11 VALUES(1, 2);
+    PRAGMA max_page_count = 13;
+} {13}
+do_execsql_test pager1-6.8 {
+    INSERT INTO t11 VALUES(3, 4);
+    PRAGMA max_page_count = 10;
+} {11}
+do_execsql_test pager1-6.9 { COMMIT } {}
 
 
 #-------------------------------------------------------------------------
@@ -1000,6 +1042,10 @@ ifcapable wal {
   }
 }
 
+#-------------------------------------------------------------------------
+# The following tests, pager1-8.*, test that the special filenames 
+# ":memory:" and "" open temporary databases.
+#
 foreach {tn filename} {
   1 :memory:
   2 ""
@@ -1165,7 +1211,6 @@ do_test pager1-11.4 {
   db2 close
   file size test.db-journal
 } {0}
-breakpoint
 do_execsql_test pager1-11.5 { SELECT count(*) FROM zz } {32}
 db close
 tv delete
@@ -1202,5 +1247,135 @@ foreach pagesize {
   db2 close
 }
 
-finish_test
+#-------------------------------------------------------------------------
+# Test specal "PRAGMA journal_mode=PERSIST" test cases.
+#
+# pager1-13.1.*: This tests a special case encountered in persistent 
+#                journal mode: If the journal associated with a transaction
+#                is smaller than the journal file (because a previous 
+#                transaction left a very large non-hot journal file in the
+#                file-system), then SQLite has to be careful that there is
+#                not a journal-header left over from a previous transaction
+#                immediately following the journal content just written.
+#                If there is, and the process crashes so that the journal
+#                becomes a hot-journal and must be rolled back by another
+#                process, there is a danger that the other process may roll
+#                back the aborted transaction, then continue copying data
+#                from an older transaction from the remainder of the journal.
+#                See the syncJournal() function for details.
+#
+# pager1-13.2.*: Same test as the previous. This time, throw an index into
+#                the mix to make the integrity-check more likely to catch
+#                errors.
+#
+testvfs tv -default 1
+tv script xSyncCb
+tv filter xSync
+proc xSyncCb {method filename args} {
+  set t [file tail $filename]
+  if {$t == "test.db"} faultsim_save
+  return SQLITE_OK
+}
+faultsim_delete_and_reopen
+db func a_string a_string
 
+# The UPDATE statement at the end of this test case creates a really big
+# journal. Since the cache-size is only 10 pages, the journal contains 
+# frequent journal headers.
+#
+do_execsql_test pager1-13.1.1 {
+  PRAGMA page_size = 1024;
+  PRAGMA journal_mode = PERSIST;
+  PRAGMA cache_size = 10;
+  BEGIN;
+    CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB);
+    INSERT INTO t1 VALUES(NULL, a_string(400));
+    INSERT INTO t1 SELECT NULL, a_string(400) FROM t1;          /*   2 */
+    INSERT INTO t1 SELECT NULL, a_string(400) FROM t1;          /*   4 */
+    INSERT INTO t1 SELECT NULL, a_string(400) FROM t1;          /*   8 */
+    INSERT INTO t1 SELECT NULL, a_string(400) FROM t1;          /*  16 */
+    INSERT INTO t1 SELECT NULL, a_string(400) FROM t1;          /*  32 */
+    INSERT INTO t1 SELECT NULL, a_string(400) FROM t1;          /*  64 */
+    INSERT INTO t1 SELECT NULL, a_string(400) FROM t1;          /* 128 */
+  COMMIT;
+  UPDATE t1 SET b = a_string(400);
+} {persist}
+
+# Run transactions of increasing sizes. Eventually, one (or more than one)
+# of these will write just enough content that one of the old headers created 
+# by the transaction in the block above lies immediately after the content
+# journalled by the current transaction.
+#
+for {set nUp 1} {$nUp<64} {incr nUp} {
+  do_execsql_test pager1-13.1.2.$nUp.1 { 
+    UPDATE t1 SET b = a_string(399) WHERE a <= $nUp
+  } {}
+  do_execsql_test pager1-13.1.2.$nUp.2 { PRAGMA integrity_check } {ok} 
+
+  # Try to access the snapshot of the file-system.
+  #
+  sqlite3 db2 sv_test.db
+  do_test pager1-13.1.2.$nUp.3 {
+    execsql { SELECT sum(length(b)) FROM t1 } db2
+  } [expr {128*400 - ($nUp-1)}]
+  do_test pager1-13.1.2.$nUp.4 {
+    execsql { PRAGMA integrity_check } db2
+  } {ok}
+  db2 close
+}
+
+# Same test as above. But this time with an index on the table.
+#
+do_execsql_test pager1-13.2.1 {
+  CREATE INDEX i1 ON t1(b);
+  UPDATE t1 SET b = a_string(400);
+} {}
+for {set nUp 1} {$nUp<64} {incr nUp} {
+  do_execsql_test pager1-13.2.2.$nUp.1 { 
+    UPDATE t1 SET b = a_string(399) WHERE a <= $nUp
+  } {}
+  do_execsql_test pager1-13.2.2.$nUp.2 { PRAGMA integrity_check } {ok} 
+  sqlite3 db2 sv_test.db
+  do_test pager1-13.2.2.$nUp.3 {
+    execsql { SELECT sum(length(b)) FROM t1 } db2
+  } [expr {128*400 - ($nUp-1)}]
+  do_test pager1-13.2.2.$nUp.4 {
+    execsql { PRAGMA integrity_check } db2
+  } {ok}
+  db2 close
+}
+
+db close
+tv delete
+
+#-------------------------------------------------------------------------
+# Test specal "PRAGMA journal_mode=OFF" test cases.
+#
+faultsim_delete_and_reopen
+do_execsql_test pager1-14.1.1 {
+  PRAGMA journal_mode = OFF;
+  CREATE TABLE t1(a, b);
+  BEGIN;
+    INSERT INTO t1 VALUES(1, 2);
+  COMMIT;
+  SELECT * FROM t1;
+} {off 1 2}
+do_catchsql_test pager1-14.1.2 {
+  BEGIN;
+    INSERT INTO t1 VALUES(3, 4);
+  ROLLBACK;
+} {0 {}}
+do_execsql_test pager1-14.1.3 {
+  SELECT * FROM t1;
+} {1 2 3 4}
+do_catchsql_test pager1-14.1.4 {
+  BEGIN;
+    INSERT INTO t1(rowid, a, b) SELECT a+3, b, b FROM t1;
+    INSERT INTO t1(rowid, a, b) SELECT a+3, b, b FROM t1;
+} {1 {PRIMARY KEY must be unique}}
+do_execsql_test pager1-14.1.5 {
+  COMMIT;
+  SELECT * FROM t1;
+} {1 2 3 4 2 2 4 4}
+
+finish_test
index c16744c0ba2e2db1ba240293b4da9c43f5bb4e0b..356e7f80c9dcb02b1a675290644e440c0812dcae 100644 (file)
@@ -495,8 +495,6 @@ do_faultsim_test pagerfault-10 -prep {
   faultsim_integrity_check
 }
 
-}
-
 #-------------------------------------------------------------------------
 # Test fault injection with transaction savepoints (savepoints created
 # when a SAVEPOINT command is executed outside of any other savepoint
@@ -544,5 +542,43 @@ do_faultsim_test pagerfault-11 -prep {
   faultsim_integrity_check
 }
 
+}
+
+do_test pagerfault-12-pre1 {
+  testvfs ss_layer -default 1
+  ss_layer sectorsize 4096
+  faultsim_delete_and_reopen
+  db func a_string a_string;
+
+  execsql {
+    PRAGMA page_size = 1024;
+    PRAGMA journal_mode = PERSIST;
+    PRAGMA cache_size = 10;
+    BEGIN;
+      CREATE TABLE t1(x, y UNIQUE);
+      INSERT INTO t1 VALUES(a_string(333), a_string(444));
+      INSERT INTO t1 SELECT a_string(333+rowid), a_string(444+rowid) FROM t1;
+      INSERT INTO t1 SELECT a_string(333+rowid), a_string(444+rowid) FROM t1;
+      INSERT INTO t1 SELECT a_string(333+rowid), a_string(444+rowid) FROM t1;
+      INSERT INTO t1 SELECT a_string(333+rowid), a_string(444+rowid) FROM t1;
+      INSERT INTO t1 SELECT a_string(44), a_string(55) FROM t1 LIMIT 13;
+    COMMIT;
+  }
+  faultsim_save_and_close
+} {}
+do_faultsim_test pagerfault-12 -prep {
+  faultsim_restore_and_reopen
+  execsql { PRAGMA cache_size = 10 }
+  db func a_string a_string;
+} -body {
+  execsql {
+    UPDATE t1 SET x = a_string(length(x)), y = a_string(length(y));
+  }
+} -test {
+  faultsim_test_result {0 {}}
+  faultsim_integrity_check
+}
+
+
 
 finish_test