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 / walrestart.test

89 lines · 2307 bytes Raw Blame History
1# 2026-03-03
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# This file implements regression tests for SQLite library. The
12# focus of this file is testing a race condition in WAL restart.
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17if {$::tcl_platform(platform) ne "unix"} {
18 # This test only works on unix
19 finish_test
20 return
21}
22set testprefix walrestart
23
24if {[permutation]=="memsubsys1"} {
25 # memsubsys1 configures a very small page-cache, which causes different
26 # numbers of frames to be written to the wal file for some transactions,
27 # which causes some of the tests in this file to fail.
28 finish_test
29 return
30}
31
32db close
33sqlite3_shutdown
34
35proc faultsim {n} { return 0 }
36sqlite3_test_control_fault_install faultsim
37
38# Populate database. Create a large wal file and checkpoint it.
39#
40reset_db
41do_execsql_test 1.0 {
42 PRAGMA auto_vacuum = 0;
43 PRAGMA journal_mode = wal;
44 CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
45 WITH s(i) AS (
46 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<20
47 )
48 INSERT INTO t1 SELECT NULL, randomblob(600) FROM s;
49 CREATE INDEX i1 ON t1(b);
50 PRAGMA wal_checkpoint;
51} {wal 0 49 49}
52do_execsql_test 1.1 {
53 UPDATE t1 SET b=randomblob(600);
54 PRAGMA wal_checkpoint;
55} {0 45 45}
56
57# We have a completely checkpointed wal file on disk. mxFrame=$large,
58# nBackfill=$large. Do another checkpoint with [db]. This time, after [db]
59# reads mxFrame but before it reads nBackfill, write to the db such
60# that 0 < mxFrame < large.
61#
62proc faultsim {n} {
63 if {$n==660} {
64 db2 eval { UPDATE t1 SET b=randomblob(600) WHERE a<5 }
65 }
66 return 0
67}
68sqlite3 db2 test.db
69do_execsql_test 1.2 {
70 PRAGMA wal_checkpoint;
71} {0 45 0}
72
73# Now write another big update to the wal file and checkpoint it.
74#
75do_execsql_test -db db2 1.3 {
76 UPDATE t1 SET b=randomblob(600);
77}
78proc faultsim {n} { return 0 }
79do_execsql_test 1.4 {
80 PRAGMA wal_checkpoint;
81} {/0 5. 5./}
82
83do_catchsql_test 1.5 {
84 PRAGMA integrity_check
85} {0 ok}
86
87sqlite3_test_control_fault_install
88
89finish_test