3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. Specifically,
12 # it tests that ticket [fc62af4523] has been resolved.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 source $testdir/lock_common.tcl
18 source $testdir/malloc_common.tcl
20 do_test tkt-fc62af4523.1 {
22 PRAGMA cache_size = 10;
23 PRAGMA journal_mode = persist;
24 CREATE TABLE t1(a UNIQUE, b UNIQUE);
25 INSERT INTO t1 SELECT randomblob(200), randomblob(300);
26 INSERT INTO t1 SELECT randomblob(200), randomblob(300) FROM t1; -- 2
27 INSERT INTO t1 SELECT randomblob(200), randomblob(300) FROM t1; -- 4
28 INSERT INTO t1 SELECT randomblob(200), randomblob(300) FROM t1; -- 8
29 INSERT INTO t1 SELECT randomblob(200), randomblob(300) FROM t1; -- 16
30 INSERT INTO t1 SELECT randomblob(200), randomblob(300) FROM t1; -- 32
31 INSERT INTO t1 SELECT randomblob(200), randomblob(300) FROM t1; -- 64
34 PRAGMA integrity_check;
35 SELECT count(*) FROM t1;
39 # Launch an external process. Have it write (but not commit) a large
40 # transaction to the database.
42 set ::chan [launch_testfixture]
43 proc buddy {code} { testfixture $::chan $code }
44 do_test tkt-fc62af4523.2 {
48 PRAGMA cache_size = 10;
50 UPDATE t1 SET b = randomblob(400);
51 UPDATE t1 SET a = randomblob(201);
54 file exists test.db-journal
57 # Now do "PRAGMA journal_mode = DELETE" in this process. At one point
58 # this was causing SQLite to delete the journal file from the file-system,
59 # even though the external process is currently using it.
61 do_test tkt-fc62af4523.3 { execsql { PRAGMA journal_mode = DELETE } } {delete}
62 do_test tkt-fc62af4523.4 { file exists test.db-journal } {1}
64 # Cause the external process to crash. Since it has already written
65 # uncommitted data into the database file, the next reader will have
66 # to do a hot-journal rollback to recover the database.
68 # Or, if this test is run in a version with the bug present, the journal
69 # file has already been deleted. In this case we are left with a corrupt
70 # database file and no hot-journal to fix it with.
72 do_test tkt-fc62af4523.5 {
73 testfixture $::chan sqlite_abort
74 } {ERROR: Child process hung up}
76 do_test tkt-fc62af4523.6 {
78 PRAGMA integrity_check;
79 SELECT count(*) FROM t1;
83 catch { close $::chan }