1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Add a test to ensure that "PRAGMA wal_checkpoint = FULL" invokes the busy-handler to wait on read-locks.

FossilOrigin-Name: f068fb116286b1dbdee9c168900348cfcab84e6d8413f3456e4e492f650d11b0
This commit is contained in:
dan
2020-06-30 18:21:45 +00:00
parent f488bc1147
commit 3f1d0f56e4
3 changed files with 85 additions and 7 deletions

View File

@ -50,5 +50,83 @@ do_multiclient_test tn {
} {}
}
#-------------------------------------------------------------------------
do_multiclient_test tn {
# Make the db a WAL mode db. And add a table and a row to it. Then open
# a second connection within process 1. Process 1 now has connections
# [db] and [db1.2], process 2 has connection [db2] only.
#
# Configure all connections to use a 1000 ms timeout.
#
do_test 2.$tn.0 {
sql1 {
PRAGMA journal_mode = wal;
CREATE TABLE t1(a, b);
INSERT INTO t1 VALUES(1, 2);
}
code2 {
db2 timeout 1000
}
code1 {
sqlite3 db1.2 test.db
db1.2 timeout 1000
db timeout 1000
db1.2 eval {SELECT * FROM t1}
}
} {1 2}
# Take a read lock with [db] in process 1.
#
do_test 2.$tn.1 {
sql1 {
BEGIN;
SELECT * FROM t1;
}
} {1 2}
# Insert a row using [db2] in process 2. Then try a passive checkpoint.
# It fails to checkpoint the final frame (due to the readlock taken by
# [db]), and returns in less than 250ms.
do_test 2.$tn.2 {
sql2 { INSERT INTO t1 VALUES(3, 4) }
set us [lindex [time {
set res [code2 { db2 eval { PRAGMA wal_checkpoint } }]
}] 0]
list [expr $us < 250000] $res
} {1 {0 4 3}}
# Now try a FULL checkpoint with [db2]. It returns SQLITE_BUSY. And takes
# over 950ms to do so.
do_test 2.$tn.3 {
set us [lindex [time {
set res [code2 { db2 eval { PRAGMA wal_checkpoint = FULL } }]
}] 0]
list [expr $us > 950000] $res
} {1 {1 4 3}}
# Passive checkpoint with [db1.2] (process 1). No SQLITE_BUSY, returns
# in under 250ms.
do_test 2.$tn.4 {
set us [lindex [time {
set res [code1 { db1.2 eval { PRAGMA wal_checkpoint } }]
}] 0]
list [expr $us < 250000] $res
} {1 {0 4 3}}
# Full checkpoint with [db1.2] (process 1). SQLITE_BUSY returned in
# a bit over 950ms.
do_test 2.$tn.5 {
set us [lindex [time {
set res [code1 { db1.2 eval { PRAGMA wal_checkpoint = FULL } }]
}] 0]
list [expr $us > 950000] $res
} {1 {1 4 3}}
code1 {
db1.2 close
}
}
finish_test