/ Check-in [7e040406]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add another fault-injection test for sqlite3_snapshot_recover().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | serializable-snapshot
Files: files | file ages | folders
SHA1: 7e040406138669bd67dd6ecae016b3e50dbfaaf8
User & Date: dan 2016-11-19 17:20:28
Context
2016-11-19
17:30
Test some extra error conditions in sqlite3_recover_snapshot(). check-in: db314213 user: dan tags: serializable-snapshot
17:20
Add another fault-injection test for sqlite3_snapshot_recover(). check-in: 7e040406 user: dan tags: serializable-snapshot
16:35
Fix a problem causing sqlite3_snapshot_recover() to return SQLITE_IOERR_SHORT_READ. check-in: 525f75fa user: dan tags: serializable-snapshot
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/snapshot_fault.test.

    13     13   #
    14     14   
    15     15   set testdir [file dirname $argv0]
    16     16   source $testdir/tester.tcl
    17     17   ifcapable !snapshot {finish_test; return}
    18     18   set testprefix snapshot_fault
    19     19   
    20         -if 1 {
    21         -
    22     20   #-------------------------------------------------------------------------
    23     21   # Check that an sqlite3_snapshot_open() client cannot be tricked into
    24     22   # reading a corrupt snapshot even if a second client fails while 
    25     23   # checkpointing the db.
    26     24   #
    27     25   do_faultsim_test 1.0 -prep {
    28     26     faultsim_delete_and_reopen
................................................................................
   157    155       }]
   158    156       if {$res != "1 2 3 ok"} { error "res is $res" }
   159    157     }
   160    158   
   161    159     sqlite3_snapshot_free $::snapshot
   162    160   }
   163    161   
   164         -}
   165         -
   166    162   #-------------------------------------------------------------------------
   167    163   # Test the handling of faults that occur within sqlite3_snapshot_recover().
   168    164   #
   169    165   reset_db
   170    166   do_execsql_test 4.0 {
   171    167     PRAGMA journal_mode = wal;
   172    168     CREATE TABLE t1(zzz);
   173    169     INSERT INTO t1 VALUES('abc');
   174    170     INSERT INTO t1 VALUES('def');
   175    171   } {wal}
   176    172   faultsim_save_and_close
   177    173   
   178         -do_test 4.1 {
          174  +do_test 4.0.1 {
   179    175     faultsim_restore_and_reopen
   180    176     db eval { SELECT * FROM sqlite_master } 
   181    177     sqlite3_snapshot_recover db main
   182    178   } {}
   183    179   db close
   184    180   
   185         -do_faultsim_test 4 -faults oom* -prep {
          181  +do_faultsim_test 4.0 -faults oom* -prep {
   186    182     faultsim_restore_and_reopen
   187    183     db eval { SELECT * FROM sqlite_master } 
   188    184   } -body {
   189    185     sqlite3_snapshot_recover db main
   190    186   } -test {
   191    187     faultsim_test_result {0 {}} {1 SQLITE_NOMEM} {1 SQLITE_IOERR_NOMEM}
   192    188   }
          189  +
          190  +# The following test cases contrive to call sqlite3_snapshot_recover()
          191  +# before all pages of the *-shm file have been mapped. This tests an
          192  +# extra branch of error handling logic in snapshot_recover().
          193  +#
          194  +reset_db
          195  +do_execsql_test 4.1.0 {
          196  +  PRAGMA page_size = 512;
          197  +  PRAGMA journal_mode = wal;
          198  +  PRAGMA wal_autocheckpoint = 0;
          199  +  CREATE TABLE t1(zzz);
          200  +  INSERT INTO t1 VALUES(randomblob( 500 * 9500 ));
          201  +  PRAGMA user_version = 211;
          202  +} {wal 0}
          203  +
          204  +do_test 4.1.1 {
          205  +  list [file size test.db-shm] [file size test.db]
          206  +} {98304 512}
          207  +
          208  +faultsim_save_and_close
          209  +do_faultsim_test 4.1 -faults shm* -prep {
          210  +  catch { db2 close } 
          211  +  catch { db close } 
          212  +  faultsim_restore_and_reopen
          213  +  sqlite3 db2 test.db
          214  +  db2 eval { SELECT * FROM sqlite_master } 
          215  +  db eval BEGIN
          216  +  sqlite3_snapshot_get_blob db main
          217  +  db eval COMMIT
          218  +} -body {
          219  +  sqlite3_snapshot_recover db main
          220  +} -test {
          221  +  faultsim_test_result {0 {}} {1 SQLITE_IOERR}
          222  +}
          223  +
   193    224   
   194    225   
   195    226   finish_test