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 #***********************************************************************
12 # This file contains tests for the RBU module. Specifically, it tests the
13 # outcome of some other client writing to the database while an RBU update
16 if {![info exists testdir]} {
17 set testdir [file join [file dirname [info script]] .. .. test]
19 source $testdir/tester.tcl
25 CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE);
26 CREATE TABLE t2(a INTEGER PRIMARY KEY, b UNIQUE);
27 CREATE TABLE t3(a INTEGER PRIMARY KEY, b UNIQUE);
34 CREATE TABLE data_t1(a, b, rbu_control);
35 CREATE TABLE data_t2(a, b, rbu_control);
36 CREATE TABLE data_t3(a, b, rbu_control);
37 INSERT INTO data_t1 VALUES(1, 't1', 0);
38 INSERT INTO data_t2 VALUES(2, 't2', 0);
39 INSERT INTO data_t3 VALUES(3, 't3', 0);
44 # Test the outcome of some other client writing the db while the *-oal
45 # file is being generated. Once this has happened, the update cannot be
48 for {set nStep 1} {$nStep < 8} {incr nStep} {
51 sqlite3rbu rbu test.db rbu.db
52 for {set i 0} {$i<$nStep} {incr i} {rbu step}
56 execsql { INSERT INTO t1 VALUES(5, 'hello') }
57 sqlite3rbu rbu test.db rbu.db
64 list [file exists test.db-oal] [file exists test.db-wal]
67 list [catch { rbu close } msg] $msg
68 } {1 {SQLITE_BUSY - database modified during rbu update}}
71 # Test the outcome of some other client writing the db after the *-oal
72 # file has been copied to the *-wal path. Once this has happened, any
73 # other client writing to the db causes RBU to consider its job finished.
75 for {set nStep 8} {$nStep < 20} {incr nStep} {
78 sqlite3rbu rbu test.db rbu.db
79 for {set i 0} {$i<$nStep} {incr i} {rbu step}
82 execsql { INSERT INTO t1 VALUES(5, 'hello') }
83 sqlite3rbu rbu test.db rbu.db
90 file exists test.db-oal
93 list [catch { rbu close } msg] $msg
96 do_execsql_test 1.$nStep.5 {