Add pager test cases. Change a condition in pager.c to NEVER().

FossilOrigin-Name: a8f6341d3b12d64ef56ed05226e3b4f183b8957d
This commit is contained in:
dan
2010-07-01 15:09:47 +00:00
parent 6b63ab47d7
commit 89ccf4481b
7 changed files with 424 additions and 20 deletions
+194 -1
View File
@@ -1093,6 +1093,28 @@ ifcapable wal {
}
}
do_test pager1-7.2.1 {
faultsim_delete_and_reopen
execsql {
PRAGMA locking_mode = EXCLUSIVE;
CREATE TABLE t1(a, b);
BEGIN;
PRAGMA journal_mode = delete;
PRAGMA journal_mode = truncate;
}
} {exclusive delete truncate}
do_test pager1-7.2.2 {
execsql { INSERT INTO t1 VALUES(1, 2) }
execsql { PRAGMA journal_mode = persist }
} {truncate}
do_test pager1-7.2.3 {
execsql { COMMIT }
execsql {
PRAGMA journal_mode = persist;
PRAGMA journal_size_limit;
}
} {persist -1}
#-------------------------------------------------------------------------
# The following tests, pager1-8.*, test that the special filenames
# ":memory:" and "" open temporary databases.
@@ -1756,7 +1778,178 @@ do_test pager1-20.3.2 {
execsql COMMIT
} {}
#-------------------------------------------------------------------------
# Test that a WAL database may not be opened if:
#
# pager1-21.1.*: The VFS has an iVersion less than 2, or
# pager1-21.2.*: The VFS does not provide xShmXXX() methods.
#
do_test pager1-21.0 {
faultsim_delete_and_reopen
execsql {
PRAGMA journal_mode = WAL;
CREATE TABLE ko(c DEFAULT 'abc', b DEFAULT 'def');
INSERT INTO ko DEFAULT VALUES;
}
} {wal}
do_test pager1-21.1 {
testvfs tv -noshm 1
sqlite3 db2 test.db -vfs tv
catchsql { SELECT * FROM ko } db2
} {1 {unable to open database file}}
db2 close
tv delete
do_test pager1-21.2 {
breakpoint
testvfs tv -iversion 1
sqlite3 db2 test.db -vfs tv
catchsql { SELECT * FROM ko } db2
} {1 {unable to open database file}}
db2 close
tv delete
#-------------------------------------------------------------------------
# Test that a "PRAGMA wal_checkpoint":
#
# pager1-22.1.*: is a no-op on a non-WAL db, and
# pager1-22.2.*: does not cause xSync calls with a synchronous=off db.
#
do_test pager1-22.1.1 {
faultsim_delete_and_reopen
execsql {
CREATE TABLE ko(c DEFAULT 'abc', b DEFAULT 'def');
INSERT INTO ko DEFAULT VALUES;
}
execsql { PRAGMA wal_checkpoint }
} {}
do_test pager1-22.2.1 {
testvfs tv -default 1
tv filter xSync
tv script xSyncCb
proc xSyncCb {args} {incr ::synccount}
set ::synccount 0
sqlite3 db test.db
execsql {
PRAGMA synchronous = off;
PRAGMA journal_mode = WAL;
INSERT INTO ko DEFAULT VALUES;
}
execsql { PRAGMA wal_checkpoint }
set synccount
} {0}
db close
tv delete
#-------------------------------------------------------------------------
# Tests for changing journal mode.
#
# pager1-23.1.*: Test that when changing from PERSIST to DELETE mode,
# the journal file is deleted.
#
# pager1-23.2.*: Same test as above, but while a shared lock is held
# on the database file.
#
# pager1-23.3.*: Same test as above, but while a reserved lock is held
# on the database file.
#
# pager1-23.4.*: And, for fun, while holding an exclusive lock.
#
# pager1-23.5.*: Try to set various different journal modes with an
# in-memory database (only MEMORY and OFF should work).
#
do_test pager1-23.1.1 {
faultsim_delete_and_reopen
execsql {
PRAGMA journal_mode = PERSIST;
CREATE TABLE t1(a, b);
}
file exists test.db-journal
} {1}
do_test pager1-23.1.2 {
execsql { PRAGMA journal_mode = DELETE }
file exists test.db-journal
} {0}
do_test pager1-23.2.1 {
execsql {
PRAGMA journal_mode = PERSIST;
INSERT INTO t1 VALUES('Canberra', 'ACT');
}
db eval { SELECT * FROM t1 } {
db eval { PRAGMA journal_mode = DELETE }
}
execsql { PRAGMA journal_mode }
} {delete}
do_test pager1-23.2.2 {
file exists test.db-journal
} {0}
do_test pager1-23.3.1 {
execsql {
PRAGMA journal_mode = PERSIST;
INSERT INTO t1 VALUES('Darwin', 'NT');
BEGIN IMMEDIATE;
}
db eval { PRAGMA journal_mode = DELETE }
execsql { PRAGMA journal_mode }
} {delete}
do_test pager1-23.3.2 {
file exists test.db-journal
} {0}
do_test pager1-23.3.3 {
execsql COMMIT
} {}
do_test pager1-23.4.1 {
execsql {
PRAGMA journal_mode = PERSIST;
INSERT INTO t1 VALUES('Adelaide', 'SA');
BEGIN EXCLUSIVE;
}
db eval { PRAGMA journal_mode = DELETE }
execsql { PRAGMA journal_mode }
} {delete}
do_test pager1-23.4.2 {
file exists test.db-journal
} {0}
do_test pager1-23.4.3 {
execsql COMMIT
} {}
do_test pager1-23.5.1 {
faultsim_delete_and_reopen
sqlite3 db :memory:
} {}
foreach {tn mode possible} {
2 off 1
3 memory 1
4 persist 0
5 delete 0
6 wal 0
7 truncate 0
} {
do_test pager1-23.5.$tn.1 {
execsql "PRAGMA journal_mode = off"
execsql "PRAGMA journal_mode = $mode"
} [if $possible {list $mode} {list off}]
do_test pager1-23.5.$tn.2 {
execsql "PRAGMA journal_mode = memory"
execsql "PRAGMA journal_mode = $mode"
} [if $possible {list $mode} {list memory}]
}
do_test pager1-23.8.1 {
execsql {PRAGMA locking_mode = normal}
} {exclusive}
do_test pager1-23.8.2 {
execsql {PRAGMA locking_mode = exclusive}
} {exclusive}
do_test pager1-23.8.3 {
execsql {PRAGMA locking_mode}
} {exclusive}
do_test pager1-23.8.4 {
execsql {PRAGMA main.locking_mode}
} {exclusive}
finish_test