Debian Codegraph @

test/walfault2.test

raw
1 # 2010 May 03
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 # This file implements regression tests for SQLite library. The
12 # focus of this file is testing the operation of the library in
13 # "PRAGMA journal_mode=WAL" mode.
14 #
15
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 source $testdir/malloc_common.tcl
19 source $testdir/lock_common.tcl
20
21 ifcapable !wal {finish_test ; return }
22 set testprefix walfault2
23
24 #-------------------------------------------------------------------------
25 # Inject faults while truncating the wal file.
26 #
27 do_execsql_test 1.0 {
28 PRAGMA auto_vacuum = 0;
29 CREATE TABLE t1(a, b);
30 PRAGMA journal_mode = wal;
31 WITH s(i) AS (
32 SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 30
33 )
34 INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM s;
35 } {wal}
36 faultsim_save_and_close
37
38 do_faultsim_test 1 -prep {
39 catch { db close }
40 faultsim_restore
41 sqlite3 db file:test.db?psow=0 -uri 1
42 file_control_powersafe_overwrite db 0
43 execsql {
44 PRAGMA wal_checkpoint;
45 PRAGMA journal_size_limit = 10000;
46 PRAGMA synchronous = full;
47 }
48 } -body {
49 execsql { INSERT INTO t1 VALUES(1,1) }
50 } -test {
51 faultsim_test_result {0 {}}
52 }
53
54 #-------------------------------------------------------------------------
55 # Inject faults while rewriting checksums.
56 #
57 reset_db
58 do_execsql_test 2.0 {
59 PRAGMA auto_vacuum = 0;
60 CREATE TABLE t1(a, b);
61 PRAGMA journal_mode = wal;
62 WITH s(i) AS (
63 SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 30
64 )
65 INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM s;
66 } {wal}
67 faultsim_save_and_close
68
69 do_faultsim_test 2 -prep {
70 faultsim_restore_and_reopen
71 execsql {
72 PRAGMA cache_size = 2;
73 BEGIN;
74 UPDATE t1 SET a=randomblob(400);
75 UPDATE t1 SET b=randomblob(400);
76 UPDATE t1 SET a=randomblob(400);
77 UPDATE t1 SET b=randomblob(400);
78 UPDATE t1 SET a=randomblob(400);
79 UPDATE t1 SET b=randomblob(400);
80 UPDATE t1 SET a=randomblob(400);
81 UPDATE t1 SET b=randomblob(400);
82 }
83 } -body {
84 execsql COMMIT
85 } -test {
86 faultsim_test_result {0 {}}
87 }
88
89
90
91 finish_test