blob: 83f292281a33030bec43abfb20ef97bf3c586272 [file] [log] [blame]
dan7c246102010-04-12 19:00:29 +00001# 2010 March 17
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#***********************************************************************
dand3f8f942010-04-13 11:35:01 +000011# 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. The tests in this file use
14# brute force methods, so may take a while to run.
dan7c246102010-04-12 19:00:29 +000015#
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
dan5cf53532010-05-01 16:40:20 +000020ifcapable !wal {finish_test ; return }
21
dan7c246102010-04-12 19:00:29 +000022proc reopen_db {} {
23 catch { db close }
mistachkinfda06be2011-08-02 00:57:34 +000024 forcedelete test.db test.db-wal
dan7c246102010-04-12 19:00:29 +000025 sqlite3 db test.db
26 execsql { PRAGMA journal_mode = wal }
27}
28
29db close
30save_prng_state
31for {set seed 1} {$seed<10} {incr seed} {
32 expr srand($seed)
33 restore_prng_state
34 reopen_db
35 do_test walslow-1.seed=$seed.0 {
36 execsql { CREATE TABLE t1(a, b) }
37 execsql { CREATE INDEX i1 ON t1(a) }
38 execsql { CREATE INDEX i2 ON t1(b) }
39 } {}
40
41 for {set iTest 1} {$iTest < 100} {incr iTest} {
42
43 do_test walslow-1.seed=$seed.$iTest.1 {
44 set w [expr int(rand()*2000)]
45 set x [expr int(rand()*2000)]
dan7c246102010-04-12 19:00:29 +000046 execsql { INSERT INTO t1 VALUES(randomblob($w), randomblob($x)) }
47 execsql { PRAGMA integrity_check }
48 } {ok}
49
50 do_test walslow-1.seed=$seed.$iTest.2 {
dan5a299f92010-05-03 11:05:08 +000051 execsql "PRAGMA wal_checkpoint;"
dan7c246102010-04-12 19:00:29 +000052 execsql { PRAGMA integrity_check }
53 } {ok}
54
55 do_test walslow-1.seed=$seed.$iTest.3 {
mistachkinfda06be2011-08-02 00:57:34 +000056 forcedelete testX.db testX.db-wal
57 copy_file test.db testX.db
58 copy_file test.db-wal testX.db-wal
dan7c246102010-04-12 19:00:29 +000059
60 sqlite3 db2 testX.db
61 execsql { PRAGMA journal_mode = WAL } db2
62 execsql { PRAGMA integrity_check } db2
63 } {ok}
64
65 do_test walslow-1.seed=$seed.$iTest.4 {
66 execsql { SELECT count(*) FROM t1 WHERE a!=b } db2
67 } [execsql { SELECT count(*) FROM t1 WHERE a!=b }]
68 db2 close
69 }
70}
71
72
73finish_test