2014-10-21 22:09:58 +04:00
|
|
|
# 2014 October 21
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
#
|
2015-07-23 23:44:49 +03:00
|
|
|
# This file contains tests for the RBU module. Specifically, it tests the
|
|
|
|
# outcome of some other client writing to the database while an RBU update
|
2014-10-21 22:09:58 +04:00
|
|
|
# is being applied.
|
|
|
|
|
|
|
|
if {![info exists testdir]} {
|
|
|
|
set testdir [file join [file dirname [info script]] .. .. test]
|
|
|
|
}
|
|
|
|
source $testdir/tester.tcl
|
2015-07-23 23:44:49 +03:00
|
|
|
set ::testprefix rbu6
|
2014-10-21 22:09:58 +04:00
|
|
|
|
|
|
|
proc setup_test {} {
|
|
|
|
reset_db
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE);
|
|
|
|
CREATE TABLE t2(a INTEGER PRIMARY KEY, b UNIQUE);
|
|
|
|
CREATE TABLE t3(a INTEGER PRIMARY KEY, b UNIQUE);
|
|
|
|
}
|
|
|
|
db close
|
|
|
|
|
2015-07-23 23:44:49 +03:00
|
|
|
forcedelete rbu.db
|
|
|
|
sqlite3 rbu rbu.db
|
|
|
|
rbu eval {
|
|
|
|
CREATE TABLE data_t1(a, b, rbu_control);
|
|
|
|
CREATE TABLE data_t2(a, b, rbu_control);
|
|
|
|
CREATE TABLE data_t3(a, b, rbu_control);
|
2014-10-21 22:09:58 +04:00
|
|
|
INSERT INTO data_t1 VALUES(1, 't1', 0);
|
|
|
|
INSERT INTO data_t2 VALUES(2, 't2', 0);
|
|
|
|
INSERT INTO data_t3 VALUES(3, 't3', 0);
|
|
|
|
}
|
2015-07-23 23:44:49 +03:00
|
|
|
rbu close
|
2014-10-21 22:09:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Test the outcome of some other client writing the db while the *-oal
|
|
|
|
# file is being generated. Once this has happened, the update cannot be
|
|
|
|
# progressed.
|
|
|
|
#
|
2015-02-18 20:40:05 +03:00
|
|
|
for {set nStep 1} {$nStep < 8} {incr nStep} {
|
2014-10-21 22:09:58 +04:00
|
|
|
do_test 1.$nStep.1 {
|
|
|
|
setup_test
|
2015-07-23 23:44:49 +03:00
|
|
|
sqlite3rbu rbu test.db rbu.db
|
|
|
|
for {set i 0} {$i<$nStep} {incr i} {rbu step}
|
2015-02-07 22:17:36 +03:00
|
|
|
|
2015-07-23 23:44:49 +03:00
|
|
|
rbu close
|
2014-10-21 22:09:58 +04:00
|
|
|
sqlite3 db test.db
|
|
|
|
execsql { INSERT INTO t1 VALUES(5, 'hello') }
|
2015-07-23 23:44:49 +03:00
|
|
|
sqlite3rbu rbu test.db rbu.db
|
|
|
|
rbu step
|
2014-10-21 22:09:58 +04:00
|
|
|
} {SQLITE_BUSY}
|
|
|
|
do_test 1.$nStep.2 {
|
2015-07-23 23:44:49 +03:00
|
|
|
rbu step
|
2014-10-21 22:09:58 +04:00
|
|
|
} {SQLITE_BUSY}
|
|
|
|
do_test 1.$nStep.3 {
|
|
|
|
list [file exists test.db-oal] [file exists test.db-wal]
|
|
|
|
} {1 0}
|
|
|
|
do_test 1.$nStep.4 {
|
2015-07-23 23:44:49 +03:00
|
|
|
list [catch { rbu close } msg] $msg
|
|
|
|
} {1 {SQLITE_BUSY - database modified during rbu update}}
|
2014-10-21 22:09:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Test the outcome of some other client writing the db after the *-oal
|
|
|
|
# file has been copied to the *-wal path. Once this has happened, any
|
2015-07-23 23:44:49 +03:00
|
|
|
# other client writing to the db causes RBU to consider its job finished.
|
2014-10-21 22:09:58 +04:00
|
|
|
#
|
2015-02-18 20:40:05 +03:00
|
|
|
for {set nStep 8} {$nStep < 20} {incr nStep} {
|
2014-10-21 22:09:58 +04:00
|
|
|
do_test 1.$nStep.1 {
|
|
|
|
setup_test
|
2015-07-23 23:44:49 +03:00
|
|
|
sqlite3rbu rbu test.db rbu.db
|
|
|
|
for {set i 0} {$i<$nStep} {incr i} {rbu step}
|
|
|
|
rbu close
|
2014-10-21 22:09:58 +04:00
|
|
|
sqlite3 db test.db
|
|
|
|
execsql { INSERT INTO t1 VALUES(5, 'hello') }
|
2015-07-23 23:44:49 +03:00
|
|
|
sqlite3rbu rbu test.db rbu.db
|
|
|
|
rbu step
|
2014-10-21 22:09:58 +04:00
|
|
|
} {SQLITE_DONE}
|
|
|
|
do_test 1.$nStep.2 {
|
2015-07-23 23:44:49 +03:00
|
|
|
rbu step
|
2014-10-21 22:09:58 +04:00
|
|
|
} {SQLITE_DONE}
|
|
|
|
do_test 1.$nStep.3 {
|
|
|
|
file exists test.db-oal
|
|
|
|
} {0}
|
|
|
|
do_test 1.$nStep.4 {
|
2015-07-23 23:44:49 +03:00
|
|
|
list [catch { rbu close } msg] $msg
|
2014-10-21 22:09:58 +04:00
|
|
|
} {0 SQLITE_DONE}
|
|
|
|
|
|
|
|
do_execsql_test 1.$nStep.5 {
|
|
|
|
SELECT * FROM t1;
|
|
|
|
} {1 t1 5 hello}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
finish_test
|