blob: 8dc99e0bc07d884d2a55d99167e2969a23aab884 [file] [log] [blame]
danb0ac3e32010-06-16 10:55:42 +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
13set testdir [file dirname $argv0]
14source $testdir/tester.tcl
15source $testdir/lock_common.tcl
16source $testdir/malloc_common.tcl
17
18set a_string_counter 1
19proc a_string {n} {
20 global a_string_counter
21 incr a_string_counter
22 string range [string repeat "${a_string_counter}." $n] 1 $n
23}
24db func a_string a_string
25
26#-------------------------------------------------------------------------
27# Test fault-injection while rolling back a hot-journal file.
28#
29do_test pagerfault-1-pre1 {
30 execsql {
31 PRAGMA journal_mode = DELETE;
32 PRAGMA cache_size = 10;
33 CREATE TABLE t1(a UNIQUE, b UNIQUE);
34 INSERT INTO t1 VALUES(a_string(200), a_string(300));
35 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
36 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
37 BEGIN;
38 INSERT INTO t1 SELECT a_string(201), a_string(301) FROM t1;
39 INSERT INTO t1 SELECT a_string(202), a_string(302) FROM t1;
40 INSERT INTO t1 SELECT a_string(203), a_string(303) FROM t1;
41 INSERT INTO t1 SELECT a_string(204), a_string(304) FROM t1;
42 }
43 faultsim_save_and_close
44} {}
45do_faultsim_test pagerfault-1 -prep {
46 faultsim_restore_and_reopen
47} -body {
48 execsql { SELECT count(*) FROM t1 }
49} -test {
50 faultsim_test_result {0 4}
51 faultsim_integrity_check
52 if {[db one { SELECT count(*) FROM t1 }] != 4} {
53 error "Database content appears incorrect"
54 }
55}
56
57#-------------------------------------------------------------------------
58# Test fault-injection while rolling back hot-journals that were created
59# as part of a multi-file transaction.
60#
61do_test pagerfault-2-pre1 {
62 testvfs tstvfs -default 1
63 tstvfs filter xDelete
64 tstvfs script xDeleteCallback
65
66 proc xDeleteCallback {method file args} {
67 set file [file tail $file]
68 if { [string match *mj* $file] } { faultsim_save }
69 }
70
71 faultsim_delete_and_reopen
72 db func a_string a_string
73
74 execsql {
75 ATTACH 'test.db2' AS aux;
76 PRAGMA journal_mode = DELETE;
77 PRAGMA main.cache_size = 10;
78 PRAGMA aux.cache_size = 10;
79
80 CREATE TABLE t1(a UNIQUE, b UNIQUE);
81 CREATE TABLE aux.t2(a UNIQUE, b UNIQUE);
82 INSERT INTO t1 VALUES(a_string(200), a_string(300));
83 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
84 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
85 INSERT INTO t2 SELECT * FROM t1;
86
87 BEGIN;
88 INSERT INTO t1 SELECT a_string(201), a_string(301) FROM t1;
89 INSERT INTO t1 SELECT a_string(202), a_string(302) FROM t1;
90 INSERT INTO t1 SELECT a_string(203), a_string(303) FROM t1;
91 INSERT INTO t1 SELECT a_string(204), a_string(304) FROM t1;
92 REPLACE INTO t2 SELECT * FROM t1;
93 COMMIT;
94 }
95
96 db close
97 tstvfs delete
98} {}
99do_faultsim_test pagerfault-2 -faults ioerr-persistent -prep {
100 faultsim_restore_and_reopen
101} -body {
102 execsql {
103 ATTACH 'test.db2' AS aux;
104 SELECT count(*) FROM t2;
105 SELECT count(*) FROM t1;
106 }
107} -test {
108 faultsim_test_result {0 {4 4}} {1 {unable to open database: test.db2}}
109 faultsim_integrity_check
110
111 catchsql { ATTACH 'test.db2' AS aux }
112 if {[db one { SELECT count(*) FROM t1 }] != 4
113 || [db one { SELECT count(*) FROM t2 }] != 4
114 } {
115 error "Database content appears incorrect"
116 }
117}
118
119finish_test