Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/rbu/rbu6.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / rbu / rbu6.test` 100 lines ยท 2802 bytes Raw Blame History 1 # 2014 October 21 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 #*********************************************************************** 11 # 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 14 # is being applied. 15 16 source [file join [file dirname [info script]] rbu_common.tcl] 17 if_no_rbu_support { finish_test ; return } 18 set ::testprefix rbu6 19 20 proc setup_test {} { 21 reset_db 22 execsql { 23 CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE); 24 CREATE TABLE t2(a INTEGER PRIMARY KEY, b UNIQUE); 25 CREATE TABLE t3(a INTEGER PRIMARY KEY, b UNIQUE); 26 } 27 db close 28 29 forcedelete rbu.db 30 sqlite3 rbu rbu.db 31 rbu eval { 32 CREATE TABLE data_t1(a, b, rbu_control); 33 CREATE TABLE data_t2(a, b, rbu_control); 34 CREATE TABLE data_t3(a, b, rbu_control); 35 INSERT INTO data_t1 VALUES(1, 't1', 0); 36 INSERT INTO data_t2 VALUES(2, 't2', 0); 37 INSERT INTO data_t3 VALUES(3, 't3', 0); 38 } 39 rbu close 40 } 41 42 # Test the outcome of some other client writing the db while the *-oal 43 # file is being generated. Once this has happened, the update cannot be 44 # progressed. 45 # 46 for {set nStep 1} {$nStep < 8} {incr nStep} { 47 do_test 1.$nStep.1 { 48 setup_test 49 sqlite3rbu rbu test.db rbu.db 50 for {set i 0} {$i<$nStep} {incr i} {rbu step} 51 52 rbu close 53 sqlite3 db test.db 54 execsql { INSERT INTO t1 VALUES(5, 'hello') } 55 sqlite3rbu rbu test.db rbu.db 56 rbu step 57 } {SQLITE_BUSY} 58 do_test 1.$nStep.2 { 59 rbu step 60 } {SQLITE_BUSY} 61 do_test 1.$nStep.3 { 62 list [file exists test.db-oal] [file exists test.db-wal] 63 } {1 0} 64 do_test 1.$nStep.4 { 65 list [catch { rbu close } msg] $msg 66 } {1 {SQLITE_BUSY - database modified during rbu update}} 67 } 68 69 # Test the outcome of some other client writing the db after the *-oal 70 # file has been copied to the *-wal path. Once this has happened, any 71 # other client writing to the db causes RBU to consider its job finished. 72 # 73 for {set nStep 8} {$nStep < 20} {incr nStep} { 74 do_test 1.$nStep.1 { 75 setup_test 76 sqlite3rbu rbu test.db rbu.db 77 for {set i 0} {$i<$nStep} {incr i} {rbu step} 78 rbu close 79 sqlite3 db test.db 80 execsql { INSERT INTO t1 VALUES(5, 'hello') } 81 sqlite3rbu rbu test.db rbu.db 82 rbu step 83 } {SQLITE_DONE} 84 do_test 1.$nStep.2 { 85 rbu step 86 } {SQLITE_DONE} 87 do_test 1.$nStep.3 { 88 file exists test.db-oal 89 } {0} 90 do_test 1.$nStep.4 { 91 list [catch { rbu close } msg] $msg 92 } {0 SQLITE_DONE} 93 94 do_execsql_test 1.$nStep.5 { 95 SELECT * FROM t1; 96 } {1 t1 5 hello} 97 } 98 99 100 finish_test