Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Enhance walro2.test to better ensure that readonly_shm clients are not using invalid *-shm files. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | readonly-wal-recovery |
Files: | files | file ages | folders |
SHA3-256: |
ff630b66714b20c09888ead0a45f344d |
User & Date: | dan 2017-11-09 20:34:35 |
Context
2017-11-09
| ||
20:37 | Add an assert() in the Win32 VFS. check-in: 22e58330 user: mistachkin tags: readonly-wal-recovery | |
20:34 | Enhance walro2.test to better ensure that readonly_shm clients are not using invalid *-shm files. check-in: ff630b66 user: dan tags: readonly-wal-recovery | |
20:02 | Get read-only SHM file tests passing on Win32. check-in: abef0535 user: mistachkin tags: readonly-wal-recovery | |
Changes
Changes to test/walro2.test.
21 21 # And only if the build is WAL-capable. 22 22 # 23 23 ifcapable !wal { 24 24 finish_test 25 25 return 26 26 } 27 27 28 +proc copy_to_test2 {bZeroShm} { 29 + forcecopy test.db test.db2 30 + forcecopy test.db-wal test.db2-wal 31 + if {$bZeroShm} { 32 + forcedelete test.db2-shm 33 + set fd [open test.db2-shm w] 34 + seek $fd [expr [file size test.db-shm]-1] 35 + puts -nonewline $fd "\0" 36 + close $fd 37 + } else { 38 + forcecopy test.db-shm test.db2-shm 39 + } 40 +} 41 + 42 +foreach bZeroShm {0 1} { 43 +set TN [expr $bZeroShm+1] 28 44 do_multiclient_test tn { 29 45 30 46 # Close all connections and delete the database. 31 47 # 32 48 code1 { db close } 33 49 code2 { db2 close } 34 50 code3 { db3 close } ................................................................................ 41 57 foreach c {code1 code2 code3} { 42 58 $c { 43 59 sqlite3_shutdown 44 60 sqlite3_config_uri 1 45 61 } 46 62 } 47 63 48 - do_test 1.1 { 64 + do_test $TN.1.1 { 49 65 code2 { sqlite3 db2 test.db } 50 66 sql2 { 51 67 CREATE TABLE t1(x, y); 52 68 PRAGMA journal_mode = WAL; 53 69 INSERT INTO t1 VALUES('a', 'b'); 54 70 INSERT INTO t1 VALUES('c', 'd'); 55 71 } 56 72 file exists test.db-shm 57 73 } {1} 58 74 59 - do_test 1.2.1 { 60 - forcecopy test.db test.db2 61 - forcecopy test.db-wal test.db2-wal 62 - forcecopy test.db-shm test.db2-shm 75 + do_test $TN.1.2.1 { 76 + copy_to_test2 $bZeroShm 63 77 code1 { 64 78 sqlite3 db file:test.db2?readonly_shm=1 65 79 } 66 80 67 81 sql1 { SELECT * FROM t1 } 68 82 } {a b c d} 69 - do_test 1.2.2 { 83 + do_test $TN.1.2.2 { 70 84 sql1 { SELECT * FROM t1 } 71 85 } {a b c d} 72 86 73 - do_test 1.3.1 { 87 + do_test $TN.1.3.1 { 74 88 code3 { sqlite3 db3 test.db2 } 75 89 sql3 { SELECT * FROM t1 } 76 90 } {a b c d} 77 91 78 - do_test 1.3.2 { 92 + do_test $TN.1.3.2 { 79 93 sql1 { SELECT * FROM t1 } 80 94 } {a b c d} 81 95 82 96 code1 { db close } 83 97 code2 { db2 close } 84 98 code3 { db3 close } 85 99 86 - do_test 2.1 { 100 + do_test $TN.2.1 { 87 101 code2 { sqlite3 db2 test.db } 88 102 sql2 { 89 103 INSERT INTO t1 VALUES('e', 'f'); 90 104 INSERT INTO t1 VALUES('g', 'h'); 91 105 } 92 106 file exists test.db-shm 93 107 } {1} 94 108 95 - do_test 2.2 { 96 - forcecopy test.db test.db2 97 - forcecopy test.db-wal test.db2-wal 98 - forcecopy test.db-shm test.db2-shm 109 + do_test $TN.2.2 { 110 + copy_to_test2 $bZeroShm 99 111 code1 { 100 112 sqlite3 db file:test.db2?readonly_shm=1 101 113 } 102 114 sql1 { 103 115 BEGIN; 104 116 SELECT * FROM t1; 105 117 } 106 118 } {a b c d e f g h} 107 119 108 - do_test 2.3.1 { 120 + do_test $TN.2.3.1 { 109 121 code3 { sqlite3 db3 test.db2 } 110 122 sql3 { SELECT * FROM t1 } 111 123 } {a b c d e f g h} 112 - do_test 2.3.2 { 124 + do_test $TN.2.3.2 { 113 125 sql3 { INSERT INTO t1 VALUES('i', 'j') } 114 126 code3 { db3 close } 115 127 sql1 { COMMIT } 116 128 } {} 117 - do_test 2.3.3 { 129 + do_test $TN.2.3.3 { 118 130 sql1 { SELECT * FROM t1 } 119 131 } {a b c d e f g h i j} 120 132 121 133 122 134 #----------------------------------------------------------------------- 123 135 # 3.1.*: That a readonly_shm connection can read a database file if both 124 136 # the *-wal and *-shm files are zero bytes in size. ................................................................................ 130 142 # 131 143 # 3.3.*: That, if between transactions some other process wraps the wal 132 144 # file, the readonly_shm client reruns recovery. 133 145 # 134 146 catch { code1 { db close } } 135 147 catch { code2 { db2 close } } 136 148 catch { code3 { db3 close } } 137 - do_test 3.1.0 { 149 + do_test $TN.3.1.0 { 138 150 list [file exists test.db-wal] [file exists test.db-shm] 139 151 } {0 0} 140 - do_test 3.1.1 { 152 + do_test $TN.3.1.1 { 141 153 close [open test.db-wal w] 142 154 close [open test.db-shm w] 143 155 code1 { 144 156 sqlite3 db file:test.db?readonly_shm=1 145 157 } 146 158 sql1 { SELECT * FROM t1 } 147 159 } {a b c d e f g h} 148 160 149 - do_test 3.2.0 { 161 + do_test $TN.3.2.0 { 150 162 list [file size test.db-wal] [file size test.db-shm] 151 163 } {0 0} 152 - do_test 3.2.1 { 164 + do_test $TN.3.2.1 { 153 165 code2 { sqlite3 db2 test.db } 154 166 sql2 { INSERT INTO t1 VALUES(1, 2) ; PRAGMA wal_checkpoint=truncate } 155 167 code2 { db2 close } 156 168 sql1 { SELECT * FROM t1 } 157 169 } {a b c d e f g h 1 2} 158 - do_test 3.2.2 { 170 + do_test $TN.3.2.2 { 159 171 list [file size test.db-wal] [file size test.db-shm] 160 172 } {0 32768} 161 173 162 - do_test 3.3.0 { 174 + do_test $TN.3.3.0 { 163 175 code2 { sqlite3 db2 test.db } 164 176 sql2 { 165 177 INSERT INTO t1 VALUES(3, 4); 166 178 INSERT INTO t1 VALUES(5, 6); 167 179 INSERT INTO t1 VALUES(7, 8); 168 180 INSERT INTO t1 VALUES(9, 10); 169 181 } 170 182 code2 { db2 close } 171 183 code1 { db close } 172 184 list [file size test.db-wal] [file size test.db-shm] 173 185 } [list [wal_file_size 4 1024] 32768] 174 - do_test 3.3.1 { 186 + do_test $TN.3.3.1 { 175 187 code1 { sqlite3 db file:test.db?readonly_shm=1 } 176 188 sql1 { SELECT * FROM t1 } 177 189 } {a b c d e f g h 1 2 3 4 5 6 7 8 9 10} 178 - do_test 3.3.2 { 190 + do_test $TN.3.3.2 { 179 191 code2 { sqlite3 db2 test.db } 180 192 sql2 { 181 193 PRAGMA wal_checkpoint; 182 194 DELETE FROM t1; 183 195 INSERT INTO t1 VALUES('i', 'ii'); 184 196 } 185 197 code2 { db2 close } 186 198 list [file size test.db-wal] [file size test.db-shm] 187 199 } [list [wal_file_size 4 1024] 32768] 188 - do_test 3.3.3 { 200 + do_test $TN.3.3.3 { 189 201 sql1 { SELECT * FROM t1 } 190 202 } {i ii} 191 203 192 204 #----------------------------------------------------------------------- 193 205 # 194 206 # 195 207 catch { code1 { db close } } 196 208 catch { code2 { db2 close } } 197 209 catch { code3 { db3 close } } 198 210 199 - do_test 4.0 { 211 + do_test $TN.4.0 { 200 212 code1 { forcedelete test.db } 201 213 code1 { sqlite3 db test.db } 202 214 sql1 { 203 215 PRAGMA journal_mode = wal; 204 216 CREATE TABLE t1(x); 205 217 INSERT INTO t1 VALUES('hello'); 206 218 INSERT INTO t1 VALUES('world'); 207 219 } 208 220 209 - forcecopy test.db test.db2 210 - forcecopy test.db-wal test.db2-wal 211 - forcecopy test.db-shm test.db2-shm 212 - 221 + copy_to_test2 $bZeroShm 222 + 213 223 code1 { db close } 214 224 } {} 215 225 216 - do_test 4.1.1 { 226 + do_test $TN.4.1.1 { 217 227 code2 { sqlite3 db2 file:test.db2?readonly_shm=1 } 218 228 sql2 { SELECT * FROM t1 } 219 229 } {hello world} 220 230 221 - do_test 4.1.2 { 231 + do_test $TN.4.1.2 { 222 232 code3 { sqlite3 db3 test.db2 } 223 233 sql3 { 224 234 INSERT INTO t1 VALUES('!'); 225 235 PRAGMA wal_checkpoint = truncate; 226 236 } 227 237 code3 { db3 close } 228 238 } {} 229 - do_test 4.1.3 { 239 + do_test $TN.4.1.3 { 230 240 sql2 { SELECT * FROM t1 } 231 241 } {hello world !} 232 242 233 243 catch { code1 { db close } } 234 244 catch { code2 { db2 close } } 235 245 catch { code3 { db3 close } } 236 246 237 - do_test 4.2.1 { 247 + do_test $TN.4.2.1 { 238 248 code1 { sqlite3 db test.db } 239 249 sql1 { 240 250 INSERT INTO t1 VALUES('!'); 241 251 INSERT INTO t1 VALUES('!'); 242 252 243 253 PRAGMA cache_size = 10; 244 254 CREATE TABLE t2(x); ................................................................................ 247 257 WITH s(i) AS ( 248 258 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<500 249 259 ) 250 260 INSERT INTO t2 SELECT randomblob(500) FROM s; 251 261 SELECT count(*) FROM t2; 252 262 } 253 263 } {500} 254 - do_test 4.2.2 { 264 + do_test $TN.4.2.2 { 255 265 file size test.db-wal 256 266 } {461152} 257 - do_test 4.2.4 { 267 + do_test $TN.4.2.4 { 258 268 file_control_persist_wal db 1; db close 259 269 260 - forcecopy test.db test.db2 261 - forcecopy test.db-wal test.db2-wal 262 - forcecopy test.db-shm test.db2-shm 263 - 270 + copy_to_test2 $bZeroShm 264 271 code2 { sqlite3 db2 file:test.db2?readonly_shm=1 } 265 272 sql2 { 266 273 SELECT * FROM t1; 267 274 SELECT count(*) FROM t2; 268 275 } 269 276 } {hello world ! ! 0} 270 277 ................................................................................ 271 278 #----------------------------------------------------------------------- 272 279 # 273 280 # 274 281 catch { code1 { db close } } 275 282 catch { code2 { db2 close } } 276 283 catch { code3 { db3 close } } 277 284 278 - do_test 5.0 { 285 + do_test $TN.5.0 { 279 286 code1 { forcedelete test.db } 280 287 code1 { sqlite3 db test.db } 281 288 sql1 { 282 289 PRAGMA journal_mode = wal; 283 290 CREATE TABLE t1(x); 284 291 INSERT INTO t1 VALUES('hello'); 285 292 INSERT INTO t1 VALUES('world'); 286 293 INSERT INTO t1 VALUES('!'); 287 294 INSERT INTO t1 VALUES('world'); 288 295 INSERT INTO t1 VALUES('hello'); 289 296 } 290 297 291 - forcecopy test.db test.db2 292 - forcecopy test.db-wal test.db2-wal 293 - forcecopy test.db-shm test.db2-shm 298 + copy_to_test2 $bZeroShm 294 299 295 300 code1 { db close } 296 301 } {} 297 302 298 - do_test 5.1 { 303 + do_test $TN.5.1 { 299 304 code2 { sqlite3 db2 file:test.db2?readonly_shm=1 } 300 305 sql2 { 301 306 SELECT * FROM t1; 302 307 } 303 308 } {hello world ! world hello} 304 309 305 - do_test 5.2 { 310 + do_test $TN.5.2 { 306 311 code1 { 307 312 proc handle_read {op args} { 308 313 if {$op=="xRead" && [file tail [lindex $args 0]]=="test.db2-wal"} { 309 314 set ::res2 [sql2 { SELECT * FROM t1 }] 310 315 } 311 316 puts "$msg xRead $args" 312 317 return "SQLITE_OK" ................................................................................ 321 326 } 322 327 sql1 { 323 328 PRAGMA wal_checkpoint = truncate; 324 329 } 325 330 code1 { set ::res2 } 326 331 } {hello world ! world hello} 327 332 328 - do_test 5.3 { 333 + do_test $TN.5.3 { 329 334 code1 { db close } 330 335 code1 { tvfs delete } 331 336 } {} 332 337 333 338 #----------------------------------------------------------------------- 334 339 # 335 340 # 336 341 catch { code1 { db close } } 337 342 catch { code2 { db2 close } } 338 343 catch { code3 { db3 close } } 339 344 340 - do_test 6.1 { 345 + do_test $TN.6.1 { 341 346 code1 { forcedelete test.db } 342 347 code1 { sqlite3 db test.db } 343 348 sql1 { 344 349 PRAGMA journal_mode = wal; 345 350 CREATE TABLE t1(x); 346 351 INSERT INTO t1 VALUES('hello'); 347 352 INSERT INTO t1 VALUES('world'); 348 353 INSERT INTO t1 VALUES('!'); 349 354 INSERT INTO t1 VALUES('world'); 350 355 INSERT INTO t1 VALUES('hello'); 351 356 } 352 357 353 - forcecopy test.db test.db2 354 - forcecopy test.db-wal test.db2-wal 355 - forcecopy test.db-shm test.db2-shm 358 + copy_to_test2 $bZeroShm 356 359 357 360 code1 { db close } 358 361 } {} 359 362 360 - do_test 6.2 { 363 + do_test $TN.6.2 { 361 364 code1 { 362 365 set ::nRem 5 363 366 proc handle_read {op args} { 364 367 if {$op=="xRead" && [file tail [lindex $args 0]]=="test.db2-wal"} { 365 368 incr ::nRem -1 366 369 if {$::nRem==0} { 367 370 code2 { sqlite3 db2 test.db2 } ................................................................................ 376 379 tvfs script handle_read 377 380 378 381 sqlite3 db file:test.db2?readonly_shm=1&vfs=tvfs 379 382 db eval { SELECT * FROM t1 } 380 383 } 381 384 } {hello world ! world hello} 382 385 383 - do_test 6.3 { 386 + do_test $TN.6.3 { 384 387 code1 { db close } 385 388 code1 { tvfs delete } 386 389 } {} 387 390 } 391 +} ;# foreach bZeroShm 388 392 389 393 finish_test