sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / test / tkt-fc62af4523.test
| 1 | # 2010 June 16 |
| 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. Specifically, |
| 12 | # it tests that ticket [fc62af4523] has been resolved. |
| 13 | # |
| 14 | |
| 15 | set testdir [file dirname $argv0] |
| 16 | source $testdir/tester.tcl |
| 17 | source $testdir/lock_common.tcl |
| 18 | source $testdir/malloc_common.tcl |
| 19 | |
| 20 | do_test tkt-fc62af4523.1 { |
| 21 | execsql { |
| 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 |
| 32 | } |
| 33 | execsql { |
| 34 | PRAGMA integrity_check; |
| 35 | SELECT count(*) FROM t1; |
| 36 | } |
| 37 | } {ok 64} |
| 38 | |
| 39 | # Launch an external process. Have it write (but not commit) a large |
| 40 | # transaction to the database. |
| 41 | # |
| 42 | set ::chan [launch_testfixture] |
| 43 | proc buddy {code} { testfixture $::chan $code } |
| 44 | do_test tkt-fc62af4523.2 { |
| 45 | testfixture $::chan { |
| 46 | sqlite3 db test.db |
| 47 | db eval { |
| 48 | PRAGMA cache_size = 10; |
| 49 | BEGIN; |
| 50 | UPDATE t1 SET b = randomblob(400); |
| 51 | UPDATE t1 SET a = randomblob(201); |
| 52 | } |
| 53 | } |
| 54 | file exists test.db-journal |
| 55 | } {1} |
| 56 | |
| 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. |
| 60 | # |
| 61 | do_test tkt-fc62af4523.3 { execsql { PRAGMA journal_mode = DELETE } } {delete} |
| 62 | do_test tkt-fc62af4523.4 { file exists test.db-journal } {1} |
| 63 | |
| 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. |
| 67 | # |
| 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. |
| 71 | # |
| 72 | do_test tkt-fc62af4523.5 { |
| 73 | testfixture $::chan sqlite_abort |
| 74 | } {ERROR: Child process hung up} |
| 75 | after 200 |
| 76 | do_test tkt-fc62af4523.6 { |
| 77 | execsql { |
| 78 | PRAGMA integrity_check; |
| 79 | SELECT count(*) FROM t1; |
| 80 | } |
| 81 | } {ok 64} |
| 82 | |
| 83 | catch { close $::chan } |
| 84 | finish_test |