1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
# 2011 November 16
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file contains fault-injection test cases for the
# sqlite3_db_cacheflush API.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix cffault
source $testdir/malloc_common.tcl
# Run the supplied SQL on a copy of the database currently stored on
# disk in file $dbfile.
proc diskquery {dbfile sql} {
forcecopy $dbfile dq.db
sqlite3 dq dq.db
set res [execsql $sql dq]
dq close
set res
}
do_execsql_test 1.0 {
CREATE TABLE t1(a PRIMARY KEY, b);
CREATE INDEX i1 ON t1(b);
INSERT INTO t1 VALUES(1, 2);
INSERT INTO t1 VALUES(3, 4);
INSERT INTO t1 VALUES(5, 6);
INSERT INTO t1 VALUES(7, 8);
}
faultsim_save_and_close
do_faultsim_test 1.1 -prep {
faultsim_restore_and_reopen
db eval {
BEGIN;
UPDATE t1 SET b=b+1;
}
} -body {
sqlite3_db_cacheflush db
} -test {
if {[sqlite3_get_autocommit db]} { error "Transaction rolled back!" }
faultsim_test_result {0 {}} {1 {disk I/O error}}
catch { db eval COMMIT }
faultsim_integrity_check
}
do_faultsim_test 1.2 -prep {
faultsim_restore_and_reopen
db eval {
BEGIN;
UPDATE t1 SET b=b+1;
}
} -body {
set result [list]
db eval { SELECT * FROM t1 } {
if {$a==5} { catch { sqlite3_db_cacheflush db } }
lappend result $a $b
}
set result
} -test {
faultsim_test_result {0 {1 3 3 5 5 7 7 9}} {1 {disk I/O error}}
catch { db eval COMMIT }
faultsim_integrity_check
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
CREATE TABLE t1(a PRIMARY KEY, b, c);
CREATE INDEX i1 ON t1(b);
CREATE INDEX i2 ON t1(c, b);
INSERT INTO t1 VALUES(1, 2, randomblob(600));
INSERT INTO t1 VALUES(3, 4, randomblob(600));
INSERT INTO t1 VALUES(5, 6, randomblob(600));
INSERT INTO t1 VALUES(7, 8, randomblob(600));
INSERT INTO t1 VALUES(9, 10, randomblob(600));
}
faultsim_save_and_close
do_faultsim_test 2.1 -prep {
faultsim_restore_and_reopen
db eval {
BEGIN;
UPDATE t1 SET b=b+1;
}
} -body {
set result [list]
db eval { SELECT * FROM t1 } {
if {$a==5} { catch { sqlite3_db_cacheflush db } }
lappend result $a $b
}
set result
} -test {
faultsim_test_result {0 {1 3 3 5 5 7 7 9 9 11}} {1 {disk I/O error}}
catch { db eval { INSERT INTO t1 VALUES(11, 12, randomblob(600)) } }
catch { db eval COMMIT }
faultsim_integrity_check
}
do_faultsim_test 2.2 -prep {
faultsim_restore_and_reopen
db eval {
BEGIN;
UPDATE t1 SET b=b+1;
}
} -body {
sqlite3_db_cacheflush db
} -test {
if {[sqlite3_get_autocommit db]} { error "Transaction rolled back!" }
faultsim_test_result {0 {}} {1 {disk I/O error}}
catch { db eval { SELECT * FROM t1 } }
catch { db eval COMMIT }
faultsim_integrity_check
}
do_faultsim_test 2.3 -prep {
faultsim_restore_and_reopen
db eval {
BEGIN;
UPDATE t1 SET b=b-1;
}
} -body {
sqlite3_db_cacheflush db
} -test {
if {[sqlite3_get_autocommit db]} { error "Transaction rolled back!" }
faultsim_test_result {0 {}} {1 {disk I/O error}}
catch { db eval { INSERT INTO t1 VALUES(11, 12, randomblob(600)) } }
catch { db eval COMMIT }
faultsim_integrity_check
}
do_faultsim_test 2.4 -prep {
faultsim_restore_and_reopen
db eval {
BEGIN;
UPDATE t1 SET b=b-1;
}
} -body {
catch { sqlite3_db_cacheflush db }
catch { sqlite3_db_release_memory db }
catch { sqlite3_db_cacheflush db }
execsql { SELECT a, b FROM t1 }
} -test {
faultsim_test_result {0 {1 1 3 3 5 5 7 7 9 9}} {1 {disk I/O error}}
catchsql ROLLBACK
faultsim_integrity_check
}
finish_test
|