blob: edc24bda7e1515359867ed6ef12f1939642b06df [file] [log] [blame]
dan273f3f02010-06-26 15:42:33 +00001# 2010 June 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# The tests in this file test the pager modules response to various
13# fault conditions (OOM, IO error, disk full etc.). They are similar
14# to those in file pagerfault1.test.
15#
16# More specifically, the tests in this file are those deemed too slow to
17# run as part of pagerfault1.test.
18#
19
20set testdir [file dirname $argv0]
21source $testdir/tester.tcl
22source $testdir/lock_common.tcl
23source $testdir/malloc_common.tcl
24
danc396d4a2010-07-02 11:27:43 +000025sqlite3_memdebug_vfs_oom_test 0
26
dan273f3f02010-06-26 15:42:33 +000027set a_string_counter 1
28proc a_string {n} {
29 global a_string_counter
30 incr a_string_counter
31 string range [string repeat "${a_string_counter}." $n] 1 $n
32}
33db func a_string a_string
34
dan273f3f02010-06-26 15:42:33 +000035do_test pagerfault2-1-pre1 {
36 faultsim_delete_and_reopen
37 db func a_string a_string
38 execsql {
39 PRAGMA journal_mode = DELETE;
danc396d4a2010-07-02 11:27:43 +000040 PRAGMA page_size = 1024;
dan273f3f02010-06-26 15:42:33 +000041 CREATE TABLE t1(a, b);
42 INSERT INTO t1 VALUES(a_string(401), a_string(402));
43 }
danc396d4a2010-07-02 11:27:43 +000044 for {set ii 0} {$ii < 13} {incr ii} {
dan273f3f02010-06-26 15:42:33 +000045 execsql { INSERT INTO t1 SELECT a_string(401), a_string(402) FROM t1 }
46 }
47 faultsim_save_and_close
danc396d4a2010-07-02 11:27:43 +000048 file size test.db
49} [expr 1024 * 8268]
50
51do_faultsim_test pagerfault2-1 -faults oom-transient -prep {
dan273f3f02010-06-26 15:42:33 +000052 faultsim_restore_and_reopen
danc396d4a2010-07-02 11:27:43 +000053 sqlite3_db_config_lookaside db 0 256 4096
dan273f3f02010-06-26 15:42:33 +000054 execsql {
55 BEGIN;
danc396d4a2010-07-02 11:27:43 +000056 SELECT * FROM t1;
dan273f3f02010-06-26 15:42:33 +000057 INSERT INTO t1 VALUES(5, 6);
58 SAVEPOINT abc;
danc396d4a2010-07-02 11:27:43 +000059 UPDATE t1 SET a = a||'x' WHERE rowid<3700;
dan273f3f02010-06-26 15:42:33 +000060 }
61} -body {
danc396d4a2010-07-02 11:27:43 +000062 execsql { UPDATE t1 SET a = a||'x' WHERE rowid>=3700 AND rowid<=4200 }
dan273f3f02010-06-26 15:42:33 +000063 execsql { ROLLBACK TO abc }
64} -test {
65 faultsim_test_result {0 {}}
dan273f3f02010-06-26 15:42:33 +000066}
67
danc396d4a2010-07-02 11:27:43 +000068do_test pagerfault2-2-pre1 {
69 faultsim_restore_and_reopen
70 execsql { DELETE FROM t1 }
71 faultsim_save_and_close
72} {}
73
74do_faultsim_test pagerfault2-2 -faults oom-transient -prep {
75 faultsim_restore_and_reopen
76 sqlite3_db_config_lookaside db 0 256 4096
77 db func a_string a_string
78
79 execsql {
80 PRAGMA cache_size = 20;
81 BEGIN;
82 INSERT INTO t1 VALUES(a_string(401), a_string(402));
83 SAVEPOINT abc;
84 }
85} -body {
86 execsql { INSERT INTO t1 VALUES (a_string(2000000), a_string(2500000)) }
87} -test {
88 faultsim_test_result {0 {}}
89}
90
91sqlite3_memdebug_vfs_oom_test 1
dan273f3f02010-06-26 15:42:33 +000092finish_test
danc396d4a2010-07-02 11:27:43 +000093