xref: /sqlite-3.40.0/test/writecrash.test (revision 33447e77)
1# 2009 January 8
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# Test the outcome of a writer crashing within a call to the VFS
13# xWrite function.
14#
15
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19set testprefix writecrash
20
21do_not_use_codec
22
23do_execsql_test 1.0 {
24  CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB UNIQUE);
25  WITH s(i) AS (
26    VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<100
27  )
28  INSERT INTO t1 SELECT NULL, randomblob(900) FROM s;
29} {}
30
31set bGo 1
32for {set tn 1} {$bGo} {incr tn} {
33
34db close
35sqlite3 db test.db
36
37  do_test 1.$tn.1 {
38    set res [crash_on_write $tn {
39      UPDATE t1 SET b = randomblob(899) WHERE (a%3)==0
40    }]
41    set bGo 0
42    if {[string match {1 {child killed:*}} $res]} {
43      set res {0 {}}
44      set bGo 1
45    }
46    set res
47  } {0 {}}
48
49#db close
50#sqlite3 db test.db
51
52  do_execsql_test 1.$tn.2 { PRAGMA integrity_check } {ok}
53
54db close
55sqlite3 db test.db
56
57  do_execsql_test 1.$tn.3 { PRAGMA integrity_check } {ok}
58}
59
60
61
62finish_test
63