modernc.org/cc@v1.0.1/v2/testdata/_sqlite/ext/rbu/rbucrash2.test (about)

     1  # 2017 March 02
     2  #
     3  # The author disclaims copyright to this source code.  In place of
     4  # a legal notice, here is a blessing:
     5  #
     6  #    May you do good and not evil.
     7  #    May you find forgiveness for yourself and forgive others.
     8  #    May you share freely, never taking more than you give.
     9  #
    10  #***********************************************************************
    11  #
    12  
    13  if {![info exists testdir]} {
    14    set testdir [file join [file dirname [info script]] .. .. test]
    15  }
    16  source $testdir/tester.tcl
    17  set ::testprefix rbucrash2
    18  
    19  db close
    20  forcedelete test.db-oal rbu.db
    21  sqlite3_shutdown
    22  sqlite3_config_uri 1
    23  reset_db
    24  
    25  # Set up a target database and an rbu update database. The target
    26  # db is the usual "test.db", the rbu db is "test.db2".
    27  #
    28  forcedelete test.db2
    29  do_execsql_test 1.0 {
    30    CREATE TABLE t1(a, b, c, PRIMARY KEY(a), UNIQUE(b));
    31    INSERT INTO t1 VALUES(1, 2, 3);
    32    INSERT INTO t1 VALUES(4, 5, 6);
    33    INSERT INTO t1 VALUES(7, 8, 9);
    34  
    35    ATTACH 'test.db2' AS rbu;
    36    CREATE TABLE rbu.data_t1(a, b, c, rbu_control);
    37    INSERT INTO data_t1 VALUES('one', randomblob(3500), NULL, 0);
    38    INSERT INTO data_t1 VALUES('two', randomblob(3500), NULL, 0);
    39    INSERT INTO data_t1 VALUES('three', randomblob(3500), NULL, 0);
    40    INSERT INTO data_t1 VALUES('four', randomblob(3500), NULL, 0);
    41    INSERT INTO data_t1 VALUES('five', randomblob(3500), NULL, 0);
    42    INSERT INTO data_t1 VALUES('six', randomblob(3500), NULL, 0);
    43  }
    44  db_save_and_close
    45  
    46  proc do_rbu_crash_test2 {tn script} {
    47  
    48    foreach {f blksz} {
    49      test.db   512
    50      test.db2  512
    51      test.db   4096
    52      test.db2  4096
    53    } {
    54      set bDone 0
    55      for {set iDelay 1} {$bDone==0} {incr iDelay} {
    56        forcedelete test.db2 test.db2-journal test.db test.db-oal test.db-wal
    57        db_restore
    58    
    59        set res [
    60          crashsql -file $f -delay $iDelay -tclbody $script -dflt 1 -opendb {} \
    61              -blocksize $blksz {}
    62        ]
    63    
    64        set bDone 1
    65        if {$res == "1 {child process exited abnormally}"} {
    66          set bDone 0
    67        } elseif {$res != "0 {}"} {
    68          error "unexected catchsql result: $res"
    69        }
    70    
    71        sqlite3rbu rbu test.db test.db2
    72        while {[rbu step]=="SQLITE_OK"} {}
    73        rbu close
    74    
    75        sqlite3 db test.db
    76        do_execsql_test $tn.delay=$iDelay.f=$f.blksz=$blksz {
    77          PRAGMA integrity_check;
    78        } {ok}
    79        db close
    80      }
    81    }
    82  }
    83  
    84  for {set x 1} {$x < 10} {incr x} {
    85    do_rbu_crash_test2 1.$x {
    86      sqlite3rbu rbu test.db test.db2
    87      while {[rbu step]=="SQLITE_OK"} {
    88        rbu savestate
    89      }
    90      rbu close
    91    }
    92  }
    93  
    94  for {set x 1} {$x < 2} {incr x} {
    95    do_rbu_crash_test2 2.$x {
    96      sqlite3rbu rbu test.db test.db2
    97      while {[rbu step]=="SQLITE_OK"} {
    98        rbu close
    99        sqlite3rbu rbu test.db test.db2
   100      }
   101      rbu close
   102    }
   103  }
   104  
   105  finish_test
   106