Enhance the command-line completion extension to return the names of
[sqlite.git] / ext / rbu / rbucrash2.test
blob5f2ba604d12714ddcb6488b345fa55483f270178
1 # 2017 March 02
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
6 #    May you do good and not evil.
7 #    May you find forgiveness for yourself and forgive others.
8 #    May you share freely, never taking more than you give.
10 #***********************************************************************
13 if {![info exists testdir]} {
14   set testdir [file join [file dirname [info script]] .. .. test]
16 source $testdir/tester.tcl
17 set ::testprefix rbucrash2
19 db close
20 forcedelete test.db-oal rbu.db
21 sqlite3_shutdown
22 sqlite3_config_uri 1
23 reset_db
25 # Set up a target database and an rbu update database. The target
26 # db is the usual "test.db", the rbu db is "test.db2".
28 forcedelete test.db2
29 do_execsql_test 1.0 {
30   CREATE TABLE t1(a, b, c, PRIMARY KEY(a), UNIQUE(b));
31   INSERT INTO t1 VALUES(1, 2, 3);
32   INSERT INTO t1 VALUES(4, 5, 6);
33   INSERT INTO t1 VALUES(7, 8, 9);
35   ATTACH 'test.db2' AS rbu;
36   CREATE TABLE rbu.data_t1(a, b, c, rbu_control);
37   INSERT INTO data_t1 VALUES('one', randomblob(3500), NULL, 0);
38   INSERT INTO data_t1 VALUES('two', randomblob(3500), NULL, 0);
39   INSERT INTO data_t1 VALUES('three', randomblob(3500), NULL, 0);
40   INSERT INTO data_t1 VALUES('four', randomblob(3500), NULL, 0);
41   INSERT INTO data_t1 VALUES('five', randomblob(3500), NULL, 0);
42   INSERT INTO data_t1 VALUES('six', randomblob(3500), NULL, 0);
44 db_save_and_close
46 proc do_rbu_crash_test2 {tn script} {
48   foreach {f blksz} {
49     test.db   512
50     test.db2  512
51     test.db   4096
52     test.db2  4096
53   } {
54     set bDone 0
55     for {set iDelay 1} {$bDone==0} {incr iDelay} {
56       forcedelete test.db2 test.db2-journal test.db test.db-oal test.db-wal
57       db_restore
58   
59       set res [
60         crashsql -file $f -delay $iDelay -tclbody $script -dflt 1 -opendb {} \
61             -blocksize $blksz {}
62       ]
63   
64       set bDone 1
65       if {$res == "1 {child process exited abnormally}"} {
66         set bDone 0
67       } elseif {$res != "0 {}"} {
68         error "unexected catchsql result: $res"
69       }
70   
71       sqlite3rbu rbu test.db test.db2
72       while {[rbu step]=="SQLITE_OK"} {}
73       rbu close
74   
75       sqlite3 db test.db
76       do_execsql_test $tn.delay=$iDelay.f=$f.blksz=$blksz {
77         PRAGMA integrity_check;
78       } {ok}
79       db close
80     }
81   }
84 for {set x 1} {$x < 10} {incr x} {
85   do_rbu_crash_test2 1.$x {
86     sqlite3rbu rbu test.db test.db2
87     while {[rbu step]=="SQLITE_OK"} {
88       rbu savestate
89     }
90     rbu close
91   }
94 for {set x 1} {$x < 2} {incr x} {
95   do_rbu_crash_test2 2.$x {
96     sqlite3rbu rbu test.db test.db2
97     while {[rbu step]=="SQLITE_OK"} {
98       rbu close
99       sqlite3rbu rbu test.db test.db2
100     }
101     rbu close
102   }
105 finish_test