| 1 |
# 2017 March 02 |
| 2 |
# |
| 3 |
# The author disclaims copyright to this source code. In place of |
| 4 |
# a legal notice, here is a blessing: |
| 5 |
# |
| 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. |
| 9 |
# |
| 10 |
#*********************************************************************** |
| 11 |
# |
| 12 |
|
| 13 |
source [file join [file dirname [info script]] rbu_common.tcl] |
| 14 |
if_no_rbu_support { finish_test ; return } |
| 15 |
set ::testprefix rbucrash2 |
| 16 |
|
| 17 |
# Set up a target database and an rbu update database. The target |
| 18 |
# db is the usual "test.db", the rbu db is "test.db2". |
| 19 |
# |
| 20 |
forcedelete test.db2 |
| 21 |
do_execsql_test 1.0 { |
| 22 |
CREATE TABLE t1(a, b, c, PRIMARY KEY(a), UNIQUE(b)); |
| 23 |
INSERT INTO t1 VALUES(1, 2, 3); |
| 24 |
INSERT INTO t1 VALUES(4, 5, 6); |
| 25 |
INSERT INTO t1 VALUES(7, 8, 9); |
| 26 |
|
| 27 |
ATTACH 'test.db2' AS rbu; |
| 28 |
CREATE TABLE rbu.data_t1(a, b, c, rbu_control); |
| 29 |
INSERT INTO data_t1 VALUES('one', randomblob(3500), NULL, 0); |
| 30 |
INSERT INTO data_t1 VALUES('two', randomblob(3500), NULL, 0); |
| 31 |
INSERT INTO data_t1 VALUES('three', randomblob(3500), NULL, 0); |
| 32 |
INSERT INTO data_t1 VALUES('four', randomblob(3500), NULL, 0); |
| 33 |
INSERT INTO data_t1 VALUES('five', randomblob(3500), NULL, 0); |
| 34 |
INSERT INTO data_t1 VALUES('six', randomblob(3500), NULL, 0); |
| 35 |
} |
| 36 |
db_save_and_close |
| 37 |
|
| 38 |
proc do_rbu_crash_test2 {tn script} { |
| 39 |
|
| 40 |
foreach {f blksz} { |
| 41 |
test.db 512 |
| 42 |
test.db2 512 |
| 43 |
test.db 4096 |
| 44 |
test.db2 4096 |
| 45 |
} { |
| 46 |
set bDone 0 |
| 47 |
for {set iDelay 1} {$bDone==0} {incr iDelay} { |
| 48 |
forcedelete test.db2 test.db2-journal test.db test.db-oal test.db-wal |
| 49 |
db_restore |
| 50 |
|
| 51 |
set res [ |
| 52 |
crashsql -file $f -delay $iDelay -tclbody $script -dflt 1 -opendb {} \ |
| 53 |
-blocksize $blksz {} |
| 54 |
] |
| 55 |
|
| 56 |
set bDone 1 |
| 57 |
if {$res == "1 {child process exited abnormally}"} { |
| 58 |
set bDone 0 |
| 59 |
} elseif {$res != "0 {}"} { |
| 60 |
error "unexected catchsql result: $res" |
| 61 |
} |
| 62 |
|
| 63 |
sqlite3rbu rbu test.db test.db2 |
| 64 |
while {[rbu step]=="SQLITE_OK"} {} |
| 65 |
rbu close |
| 66 |
|
| 67 |
sqlite3 db test.db |
| 68 |
do_execsql_test $tn.delay=$iDelay.f=$f.blksz=$blksz { |
| 69 |
PRAGMA integrity_check; |
| 70 |
} {ok} |
| 71 |
db close |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
for {set x 1} {$x < 10} {incr x} { |
| 77 |
do_rbu_crash_test2 1.$x { |
| 78 |
sqlite3rbu rbu test.db test.db2 |
| 79 |
while {[rbu step]=="SQLITE_OK"} { |
| 80 |
rbu savestate |
| 81 |
} |
| 82 |
rbu close |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
for {set x 1} {$x < 2} {incr x} { |
| 87 |
do_rbu_crash_test2 2.$x { |
| 88 |
sqlite3rbu rbu test.db test.db2 |
| 89 |
while {[rbu step]=="SQLITE_OK"} { |
| 90 |
rbu close |
| 91 |
sqlite3rbu rbu test.db test.db2 |
| 92 |
} |
| 93 |
rbu close |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
finish_test |