mirror of https://github.com/sqlite/sqlite
188 lines
4.2 KiB
Plaintext
188 lines
4.2 KiB
Plaintext
|
# 2018 December 23
|
||
|
#
|
||
|
# The author disclaims copyright to this source code. In place of
|
||
|
# a legal notice, here is a blessing:
|
||
|
#
|
||
|
# May you do good and not evil.
|
||
|
# May you find forgiveness for yourself and forgive others.
|
||
|
# May you share freely, never taking more than you give.
|
||
|
#
|
||
|
#***********************************************************************
|
||
|
# This file implements regression tests for SQLite library. The
|
||
|
# focus of this file is testing the operation of the library in
|
||
|
# "PRAGMA journal_mode=WAL" mode.
|
||
|
#
|
||
|
|
||
|
set testdir [file dirname $argv0]
|
||
|
source $testdir/tester.tcl
|
||
|
source $testdir/lock_common.tcl
|
||
|
source $testdir/malloc_common.tcl
|
||
|
source $testdir/wal_common.tcl
|
||
|
set testprefix walvfs
|
||
|
|
||
|
ifcapable !wal {finish_test ; return }
|
||
|
|
||
|
db close
|
||
|
testvfs tvfs
|
||
|
tvfs script xSync
|
||
|
tvfs filter xSync
|
||
|
set ::sync_count 0
|
||
|
proc xSync {method file args} {
|
||
|
if {[file tail $file]=="test.db-wal"} {
|
||
|
incr ::sync_count
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#-------------------------------------------------------------------------
|
||
|
# Test that if IOCAP_SEQUENTIAL is set, the wal-header is not synced to
|
||
|
# disk immediately after it is written.
|
||
|
#
|
||
|
sqlite3 db test.db -vfs tvfs
|
||
|
do_execsql_test 1.0 {
|
||
|
PRAGMA auto_vacuum = 0;
|
||
|
PRAGMA journal_mode = wal;
|
||
|
PRAGMA synchronous = normal;
|
||
|
CREATE TABLE t1(a, b, c);
|
||
|
INSERT INTO t1 VALUES(1, 2, 3);
|
||
|
INSERT INTO t1 VALUES(4, 5, 6);
|
||
|
INSERT INTO t1 VALUES(7, 8, 9);
|
||
|
PRAGMA wal_checkpoint;
|
||
|
} {wal 0 5 5}
|
||
|
|
||
|
set ::sync_count 0
|
||
|
do_test 1.1 {
|
||
|
execsql { INSERT INTO t1 VALUES(10, 11, 12) }
|
||
|
set ::sync_count
|
||
|
} 1
|
||
|
|
||
|
db close
|
||
|
tvfs devchar sequential
|
||
|
sqlite3 db test.db -vfs tvfs
|
||
|
do_execsql_test 1.2 {
|
||
|
PRAGMA synchronous = normal;
|
||
|
INSERT INTO t1 VALUES(13, 14, 15);
|
||
|
INSERT INTO t1 VALUES(16, 17, 18);
|
||
|
PRAGMA wal_checkpoint;
|
||
|
} {0 4 4}
|
||
|
|
||
|
set ::sync_count 0
|
||
|
do_test 1.3 {
|
||
|
execsql { INSERT INTO t1 VALUES(10, 11, 12) }
|
||
|
set ::sync_count
|
||
|
} 0
|
||
|
|
||
|
#-------------------------------------------------------------------------
|
||
|
# Test that "PRAGMA journal_size_limit" works in wal mode.
|
||
|
#
|
||
|
reset_db
|
||
|
do_execsql_test 2.0 {
|
||
|
PRAGMA journal_size_limit = 10000;
|
||
|
CREATE TABLE t1(x);
|
||
|
PRAGMA journal_mode = wal;
|
||
|
WITH s(i) AS (
|
||
|
SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 20
|
||
|
)
|
||
|
INSERT INTO t1 SELECT randomblob(750) FROM s;
|
||
|
} {10000 wal}
|
||
|
do_test 2.1 {
|
||
|
expr [file size test.db-wal]>12000
|
||
|
} {1}
|
||
|
do_test 2.2 {
|
||
|
execsql {
|
||
|
PRAGMA wal_checkpoint;
|
||
|
INSERT INTO t1 VALUES(randomblob(750));
|
||
|
}
|
||
|
file size test.db-wal
|
||
|
} {10000}
|
||
|
do_test 2.3 {
|
||
|
execsql {
|
||
|
PRAGMA journal_size_limit = 8000;
|
||
|
PRAGMA wal_checkpoint;
|
||
|
INSERT INTO t1 VALUES(randomblob(750));
|
||
|
}
|
||
|
file size test.db-wal
|
||
|
} {8000}
|
||
|
|
||
|
#-------------------------------------------------------------------------
|
||
|
# Test that a checkpoint may be interrupted using sqlite3_interrupt().
|
||
|
#
|
||
|
reset_db
|
||
|
db close
|
||
|
sqlite3 db test.db -vfs tvfs
|
||
|
tvfs filter {}
|
||
|
|
||
|
do_execsql_test 3.0 {
|
||
|
CREATE TABLE t1(x);
|
||
|
PRAGMA journal_mode = wal;
|
||
|
WITH s(i) AS (
|
||
|
SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 20
|
||
|
)
|
||
|
INSERT INTO t1 SELECT randomblob(750) FROM s;
|
||
|
} {wal}
|
||
|
|
||
|
tvfs filter xWrite
|
||
|
tvfs script xWrite
|
||
|
set ::cnt 2
|
||
|
proc xWrite {method file args} {
|
||
|
if {[file tail $file]=="test.db"} {
|
||
|
incr ::cnt -1
|
||
|
if {$::cnt==0} {
|
||
|
sqlite3_interrupt db
|
||
|
}
|
||
|
}
|
||
|
return SQLITE_OK
|
||
|
}
|
||
|
|
||
|
do_catchsql_test 3.1 {
|
||
|
PRAGMA wal_checkpoint
|
||
|
} {1 interrupted}
|
||
|
|
||
|
#-------------------------------------------------------------------------
|
||
|
#
|
||
|
reset_db
|
||
|
db close
|
||
|
do_test 4.0 {
|
||
|
sqlite3 db test.db -vfs tvfs
|
||
|
execsql {
|
||
|
CREATE TABLE t1(x);
|
||
|
PRAGMA journal_mode = wal;
|
||
|
WITH s(i) AS (
|
||
|
SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 20
|
||
|
)
|
||
|
INSERT INTO t1 SELECT randomblob(750) FROM s;
|
||
|
} db
|
||
|
} {wal}
|
||
|
db close
|
||
|
|
||
|
tvfs filter xShmMap
|
||
|
tvfs script xShmMap
|
||
|
proc xShmMap {method file args} {
|
||
|
return SQLITE_READONLY
|
||
|
}
|
||
|
sqlite3 db test.db -vfs tvfs
|
||
|
do_catchsql_test 4.1 {
|
||
|
SELECT count(*) FROM t1
|
||
|
} {1 {attempt to write a readonly database}}
|
||
|
|
||
|
set ::cnt 5
|
||
|
tvfs filter {xShmMap xShmLock}
|
||
|
proc xShmMap {method file name args} {
|
||
|
switch -- $method {
|
||
|
xShmMap { return SQLITE_READONLY }
|
||
|
xShmLock {
|
||
|
if {$args == "{0 1 lock shared}"} {
|
||
|
incr ::cnt -1
|
||
|
if {$::cnt>0} { return SQLITE_BUSY }
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return SQLITE_OK
|
||
|
}
|
||
|
do_catchsql_test 4.2 {
|
||
|
SELECT count(*) FROM t1
|
||
|
} {1 {attempt to write a readonly database}}
|
||
|
|
||
|
db close
|
||
|
tvfs delete
|
||
|
finish_test
|