1 # 2008 December 15 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 # $Id: savepoint4.test,v 1.7 2009/06/09 15:25:33 danielk1977 Exp $ 13 14 set testdir [file dirname $argv0] 15 source $testdir/tester.tcl 16 17 ifcapable !crashtest { 18 finish_test 19 return 20 } 21 22 proc signature {} { 23 return [db eval {SELECT count(*), md5sum(x) FROM t1}] 24 } 25 26 set ITERATIONS 25 ;# Number of iterations for savepoint4-1 27 set ITERATIONS2 13 ;# Number of iterations for savepoint4-2 28 expr srand(0) 29 30 do_test savepoint4-1 { 31 execsql { 32 PRAGMA cache_size=10; 33 BEGIN; 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; 46 COMMIT; 47 SELECT count(*) FROM t1; 48 } 49 } {1024} 50 51 52 unset -nocomplain ::sig 53 54 for {set ii 1} {$ii<=$ITERATIONS} {incr ii} { 55 set ::sig [signature] 56 57 for {set iDelay 1 ; set crashed 1} {$crashed} {incr iDelay} { 58 59 do_test savepoint4-1.$ii.1.$iDelay { 60 set ret [crashsql -delay $iDelay -file test.db-journal { 61 PRAGMA cache_size = 20; 62 SAVEPOINT one; 63 DELETE FROM t1 WHERE random()%2==0; 64 SAVEPOINT two; 65 INSERT INTO t1 SELECT randstr(10,10)||x FROM t1; 66 ROLLBACK TO two; 67 UPDATE t1 SET x = randstr(10, 400) WHERE random()%10; 68 RELEASE two; 69 ROLLBACK TO one; 70 RELEASE one; 71 }] 72 signature 73 } $::sig 74 75 set crashed [lindex $ret 0] 76 integrity_check savepoint4-1.$ii.1.$iDelay.integrity 77 } 78 79 do_test savepoint4-1.$ii.2 { 80 execsql { 81 DELETE FROM t1 WHERE random()%10==0; 82 INSERT INTO t1 SELECT randstr(10,10)||x FROM t1 WHERE random()%9==0; 83 } 84 } {} 85 } 86 87 do_test savepoint4-2 { 88 execsql { 89 PRAGMA cache_size=10; 90 DROP TABLE IF EXISTS t1; 91 BEGIN; 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; 103 COMMIT; 104 SELECT count(*) FROM t1; 105 } 106 } {256} 107 108 for {set ii 1} {$ii<=$ITERATIONS2} {incr ii} { 109 set ::sig [signature] 110 set file test.db-journal 111 112 for {set iDelay 1 ; set crashed 1} {$crashed} {incr iDelay} { 113 114 do_test savepoint4-2.$ii.1.$iDelay { 115 116 set ret [crashsql -delay $iDelay -file $file { 117 SAVEPOINT one; 118 INSERT INTO t1 SELECT * FROM t1 WHERE rowid<50; 119 ROLLBACK TO one; 120 INSERT INTO t1 SELECT * FROM t1 WHERE rowid<50; 121 SAVEPOINT two; 122 DELETE FROM t1 WHERE (random()%10)==0; 123 SAVEPOINT three; 124 DELETE FROM t1 WHERE (random()%10)==0; 125 SAVEPOINT four; 126 DELETE FROM t1 WHERE (random()%10)==0; 127 RELEASE two; 128 129 SAVEPOINT three; 130 UPDATE t1 SET x = substr(x||x, 12, 100000) WHERE (rowid%12)==0; 131 SAVEPOINT four; 132 UPDATE t1 SET x = substr(x||x, 14, 100000) WHERE (rowid%14)==0; 133 ROLLBACK TO three; 134 UPDATE t1 SET x = substr(x||x, 13, 100000) WHERE (rowid%13)==0; 135 RELEASE three; 136 137 DELETE FROM t1 WHERE rowid > ( 138 SELECT rowid FROM t1 ORDER BY rowid ASC LIMIT 1 OFFSET 256 139 ); 140 RELEASE one; 141 }] 142 143 set crashed [lindex $ret 0] 144 if {$crashed} { 145 signature 146 } else { 147 set ::sig 148 } 149 } $::sig 150 151 integrity_check savepoint4-2.$ii.1.$iDelay.integrity 152 153 if {$crashed == 0 && $file == "test.db-journal"} { 154 set crashed 1 155 set iDelay 0 156 set file test.db 157 set ::sig [signature] 158 } 159 } 160 161 do_test savepoint4-2.$ii.2 { 162 execsql { 163 DELETE FROM t1 WHERE random()%10==0; 164 INSERT INTO t1 SELECT randstr(10,10)||x FROM t1 WHERE random()%9==0; 165 } 166 } {} 167 } 168 169 finish_test 170