mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Add tests to simulate power-failure on devices that support IOCAP_SEQUENTIAL or IOCAP_SAFE_APPEND. (CVS 4284)
FossilOrigin-Name: bdf5cb8d25d93d48220ce46acad2ccf967a87843
This commit is contained in:
@ -9,7 +9,11 @@
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# $Id: crash3.test,v 1.1 2007/08/23 11:07:10 danielk1977 Exp $
|
||||
# This file contains tests that verify that SQLite can correctly rollback
|
||||
# databases after crashes when using the special IO modes triggered
|
||||
# by device IOCAP flags.
|
||||
#
|
||||
# $Id: crash3.test,v 1.2 2007/08/24 08:15:54 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@ -34,6 +38,8 @@ proc do_test2 {name tcl res1 res2} {
|
||||
uplevel $script
|
||||
}
|
||||
|
||||
# This block tests crash-recovery when the IOCAP_ATOMIC flags is set.
|
||||
#
|
||||
# Each iteration of the following loop sets up the database to contain
|
||||
# the following schema and data:
|
||||
#
|
||||
@ -96,5 +102,89 @@ foreach {sql res2} [list \
|
||||
}
|
||||
}
|
||||
|
||||
# This block tests both the IOCAP_SEQUENTIAL and IOCAP_SAFE_APPEND flags.
|
||||
#
|
||||
db close
|
||||
file delete -force test.db test.db-journal
|
||||
sqlite3 db test.db
|
||||
do_test crash3-2.0 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
CREATE TABLE abc(a PRIMARY KEY, b, c);
|
||||
CREATE TABLE def(d PRIMARY KEY, e, f);
|
||||
PRAGMA default_cache_size = 10;
|
||||
INSERT INTO abc VALUES(randstr(10,1000),randstr(10,1000),randstr(10,1000));
|
||||
INSERT INTO abc
|
||||
SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc;
|
||||
INSERT INTO abc
|
||||
SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc;
|
||||
INSERT INTO abc
|
||||
SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc;
|
||||
INSERT INTO abc
|
||||
SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc;
|
||||
INSERT INTO abc
|
||||
SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc;
|
||||
INSERT INTO abc
|
||||
SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000) FROM abc;
|
||||
COMMIT;
|
||||
}
|
||||
} {}
|
||||
|
||||
set tn 1
|
||||
foreach {::crashfile ::delay ::char} {
|
||||
test.db 1 sequential
|
||||
test.db 1 safe_append
|
||||
test.db-journal 1 sequential
|
||||
test.db-journal 1 safe_append
|
||||
test.db-journal 2 safe_append
|
||||
test.db-journal 2 sequential
|
||||
test.db-journal 3 sequential
|
||||
test.db-journal 3 safe_append
|
||||
} {
|
||||
for {set ii 0} {$ii < 100} {incr ii} {
|
||||
set ::SQL [subst {
|
||||
SELECT randstr($ii,$ii+10);
|
||||
BEGIN;
|
||||
DELETE FROM abc WHERE random()%5;
|
||||
INSERT INTO abc
|
||||
SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000)
|
||||
FROM abc
|
||||
WHERE (random()%5)==0;
|
||||
DELETE FROM def WHERE random()%5;
|
||||
INSERT INTO def
|
||||
SELECT randstr(10,1000),randstr(10,1000),randstr(10,1000)
|
||||
FROM def
|
||||
WHERE (random()%5)==0;
|
||||
COMMIT;
|
||||
}]
|
||||
|
||||
do_test crash3-2.$tn.$ii {
|
||||
crashsql -file $::crashfile -delay $::delay -char $::char $::SQL
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
execsql {PRAGMA integrity_check}
|
||||
} {ok}
|
||||
}
|
||||
incr tn
|
||||
}
|
||||
|
||||
# The following block tests an interaction between IOCAP_ATOMIC and
|
||||
# IOCAP_SEQUENTIAL. At one point, if both flags were set, small
|
||||
# journal files that contained only a single page, but were required
|
||||
# for some other reason (i.e. nTrunk) were not being written to
|
||||
# disk.
|
||||
#
|
||||
for {set ii 0} {$ii < 10} {incr ii} {
|
||||
db close
|
||||
file delete -force test.db test.db-journal
|
||||
crashsql -file test.db -char {sequential atomic} {
|
||||
CREATE TABLE abc(a, b, c);
|
||||
}
|
||||
sqlite3 db test.db
|
||||
do_test crash3-3.$ii {
|
||||
execsql {PRAGMA integrity_check}
|
||||
} {ok}
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
|
Reference in New Issue
Block a user