summaryrefslogtreecommitdiffstats
path: root/ext/rbu/rbucrash2.test
blob: 9ff6eba4f22ec0dcef3e00c0fa3c70361fb3578a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# 2017 March 02
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#

if {![info exists testdir]} {
  set testdir [file join [file dirname [info script]] .. .. test]
}
source $testdir/tester.tcl
set ::testprefix rbucrash2

db close
forcedelete test.db-oal rbu.db
sqlite3_shutdown
sqlite3_config_uri 1
reset_db

# Set up a target database and an rbu update database. The target
# db is the usual "test.db", the rbu db is "test.db2".
#
forcedelete test.db2
do_execsql_test 1.0 {
  CREATE TABLE t1(a, b, c, PRIMARY KEY(a), UNIQUE(b));
  INSERT INTO t1 VALUES(1, 2, 3);
  INSERT INTO t1 VALUES(4, 5, 6);
  INSERT INTO t1 VALUES(7, 8, 9);

  ATTACH 'test.db2' AS rbu;
  CREATE TABLE rbu.data_t1(a, b, c, rbu_control);
  INSERT INTO data_t1 VALUES('one', randomblob(3500), NULL, 0);
  INSERT INTO data_t1 VALUES('two', randomblob(3500), NULL, 0);
  INSERT INTO data_t1 VALUES('three', randomblob(3500), NULL, 0);
  INSERT INTO data_t1 VALUES('four', randomblob(3500), NULL, 0);
  INSERT INTO data_t1 VALUES('five', randomblob(3500), NULL, 0);
  INSERT INTO data_t1 VALUES('six', randomblob(3500), NULL, 0);
}
db_save_and_close

proc do_rbu_crash_test2 {tn script} {

  foreach {f blksz} {
    test.db   512
    test.db2  512
    test.db   4096
    test.db2  4096
  } {
    set bDone 0
    for {set iDelay 1} {$bDone==0} {incr iDelay} {
      forcedelete test.db2 test.db2-journal test.db test.db-oal test.db-wal
      db_restore
  
      set res [
        crashsql -file $f -delay $iDelay -tclbody $script -dflt 1 -opendb {} \
            -blocksize $blksz {}
      ]
  
      set bDone 1
      if {$res == "1 {child process exited abnormally}"} {
        set bDone 0
      } elseif {$res != "0 {}"} {
        error "unexected catchsql result: $res"
      }
  
      sqlite3rbu rbu test.db test.db2
      while {[rbu step]=="SQLITE_OK"} {}
      rbu close
  
      sqlite3 db test.db
      do_execsql_test $tn.delay=$iDelay.f=$f.blksz=$blksz {
        PRAGMA integrity_check;
      } {ok}
      db close
    }
  }
}

for {set x 1} {$x < 10} {incr x} {
  do_rbu_crash_test2 1.$x {
    sqlite3rbu rbu test.db test.db2
    while {[rbu step]=="SQLITE_OK"} {
      rbu savestate
    }
    rbu close
  }
}

for {set x 1} {$x < 2} {incr x} {
  do_rbu_crash_test2 2.$x {
    sqlite3rbu rbu test.db test.db2
    while {[rbu step]=="SQLITE_OK"} {
      rbu close
      sqlite3rbu rbu test.db test.db2
    }
    rbu close
  }
}

finish_test