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 #***********************************************************************
12 # $Id: savepoint4.test,v 1.7 2009/06/09 15:25:33 danielk1977 Exp $
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
17 ifcapable !crashtest {
23 return [db eval {SELECT count(*), md5sum(x) FROM t1}]
26 set ITERATIONS 25 ;# Number of iterations for savepoint4-1
27 set ITERATIONS2 13 ;# Number of iterations for savepoint4-2
30 do_test savepoint4-1 {
34 CREATE TABLE t1(x TEXT);
35 INSERT INTO t1 VALUES(randstr(10,400));
36 INSERT INTO t1 VALUES(randstr(10,400));
37 INSERT INTO t1 SELECT randstr(10,400) FROM t1;
38 INSERT INTO t1 SELECT randstr(10,400) FROM t1;
39 INSERT INTO t1 SELECT randstr(10,400) FROM t1;
40 INSERT INTO t1 SELECT randstr(10,400) FROM t1;
41 INSERT INTO t1 SELECT randstr(10,400) FROM t1;
42 INSERT INTO t1 SELECT randstr(10,400) FROM t1;
43 INSERT INTO t1 SELECT randstr(10,400) FROM t1;
44 INSERT INTO t1 SELECT randstr(10,400) FROM t1;
45 INSERT INTO t1 SELECT randstr(10,400) FROM t1;
47 SELECT count(*) FROM t1;
52 unset -nocomplain ::sig
54 for {set ii 1} {$ii<=$ITERATIONS} {incr ii} {
57 for {set iDelay 1 ; set crashed 1} {$crashed} {incr iDelay} {
59 do_test savepoint4-1.$ii.1.$iDelay {
60 set ret [crashsql -delay $iDelay -file test.db-journal {
61 PRAGMA cache_size = 20;
63 DELETE FROM t1 WHERE random()%2==0;
65 INSERT INTO t1 SELECT randstr(10,10)||x FROM t1;
67 UPDATE t1 SET x = randstr(10, 400) WHERE random()%10;
75 set crashed [lindex $ret 0]
76 integrity_check savepoint4-1.$ii.1.$iDelay.integrity
79 do_test savepoint4-1.$ii.2 {
81 DELETE FROM t1 WHERE random()%10==0;
82 INSERT INTO t1 SELECT randstr(10,10)||x FROM t1 WHERE random()%9==0;
87 do_test savepoint4-2 {
90 DROP TABLE IF EXISTS t1;
92 CREATE TABLE t1(x TEXT);
93 CREATE INDEX i1 ON t1(x);
94 INSERT INTO t1 VALUES(randstr(10,400));
95 INSERT INTO t1 VALUES(randstr(10,400));
96 INSERT INTO t1 SELECT randstr(10,400) FROM t1;
97 INSERT INTO t1 SELECT randstr(10,400) FROM t1;
98 INSERT INTO t1 SELECT randstr(10,400) FROM t1;
99 INSERT INTO t1 SELECT randstr(10,400) FROM t1;
100 INSERT INTO t1 SELECT randstr(10,400) FROM t1;
101 INSERT INTO t1 SELECT randstr(10,400) FROM t1;
102 INSERT INTO t1 SELECT randstr(10,400) FROM t1;
104 SELECT count(*) FROM t1;
108 for {set ii 1} {$ii<=$ITERATIONS2} {incr ii} {
109 set ::sig [signature]
110 set file test.db-journal
112 for {set iDelay 1 ; set crashed 1} {$crashed} {incr iDelay} {
114 do_test savepoint4-2.$ii.1.$iDelay {
116 set ret [crashsql -delay $iDelay -file $file {
118 INSERT INTO t1 SELECT * FROM t1 WHERE rowid<50;
120 INSERT INTO t1 SELECT * FROM t1 WHERE rowid<50;
122 DELETE FROM t1 WHERE (random()%10)==0;
124 DELETE FROM t1 WHERE (random()%10)==0;
126 DELETE FROM t1 WHERE (random()%10)==0;
130 UPDATE t1 SET x = substr(x||x, 12, 100000) WHERE (rowid%12)==0;
132 UPDATE t1 SET x = substr(x||x, 14, 100000) WHERE (rowid%14)==0;
134 UPDATE t1 SET x = substr(x||x, 13, 100000) WHERE (rowid%13)==0;
137 DELETE FROM t1 WHERE rowid > (
138 SELECT rowid FROM t1 ORDER BY rowid ASC LIMIT 1 OFFSET 256
143 set crashed [lindex $ret 0]
151 integrity_check savepoint4-2.$ii.1.$iDelay.integrity
153 if {$crashed == 0 && $file == "test.db-journal"} {
157 set ::sig [signature]
161 do_test savepoint4-2.$ii.2 {
163 DELETE FROM t1 WHERE random()%10==0;
164 INSERT INTO t1 SELECT randstr(10,10)||x FROM t1 WHERE random()%9==0;