xref: /sqlite-3.40.0/test/pagerfault3.test (revision 5822d6fe)
11af5e9a4Sdan# 2011 January 28
21af5e9a4Sdan#
31af5e9a4Sdan# The author disclaims copyright to this source code.  In place of
41af5e9a4Sdan# a legal notice, here is a blessing:
51af5e9a4Sdan#
61af5e9a4Sdan#    May you do good and not evil.
71af5e9a4Sdan#    May you find forgiveness for yourself and forgive others.
81af5e9a4Sdan#    May you share freely, never taking more than you give.
91af5e9a4Sdan#
101af5e9a4Sdan#***********************************************************************
111af5e9a4Sdan#
121af5e9a4Sdan
131af5e9a4Sdanset testdir [file dirname $argv0]
141af5e9a4Sdansource $testdir/tester.tcl
151af5e9a4Sdansource $testdir/lock_common.tcl
161af5e9a4Sdansource $testdir/malloc_common.tcl
171af5e9a4Sdan
181af5e9a4Sdanif {[permutation] == "inmemory_journal"} {
191af5e9a4Sdan  finish_test
201af5e9a4Sdan  return
211af5e9a4Sdan}
221af5e9a4Sdan
231af5e9a4Sdan# Create a database with page-size 2048 bytes that uses 2 pages. Populate
241af5e9a4Sdan# it so that if the page-size is changed to 1024 bytes and the db vacuumed,
251af5e9a4Sdan# the new db size is 3 pages.
261af5e9a4Sdan#
271af5e9a4Sdando_test pagerfault3-pre1 {
281af5e9a4Sdan  execsql {
29*de17f948Sdan    PRAGMA auto_vacuum = 0;
301af5e9a4Sdan    PRAGMA page_size = 2048;
311af5e9a4Sdan    CREATE TABLE t1(x);
321af5e9a4Sdan    INSERT INTO t1 VALUES(randomblob(1200));
331af5e9a4Sdan    PRAGMA page_count;
341af5e9a4Sdan  }
351af5e9a4Sdan} {2}
361af5e9a4Sdando_test pagerfault3-pre2 {
371af5e9a4Sdan  faultsim_save_and_close
381af5e9a4Sdan  faultsim_restore_and_reopen
391af5e9a4Sdan  execsql {
401af5e9a4Sdan    PRAGMA page_size = 1024;
411af5e9a4Sdan    VACUUM;
421af5e9a4Sdan    PRAGMA page_count;
431af5e9a4Sdan  }
441af5e9a4Sdan} {3}
451af5e9a4Sdan
461af5e9a4Sdan# Now do the page-size change and VACUUM with IO error injection. When
471af5e9a4Sdan# an IO error is injected into the final xSync() of the commit, the pager
481af5e9a4Sdan# will have to extend the db file from 3072 to 4096 byts when rolling
491af5e9a4Sdan# back the hot-journal file. This is a special case in pager_truncate().
501af5e9a4Sdan#
511af5e9a4Sdando_faultsim_test pagerfault3-1 -faults ioerr-transient -prep {
521af5e9a4Sdan  faultsim_restore_and_reopen
531af5e9a4Sdan} -body {
541af5e9a4Sdan  execsql {
551af5e9a4Sdan    PRAGMA page_size = 1024;
561af5e9a4Sdan    VACUUM;
571af5e9a4Sdan  }
581af5e9a4Sdan} -test {
591af5e9a4Sdan  faultsim_test_result {0 {}}
601af5e9a4Sdan  faultsim_integrity_check
611af5e9a4Sdan}
621af5e9a4Sdan
631af5e9a4Sdanfinish_test
64