]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add tests for sessions module.
authordan <dan@noemail.net>
Mon, 18 Aug 2014 08:42:36 +0000 (08:42 +0000)
committerdan <dan@noemail.net>
Mon, 18 Aug 2014 08:42:36 +0000 (08:42 +0000)
FossilOrigin-Name: 82fdb1975f5b29a751089a8582713372999ae56e

ext/session/sessionB.test
manifest
manifest.uuid

index 8791272f8e31a0a6a6c626434edc43bd697de5c2..d61cada98fde3d4c60ec5b696cbda232c3e146cb 100644 (file)
@@ -327,6 +327,180 @@ do_patchconcat_test 4.3.9 -revert {
   {DELETE t2 0 .XX. {{} {} i 1 i 2 {} {}} {}} 
 }
 
-finish_test
+#-------------------------------------------------------------------------
+# More rigorous testing of the _patchset(), _apply and _concat() APIs.
+#
+# The inputs to each test are a populate database and a list of DML 
+# statements. This test determines that the final database is the same
+# if:
+# 
+#   1) the statements are executed directly on the database.
+#
+#   2) a single patchset is collected while executing the statements and
+#      then applied to a copy of the original database file.
+#
+#   3) individual patchsets are collected for statement while executing
+#      them and concatenated together before being applied to a copy of
+#      the original database. The concatenation is done in a couple of
+#      different ways - linear, pairwise etc.
+#
+# All tests, as it happens, are run with both changesets and patchsets.
+# But the focus is on patchset capabilities.
+#
+
+# Return a checksum of the contents of the database file. Implicit IPK
+# columns are not included in the checksum - just modifying rowids does
+# not change the database checksum.
+#
+proc databasecksum {db} {
+  set alltab [$db eval {SELECT name FROM sqlite_master WHERE type='table'}]
+  foreach tab $alltab {
+    $db eval "SELECT * FROM $tab LIMIT 1" res { }
+    set slist [list]
+    foreach col [lsort $res(*)] {
+      lappend slist "quote($col)"
+    }
+    set sql "SELECT [join $slist ,] FROM $tab"
+    append txt "[lsort [$db eval $sql]]\n"
+  }
+  return [md5 $txt]
+}
 
+proc do_patchset_test {tn tstcmd lSql} {
+  if {$tstcmd != "patchset" && $tstcmd != "changeset"} {
+    error "have $tstcmd: must be patchset or changeset"
+  }
+
+  foreach fname {test.db2 test.db3 test.db4 test.db5} {
+    forcedelete $fname
+    forcecopy test.db $fname
+  }
+
+  # Execute the SQL statements on [db]. Collect a patchset for each 
+  # individual statement, as well as a single patchset for the entire 
+  # operation.
+  sqlite3session S db main
+  S attach *
+  foreach sql $lSql { 
+    sqlite3session T db main
+    T attach *
+    db eval $sql 
+    lappend lPatch [T patchset]
+    T delete
+  }
+  set patchset [S patchset]
+  S delete
+
+  # Calculate a checksum for the final database.
+  set cksum [databasecksum db]
+
+  # 1. Apply the single large patchset to test.db2
+  sqlite3 db2 test.db2
+  sqlite3changeset_apply db2 $patchset noop
+  uplevel [list do_test $tn.1 { databasecksum db2 } $cksum ]
+  db2 close
+  
+  # 2. Apply each of the single-statement patchsets to test.db3
+  sqlite3 db2 test.db3
+  foreach p $lPatch {
+    sqlite3changeset_apply db2 $p noop
+  }
+  uplevel [list do_test $tn.2 { databasecksum db2 } $cksum ]
+  db2 close
+
+  # 3. Concatenate all single-statement patchsets into a single large
+  #    patchset, then apply it to test.db4.
+  #
+  sqlite3 db2 test.db4
+  set big ""
+  foreach p $lPatch {
+    set big [sqlite3changeset_concat $big $p]
+  }
+  sqlite3changeset_apply db2 $big noop
+  uplevel [list do_test $tn.3 { databasecksum db2 } $cksum ]
+  db2 close
+
+  # 4. Concatenate all single-statement patchsets pairwise into a single
+  #    large patchset, then apply it to test.db5. Pairwise concatenation:
+  #
+  #         a b c d e f g h i j k
+  #      -> {a b} {c d} {e f} {g h} {i j} k
+  #      -> {a b c d} {e f g h} {i j k}
+  #      -> {a b c d e f g h} {i j k}
+  #      -> {a b c d e f g h i j k}
+  #      -> APPLY!
+  #
+  sqlite3 db2 test.db5
+  set L $lPatch
+  while {[llength $L] > 1} {
+    set O [list]
+    for {set i 0} {$i < [llength $L]} {incr i 2} {
+      if {$i==[llength $L]-1} {
+        lappend O [lindex $L $i]
+      } else {
+        set i1 [expr $i+1]
+        lappend O [sqlite3changeset_concat [lindex $L $i] [lindex $L $i1]]
+      }
+    }
+    set L $O
+  }
+  sqlite3changeset_apply db2 [lindex $L 0] noop
+  uplevel [list do_test $tn.4 { databasecksum db2 } $cksum ]
+  db2 close
+}
+
+proc do_patchset_changeset_test {tn initsql args} {
+  foreach tstcmd {patchset changeset} {
+    reset_db
+    execsql $initsql
+    foreach sql $args {
+      set lSql [split $sql ";"]
+      uplevel [list do_patchset_test $tn.$tstcmd $tstcmd $lSql]
+    }
+  }
+}
+
+do_patchset_changeset_test 5.1 {
+  CREATE TABLE t1(a PRIMARY KEY, b, c);
+  INSERT INTO t1 VALUES(1, 2, 3);
+} {
+  INSERT INTO t1 VALUES(4, 5, 6);
+  DELETE FROM t1 WHERE a=1;
+} {
+  INSERT INTO t1 VALUES(7, 8, 9);
+  UPDATE t1 SET c = 5;
+  INSERT INTO t1 VALUES(10, 11, 12);
+  UPDATE t1 SET c = 6;
+  INSERT INTO t1 VALUES(13, 14, 15);
+} {
+  UPDATE t1 SET c=c+1;
+  DELETE FROM t1 WHERE (a%2);
+} 
+
+do_patchset_changeset_test 5.2 {
+  CREATE TABLE t1(a PRIMARY KEY, b, c);
+  CREATE TABLE t2(a, b, c, d, PRIMARY KEY(c, b));
+} {
+  INSERT INTO t1 VALUES(x'00', 0, 'zero');
+  INSERT INTO t1 VALUES(x'01', 1, 'one');
+  INSERT INTO t1 VALUES(x'02', 4, 'four');
+  INSERT INTO t1 VALUES(x'03', 9, 'nine');
+  INSERT INTO t1 VALUES(x'04', 16, 'sixteen');
+  INSERT INTO t1 VALUES(x'05', 25, 'twenty-five');
+} {
+  UPDATE t1 SET a = b WHERE b<=4;
+  INSERT INTO t2 SELECT NULL, * FROM t1;
+  DELETE FROM t1 WHERE b=25;
+} {
+  DELETE FROM t2;
+  INSERT INTO t2 SELECT NULL, * FROM t1;
+  DELETE FROM t1;
+  INSERT INTO t1 SELECT b, c, d FROM t2;
+  UPDATE t1 SET b = b+1;
+  UPDATE t1 SET b = b+1;
+  UPDATE t1 SET b = b+1;
+}
+
+
+finish_test
 
