xref: /sqlite-3.40.0/test/writecrash.test (revision 2fc2f92e)
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
23
24if {$tcl_platform(platform)=="windows"} {
25  finish_test
26  return
27}
28
29do_execsql_test 1.0 {
30  CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB UNIQUE);
31  WITH s(i) AS (
32    VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<100
33  )
34  INSERT INTO t1 SELECT NULL, randomblob(900) FROM s;
35} {}
36
37set bGo 1
38for {set tn 1} {$bGo} {incr tn} {
39
40db close
41sqlite3 db test.db
42
43  do_test 1.$tn.1 {
44    set res [crash_on_write $tn {
45      UPDATE t1 SET b = randomblob(899) WHERE (a%3)==0
46    }]
47    set bGo 0
48    if {[string match {1 {child killed:*}} $res]} {
49      set res {0 {}}
50      set bGo 1
51    }
52    set res
53  } {0 {}}
54
55#db close
56#sqlite3 db test.db
57
58  do_execsql_test 1.$tn.2 { PRAGMA integrity_check } {ok}
59
60db close
61sqlite3 db test.db
62
63  do_execsql_test 1.$tn.3 { PRAGMA integrity_check } {ok}
64}
65
66
67
68finish_test
69