1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Add another fault-injection test for sqlite3_snapshot_recover().

FossilOrigin-Name: 7e040406138669bd67dd6ecae016b3e50dbfaaf8
This commit is contained in:
dan
2016-11-19 17:20:28 +00:00
parent 6a9e7f16eb
commit 20ba3d7fcb
3 changed files with 44 additions and 13 deletions

View File

@ -17,8 +17,6 @@ source $testdir/tester.tcl
ifcapable !snapshot {finish_test; return}
set testprefix snapshot_fault
if 1 {
#-------------------------------------------------------------------------
# Check that an sqlite3_snapshot_open() client cannot be tricked into
# reading a corrupt snapshot even if a second client fails while
@ -161,8 +159,6 @@ do_faultsim_test 3.0 -prep {
sqlite3_snapshot_free $::snapshot
}
}
#-------------------------------------------------------------------------
# Test the handling of faults that occur within sqlite3_snapshot_recover().
#
@ -175,14 +171,14 @@ do_execsql_test 4.0 {
} {wal}
faultsim_save_and_close
do_test 4.1 {
do_test 4.0.1 {
faultsim_restore_and_reopen
db eval { SELECT * FROM sqlite_master }
sqlite3_snapshot_recover db main
} {}
db close
do_faultsim_test 4 -faults oom* -prep {
do_faultsim_test 4.0 -faults oom* -prep {
faultsim_restore_and_reopen
db eval { SELECT * FROM sqlite_master }
} -body {
@ -191,5 +187,40 @@ do_faultsim_test 4 -faults oom* -prep {
faultsim_test_result {0 {}} {1 SQLITE_NOMEM} {1 SQLITE_IOERR_NOMEM}
}
# The following test cases contrive to call sqlite3_snapshot_recover()
# before all pages of the *-shm file have been mapped. This tests an
# extra branch of error handling logic in snapshot_recover().
#
reset_db
do_execsql_test 4.1.0 {
PRAGMA page_size = 512;
PRAGMA journal_mode = wal;
PRAGMA wal_autocheckpoint = 0;
CREATE TABLE t1(zzz);
INSERT INTO t1 VALUES(randomblob( 500 * 9500 ));
PRAGMA user_version = 211;
} {wal 0}
do_test 4.1.1 {
list [file size test.db-shm] [file size test.db]
} {98304 512}
faultsim_save_and_close
do_faultsim_test 4.1 -faults shm* -prep {
catch { db2 close }
catch { db close }
faultsim_restore_and_reopen
sqlite3 db2 test.db
db2 eval { SELECT * FROM sqlite_master }
db eval BEGIN
sqlite3_snapshot_get_blob db main
db eval COMMIT
} -body {
sqlite3_snapshot_recover db main
} -test {
faultsim_test_result {0 {}} {1 SQLITE_IOERR}
}
finish_test