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/test/walsetlk3.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 / test / walsetlk3.test` 135 lines ยท 2898 bytes Raw Blame History 1 # 2020 May 06 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 15 set testdir [file dirname $argv0] 16 source $testdir/tester.tcl 17 source $testdir/lock_common.tcl 18 set testprefix walsetlk3 19 20 ifcapable !wal {finish_test ; return } 21 ifcapable !setlk_timeout {finish_test ; return } 22 23 do_execsql_test 1.0 { 24 CREATE TABLE t1(x, y); 25 PRAGMA journal_mode = wal; 26 INSERT INTO t1 VALUES(1, 2); 27 INSERT INTO t1 VALUES(3, 4); 28 } {wal} 29 30 db close 31 32 proc sql_block_on_close {sql} { 33 testfixture_nb done [string map [list %SQL% $sql] { 34 testvfs tvfs 35 tvfs script xWrite 36 tvfs filter xWrite 37 38 set ::delay_done 0 39 proc xWrite {method fname args} { 40 if {[file tail $fname]=="test.db" && $::delay_done==0} { 41 after 3000 42 set ::delay_done 1 43 } 44 return 0 45 } 46 47 sqlite3 db test.db -vfs tvfs 48 db eval {%SQL%} 49 db close 50 }] 51 } 52 53 # Start a second process that writes to the db, then blocks within the 54 # [db close] holding an EXCLUSIVE on the db in order to checkpoint and 55 # delete the wal file. Then try to read the db. 56 # 57 # Without the SQLITE_SETLK_BLOCK_ON_CONNECT flag, this should fail with 58 # SQLITE_BUSY. 59 # 60 sql_block_on_close { 61 INSERT INTO t1 VALUES(5, 6); 62 INSERT INTO t1 VALUES(7, 8); 63 } 64 after 500 {set ok 1} 65 vwait ok 66 sqlite3 db test.db 67 sqlite3_setlk_timeout db 2000 68 do_catchsql_test 1.1 { 69 SELECT * FROM t1 70 } {1 {database is locked}} 71 72 vwait ::done 73 74 # But with SQLITE_SETLK_BLOCK_ON_CONNECT flag, it should succeed. 75 # 76 sql_block_on_close { 77 INSERT INTO t1 VALUES(9, 10); 78 INSERT INTO t1 VALUES(11, 12); 79 } 80 after 500 {set ok 1} 81 vwait ok 82 sqlite3 db test.db 83 sqlite3_setlk_timeout -block db 2000 84 do_catchsql_test 1.2 { 85 SELECT * FROM t1 86 } {0 {1 2 3 4 5 6 7 8 9 10 11 12}} 87 88 vwait ::done 89 90 #------------------------------------------------------------------------- 91 # Check that the SQLITE_SETLK_BLOCK_ON_CONNECT does not cause connections 92 # to block when taking a SHARED lock on a rollback mode database. 93 # 94 reset_db 95 do_execsql_test 2.1 { 96 CREATE TABLE x1(a); 97 INSERT INTO x1 VALUES(1), (2), (3); 98 } 99 100 proc sql_block_on_write {sql} { 101 testfixture_nb done [string map [list %SQL% $sql] { 102 sqlite3 db test.db 103 db eval "BEGIN EXCLUSIVE" 104 db eval {%SQL%} 105 after 3000 106 db eval COMMIT 107 db close 108 }] 109 } 110 111 db close 112 sql_block_on_write { 113 INSERT INTO x1 VALUES(4); 114 } 115 116 after 500 {set ok 1} 117 vwait ok 118 119 sqlite3 db test.db 120 sqlite3_setlk_timeout -block db 2000 121 122 do_catchsql_test 2.2 { 123 SELECT * FROM x1 124 } {1 {database is locked}} 125 126 vwait ::done 127 after 500 {set ok 1} 128 vwait ok 129 130 do_catchsql_test 2.3 { 131 SELECT * FROM x1 132 } {0 {1 2 3 4}} 133 134 finish_test 135