sqlite/test/crash.test

84 lines
2.1 KiB
Plaintext
Raw Normal View History

# 2001 September 15
#
# 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 implements regression tests for SQLite library.
#
# $Id: crash.test,v 1.2 2004/06/23 01:05:27 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# This proc execs a seperate process that crashes midway through executing
# the SQL script $sql on database test.db.
#
# Argument $crashdelay indicates the number of file closes or syncs to wait
# before crashing. When a crash occurs a random subset of unsynced writes
# are written into any open files.
proc crashsql {crashdelay sql} {
set f [open crash.tcl w]
puts $f "sqlite3_crashseed $crashdelay"
puts $f "sqlite3 db test.db"
puts $f "db eval {"
puts $f "$sql"
puts $f "}"
close $f
exec [file join . crashtest] crash.tcl
}
# Simple crash test:
#
# crash-1.1: Create a database with a table with two rows.
# crash-1.2: Run a 'DELETE FROM abc WHERE a = 1' that crashes during
# journal-sync
# crash-1.3: Ensure the database is in the same state as after crash-1.1.
# crash-1.4: Run a 'DELETE FROM abc WHERE a = 1' that crashes during
# database-sync
# crash-1.5: Ensure the database is in the same state as after crash-1.1.
#
do_test crash-1.1 {
execsql {
CREATE TABLE abc(a, b, c);
INSERT INTO abc VALUES(1, 2, 3);
INSERT INTO abc VALUES(4, 5, 6);
}
} {}
do_test crash-1.2 {
catch {
crashsql 1 {
DELETE FROM abc WHERE a = 1;
}
} msg
set msg
} {child process exited abnormally}
do_test crash-1.3 {
catchsql {
SELECT * FROM abc;
}
} {0 {1 2 3 4 5 6}}
do_test crash-1.4 {
catch {
crashsql 1 {
DELETE FROM abc WHERE a = 1;
}
} msg
set msg
} {child process exited abnormally}
do_test crash-1.5 {
catchsql {
SELECT * FROM abc;
}
} {0 {1 2 3 4 5 6}}
finish_test