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_snapshot.test

109 lines · 2113 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_snapshot
19
20ifcapable !wal {finish_test ; return }
21ifcapable !snapshot {finish_test; return}
22
23db close
24testvfs tvfs -fullshm 1
25sqlite3 db test.db -vfs tvfs
26tvfs script sleep_callback
27tvfs filter xSleep
28set ::sleep_count 0
29proc sleep_callback {args} {
30 incr ::sleep_count
31}
32
33do_execsql_test 1.0 {
34 PRAGMA journal_mode = wal;
35 CREATE TABLE t1(a, b);
36 INSERT INTO t1 VALUES(1, 2);
37 INSERT INTO t1 VALUES(3, 4);
38 INSERT INTO t1 VALUES(5, 6);
39} {wal}
40
41do_test 1.1 {
42 db eval BEGIN
43 set ::snap [sqlite3_snapshot_get db main]
44 db eval {
45 INSERT INTO t1 VALUES(7, 8);
46 COMMIT;
47 }
48} {}
49
50testfixture_nb myvar {
51
52 testvfs tvfs -fullshm 1
53 sqlite3 db test.db -vfs tvfs
54 tvfs script vfs_callback
55 tvfs filter {xWrite}
56
57 set ::done 0
58 proc vfs_callback {args} {
59 if {$::done==0} {
60 after 4000
61 set ::done 1
62 }
63 return "SQLITE_OK"
64 }
65
66 db eval {
67 PRAGMA wal_checkpoint;
68 }
69
70 db close
71}
72
73# Give the [testfixture_nb] command time to start
74after 1000 {set xyz 1}
75vwait xyz
76
77db timeout 500
78set tm [lindex [time {
79 catch {
80 db eval BEGIN
81 sqlite3_snapshot_open db main $::snap
82 } msg
83}] 0]
84
85do_test 1.2 { set ::msg } {SQLITE_BUSY}
86do_test 1.3.($::tm) { expr $::tm<2000000 } 1
87
88do_execsql_test 1.4 {
89 SELECT * FROM t1
90} {1 2 3 4 5 6 7 8}
91
92sqlite3_snapshot_free $::snap
93
94vwait myvar
95
96# All SQLite builds should pass the tests above. SQLITE_ENABLE_SETLK_TIMEOUT=1
97# builds do so without calling the VFS xSleep method.
98if {$::sqlite_options(setlk_timeout)==1} {
99 do_test 1.5.1 {
100 set ::sleep_count
101 } 0
102} else {
103 do_test 1.5.2 {
104 expr $::sleep_count>0
105 } 1
106}
107
108finish_test
109