xref: /sqlite-3.40.0/test/walslow.test (revision 7c24610e)
1*7c24610eSdan# 2010 March 17
2*7c24610eSdan#
3*7c24610eSdan# The author disclaims copyright to this source code.  In place of
4*7c24610eSdan# a legal notice, here is a blessing:
5*7c24610eSdan#
6*7c24610eSdan#    May you do good and not evil.
7*7c24610eSdan#    May you find forgiveness for yourself and forgive others.
8*7c24610eSdan#    May you share freely, never taking more than you give.
9*7c24610eSdan#
10*7c24610eSdan#***********************************************************************
11*7c24610eSdan#
12*7c24610eSdan
13*7c24610eSdanset testdir [file dirname $argv0]
14*7c24610eSdansource $testdir/tester.tcl
15*7c24610eSdan
16*7c24610eSdanproc reopen_db {} {
17*7c24610eSdan  catch { db close }
18*7c24610eSdan  file delete -force test.db test.db-wal
19*7c24610eSdan  sqlite3 db test.db
20*7c24610eSdan  execsql { PRAGMA journal_mode = wal }
21*7c24610eSdan}
22*7c24610eSdan
23*7c24610eSdandb close
24*7c24610eSdansave_prng_state
25*7c24610eSdanfor {set seed 1} {$seed<10} {incr seed} {
26*7c24610eSdan  expr srand($seed)
27*7c24610eSdan  restore_prng_state
28*7c24610eSdan  reopen_db
29*7c24610eSdan  do_test walslow-1.seed=$seed.0 {
30*7c24610eSdan    execsql { CREATE TABLE t1(a, b) }
31*7c24610eSdan    execsql { CREATE INDEX i1 ON t1(a) }
32*7c24610eSdan    execsql { CREATE INDEX i2 ON t1(b) }
33*7c24610eSdan  } {}
34*7c24610eSdan
35*7c24610eSdan  for {set iTest 1} {$iTest < 100} {incr iTest} {
36*7c24610eSdan
37*7c24610eSdan    do_test walslow-1.seed=$seed.$iTest.1 {
38*7c24610eSdan      set w [expr int(rand()*2000)]
39*7c24610eSdan      set x [expr int(rand()*2000)]
40*7c24610eSdan      set y [expr int(rand()*9)+1]
41*7c24610eSdan      set z [expr int(rand()*2)]
42*7c24610eSdan      execsql { INSERT INTO t1 VALUES(randomblob($w), randomblob($x)) }
43*7c24610eSdan      execsql { PRAGMA integrity_check }
44*7c24610eSdan    } {ok}
45*7c24610eSdan
46*7c24610eSdan    do_test walslow-1.seed=$seed.$iTest.2 {
47*7c24610eSdan      execsql "PRAGMA checkpoint('$y $y $z')"
48*7c24610eSdan      execsql { PRAGMA integrity_check }
49*7c24610eSdan    } {ok}
50*7c24610eSdan
51*7c24610eSdan    do_test walslow-1.seed=$seed.$iTest.3 {
52*7c24610eSdan      file delete -force testX.db testX.db-wal
53*7c24610eSdan      file copy test.db testX.db
54*7c24610eSdan      file copy test.db-wal testX.db-wal
55*7c24610eSdan
56*7c24610eSdan      sqlite3 db2 testX.db
57*7c24610eSdan      execsql { PRAGMA journal_mode = WAL } db2
58*7c24610eSdan      execsql { PRAGMA integrity_check } db2
59*7c24610eSdan    } {ok}
60*7c24610eSdan
61*7c24610eSdan    do_test walslow-1.seed=$seed.$iTest.4 {
62*7c24610eSdan      execsql { SELECT count(*) FROM t1 WHERE a!=b } db2
63*7c24610eSdan    } [execsql { SELECT count(*) FROM t1 WHERE a!=b }]
64*7c24610eSdan    db2 close
65*7c24610eSdan  }
66*7c24610eSdan}
67*7c24610eSdan
68*7c24610eSdan
69*7c24610eSdanfinish_test
70