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/rbumulti.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 / rbumulti.test` 175 lines ยท 4022 bytes Raw Blame History 1 # 2018 January 11 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 # TESTRUNNER: slow 13 # 14 # This file contains tests of multiple RBU operations running 15 # concurrently within the same process. 16 # 17 18 source [file join [file dirname [info script]] rbu_common.tcl] 19 if_no_rbu_support { finish_test ; return } 20 set ::testprefix rbumulti 21 22 db close 23 24 autoinstall_test_functions 25 26 proc build_db {db} { 27 $db eval { 28 CREATE TABLE t1(a PRIMARY KEY, b, c); 29 CREATE INDEX i1 ON t1(b); 30 CREATE INDEX i2 ON t1(c); 31 32 WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<500 ) 33 INSERT INTO t1 34 SELECT randomblob(10), randomblob(100), randomblob(100) FROM s; 35 } 36 } 37 38 proc build_rbu {db} { 39 $db eval { 40 CREATE TABLE data_t1(a, b, c, rbu_control); 41 WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100 ) 42 INSERT INTO data_t1 43 SELECT randomblob(10), randomblob(100), randomblob(100), 0 FROM s; 44 } 45 } 46 47 proc step_rbu2 {bOpenClose openr1 openr2} { 48 49 forcedelete teststate.db1 50 forcedelete teststate.db2 51 52 if {$bOpenClose!=0 && $bOpenClose!=1} { error $bOpenClose } 53 if {$bOpenClose==0} { 54 eval $openr1 55 eval $openr2 56 } 57 58 set b1 0 59 set b2 0 60 61 while {$b1==0 || $b2==0} { 62 if {$bOpenClose==1} { 63 if {$b1==0} { eval $openr1 teststate.db1 } 64 if {$b2==0} { eval $openr2 teststate.db2 } 65 } 66 if {$b1==0} { 67 set rc1 [r1 step] 68 if {$rc1 != "SQLITE_OK"} { set b1 1 } 69 } 70 if {$b2==0} { 71 set rc2 [r2 step] 72 if {$rc2 != "SQLITE_OK"} { set b2 1 } 73 } 74 if {$bOpenClose==1} { 75 if {$b1==0} { r1 close } 76 if {$b2==0} { r2 close } 77 } 78 } 79 80 set rc1 [r1 close] 81 set rc2 [r2 close] 82 83 list $rc1 $rc2 84 } 85 86 87 for {set i 0} {$i<=3} {incr i} { 88 89 if {$i & 0x01} { 90 sqlite3rbu_create_vfs -default myrbu "" 91 } 92 set bOpenClose [expr $i>>1] 93 94 forcedelete test.db 95 forcedelete test.db2 96 forcedelete rbu.db 97 forcedelete rbu.db2 98 99 do_test 1.$i.0 { 100 sqlite3 db test.db 101 sqlite3 db2 test.db2 102 build_db db 103 build_db db2 104 105 sqlite3 rbu1 rbu.db 106 sqlite3 rbu2 rbu.db2 107 108 build_rbu rbu1 109 build_rbu rbu2 110 111 rbu1 close 112 rbu2 close 113 } {} 114 115 set m1 [db eval {SELECT md5sum(a, b, c) FROM t1}] 116 set m2 [db2 eval {SELECT md5sum(a, b, c) FROM t1}] 117 118 do_test 1.$i.1 { 119 step_rbu2 $bOpenClose { 120 sqlite3rbu r1 test.db rbu.db 121 } { 122 sqlite3rbu r2 test.db2 rbu.db2 123 } 124 } {SQLITE_DONE SQLITE_DONE} 125 126 do_execsql_test -db db 1.$i.2.1 { PRAGMA integrity_check } ok 127 do_execsql_test -db db2 1.$i.2.2 { PRAGMA integrity_check } ok 128 129 do_execsql_test -db db 1.$i.3.1 { SELECT md5sum(a, b, c)==$m1 FROM t1 } 0 130 do_execsql_test -db db2 1.$i.3.2 { SELECT md5sum(a, b, c)==$m2 FROM t1 } 0 131 132 catch { db close } 133 catch { db2 close } 134 #----------------------------------------------------------------------- 135 forcedelete test.db2 136 forcedelete test.db 137 forcedelete rbu.db2 138 139 do_test 1.$i.4 { 140 sqlite3 db test.db 141 sqlite3 db2 test.db2 142 build_db db 143 build_db db2 144 sqlite3 rbu2 rbu.db2 145 build_rbu rbu2 146 rbu2 close 147 } {} 148 149 set m1 [db eval {SELECT md5sum(a, b, c) FROM t1}] 150 set m2 [db2 eval {SELECT md5sum(a, b, c) FROM t1}] 151 152 do_test 1.$i.5 { 153 step_rbu2 $bOpenClose { 154 sqlite3rbu_vacuum r1 test.db 155 } { 156 sqlite3rbu r2 test.db2 rbu.db2 157 } 158 } {SQLITE_DONE SQLITE_DONE} 159 160 do_execsql_test -db db 1.$i.6.1 { SELECT md5sum(a, b, c)==$m1 FROM t1 } 1 161 do_execsql_test -db db2 1.$i.6.2 { SELECT md5sum(a, b, c)==$m2 FROM t1 } 0 162 163 do_execsql_test -db db 1.$i.7.1 { PRAGMA integrity_check } ok 164 do_execsql_test -db db2 1.$i.7.2 { PRAGMA integrity_check } ok 165 166 catch { db close } 167 catch { db2 close } 168 if {$i & 0x01} { 169 sqlite3rbu_destroy_vfs myrbu 170 } 171 172 } 173 174 175 finish_test