index feade027e6912acac9f8acfe6f8992720421d71d..6060acbd59b4d45a8c1247bb6d1a298302157376 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\ssome\smissing\sand\sout-of-date\scomments\sin\sthe\ssessions\smodule.
-D 2014-08-16T19:01:00.672
+C Add\stests\sfor\ssessions\smodule.
+D 2014-08-18T08:42:36.985
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 639859a6f81bd15921ccd56ddbd6dfd335278377
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -152,7 +152,7 @@ F ext/session/session6.test 443789bc2fca12e4f7075cf692c60b8a2bea1a26
 F ext/session/session8.test 7d35947ad329b8966f095d34f9617a9eff52dc65
 F ext/session/session9.test 776e46785c29c11cda01f5205d0f1e8f8f9a46bf
 F ext/session/sessionA.test eb05c13e4ef1ca8046a3a6dbf2d5f6f5b04a11d4
-F ext/session/sessionB.test 51c70394bc04ac72d72f54bd0879614b9c34240c
+F ext/session/sessionB.test 77fca512719c136b8e1f4cb77b77e4c62b9d09ad
 F ext/session/session_common.tcl 1539d8973b2aea0025c133eb0cc4c89fcef541a5
 F ext/session/sessionfault.test 496291b287ba3c0b14ca2e074425e29cc92a64a6
 F ext/session/sqlite3session.c f2385ab5ebac94d8e54cc3aa8dc9ca77f8cdf0d9
@@ -1202,7 +1202,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P dccb34859508eac8146ae5b19c447673d04be3b0
-R 7605cd9723f946167ef7a988888841f4
+P 05c1d9149b27c68e2654ed28491722927d2176f5
+R 03b8d5b2540614bccade3685e83e41dc
 U dan
-Z 7c34f49d718669db325837ce5da84317
+Z cda8ef5f85a6d704893f36da729451e0
index 19c7a76bfc09b2ca945eb0798b9909f23acd0719..01d5ecc3e59d09b13b215f0194b4015ef60656e2 100644 (file)
@@ -1 +1 @@
-05c1d9149b27c68e2654ed28491722927d2176f5
\ No newline at end of file
+82fdb1975f5b29a751089a8582713372999ae56e
\ No newline at end of file