mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-16 23:02:26 +03:00
Add test cases to restore coverage of pager.c and wal.c.
FossilOrigin-Name: 6cae552927392d8b735aa118c318d7468097ebeb
This commit is contained in:
@@ -2353,5 +2353,62 @@ do_test pager1-29.2 {
|
||||
file size test.db
|
||||
} [expr 4096*3]
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test that if an empty database file (size 0 bytes) is opened in
|
||||
# exclusive-locking mode, any journal file is deleted from the file-system
|
||||
# without being rolled back. And that the RESERVED lock obtained while
|
||||
# doing this is not released.
|
||||
#
|
||||
do_test pager1-30.1 {
|
||||
db close
|
||||
file delete test.db
|
||||
file delete test.db-journal
|
||||
set fd [open test.db-journal w]
|
||||
seek $fd [expr 512+1032*2]
|
||||
puts -nonewline $fd x
|
||||
close $fd
|
||||
|
||||
sqlite3 db test.db
|
||||
execsql {
|
||||
PRAGMA locking_mode=EXCLUSIVE;
|
||||
SELECT count(*) FROM sqlite_master;
|
||||
PRAGMA lock_status;
|
||||
}
|
||||
} {exclusive 0 main reserved temp closed}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test that if the "page-size" field in a journal-header is 0, the journal
|
||||
# file can still be rolled back. This is required for backward compatibility -
|
||||
# versions of SQLite prior to 3.5.8 always set this field to zero.
|
||||
#
|
||||
do_test pager1-31.1 {
|
||||
faultsim_delete_and_reopen
|
||||
execsql {
|
||||
PRAGMA cache_size = 10;
|
||||
PRAGMA page_size = 1024;
|
||||
CREATE TABLE t1(x, y, UNIQUE(x, y));
|
||||
INSERT INTO t1 VALUES(randomblob(1500), randomblob(1500));
|
||||
INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
|
||||
BEGIN;
|
||||
UPDATE t1 SET y = randomblob(1499);
|
||||
}
|
||||
file copy test.db test.db2
|
||||
file copy test.db-journal test.db2-journal
|
||||
|
||||
hexio_write test.db2-journal 24 00000000
|
||||
sqlite3 db2 test.db2
|
||||
execsql { PRAGMA integrity_check } db2
|
||||
} {ok}
|
||||
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -515,4 +515,33 @@ do_faultsim_test walfault-13.3 -prep {
|
||||
if {!(($nRow==2 && $testrc) || $nRow==3)} { error "Bad db content" }
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test fault-handling when wrapping around to the start of a WAL file.
|
||||
#
|
||||
do_test walfault-14-pre {
|
||||
faultsim_delete_and_reopen
|
||||
execsql {
|
||||
PRAGMA journal_mode = WAL;
|
||||
BEGIN;
|
||||
CREATE TABLE abc(a PRIMARY KEY);
|
||||
INSERT INTO abc VALUES(randomblob(1500));
|
||||
INSERT INTO abc VALUES(randomblob(1500));
|
||||
COMMIT;
|
||||
}
|
||||
faultsim_save_and_close
|
||||
} {}
|
||||
do_faultsim_test walfault-14 -prep {
|
||||
faultsim_restore_and_reopen
|
||||
} -body {
|
||||
db eval {
|
||||
PRAGMA wal_checkpoint;
|
||||
INSERT INTO abc VALUES(randomblob(1500));
|
||||
}
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
faultsim_integrity_check
|
||||
set nRow [db eval {SELECT count(*) FROM abc}]
|
||||
if {!(($nRow==2 && $testrc) || $nRow==3)} { error "Bad db content" }
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -140,7 +140,45 @@ do_test 2.2.6 {
|
||||
} {a b c d e f g h}
|
||||
|
||||
db2 close
|
||||
db close
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# 3.1: Test that if locking_mode=EXCLUSIVE is set after the wal file is
|
||||
# opened, it is possible to drop back to locking_mode=NORMAL.
|
||||
#
|
||||
# 3.2: Test that if locking_mode=EXCLUSIVE is set before the wal file is
|
||||
# opened, it is not.
|
||||
#
|
||||
do_test 3.1 {
|
||||
sqlite3 db test.db -vfs tvfsshm
|
||||
execsql {
|
||||
SELECT * FROM t1;
|
||||
PRAGMA locking_mode = EXCLUSIVE;
|
||||
INSERT INTO t1 VALUES(5, 6);
|
||||
PRAGMA locking_mode = NORMAL;
|
||||
INSERT INTO t1 VALUES(7, 8);
|
||||
}
|
||||
sqlite3 db2 test.db -vfs tvfsshm
|
||||
execsql { SELECT * FROM t1 } db2
|
||||
} {1 2 3 4 5 6 7 8}
|
||||
db close
|
||||
db2 close
|
||||
do_test 3.2 {
|
||||
sqlite3 db test.db -vfs tvfsshm
|
||||
execsql {
|
||||
PRAGMA locking_mode = EXCLUSIVE;
|
||||
INSERT INTO t1 VALUES(9, 10);
|
||||
PRAGMA locking_mode = NORMAL;
|
||||
INSERT INTO t1 VALUES(11, 12);
|
||||
}
|
||||
sqlite3 db2 test.db -vfs tvfsshm
|
||||
catchsql { SELECT * FROM t1 } db2
|
||||
} {1 {database is locked}}
|
||||
db close
|
||||
db2 close
|
||||
|
||||
tvfs delete
|
||||
tvfsshm delete
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
Reference in New Issue
Block a user