interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / walsetlk_recover.test

104 lines · 2050 bytes Raw Blame History
1# 2025 May 30
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
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17source $testdir/lock_common.tcl
18set testprefix walsetlk_recover
19
20ifcapable !wal {finish_test ; return }
21# ifcapable !setlk_timeout {finish_test ; return }
22
23do_execsql_test 1.0 {
24 PRAGMA journal_mode = wal;
25 CREATE TABLE t1(a, b);
26 INSERT INTO t1 VALUES(1, 2);
27 INSERT INTO t1 VALUES(3, 4);
28 INSERT INTO t1 VALUES(5, 6);
29} {wal}
30
31db_save_and_close
32db_restore
33
34testfixture_nb myvar {
35
36 testvfs tvfs -fullshm 1
37 sqlite3 db test.db -vfs tvfs
38 tvfs script vfs_callback
39 tvfs filter xRead
40
41 set ::done 0
42 proc vfs_callback {method file args} {
43 if {$::done==0 && [string match *wal $file]} {
44 after 4000
45 set ::done 1
46 }
47 return "SQLITE_OK"
48 }
49
50 db eval {
51 SELECT * FROM t1
52 }
53
54 db close
55}
56
57# Give the [testfixture_nb] command time to start
58after 1000 {set xyz 1}
59vwait xyz
60
61testvfs tvfs -fullshm 1
62sqlite3 db test.db -vfs tvfs
63
64tvfs script sleep_callback
65tvfs filter xSleep
66set ::sleep_count 0
67proc sleep_callback {args} {
68 incr ::sleep_count
69}
70
71sqlite3 db test.db -vfs tvfs
72db timeout 500
73set tm [lindex [time {
74 catch {
75 db eval {SELECT * FROM t1}
76 } msg
77}] 0]
78
79do_test 1.2 { set ::msg } {database is locked}
80do_test 1.3.($::tm) { expr $::tm>400000 && $::tm<2000000 } 1
81
82vwait myvar
83
84do_execsql_test 1.4 {
85 SELECT * FROM t1
86} {1 2 3 4 5 6}
87
88db close
89tvfs delete
90
91# All SQLite builds should pass the tests above. SQLITE_ENABLE_SETLK_TIMEOUT=1
92# builds do so without calling the VFS xSleep method.
93if {$::sqlite_options(setlk_timeout)==1} {
94 do_test 1.5.1 {
95 set ::sleep_count
96 } 0
97} else {
98 do_test 1.5.2 {
99 expr $::sleep_count>0
100 } 1
101}
102
103finish_test
104