/ Check-in [58c0b5bf]
Login

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

Overview
Comment:Add tests to pager1.test and pagerfault.test.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | experimental
Files: files | file ages | folders
SHA1: 58c0b5bfed8c67cc3f2f4a6784d08c14e652c265
User & Date: dan 2010-06-19 11:30:41
Context
2010-06-19
17:26
Add tests to pager1.test and pagerfault.test. check-in: f5df83fd user: dan tags: experimental
11:30
Add tests to pager1.test and pagerfault.test. check-in: 58c0b5bf user: dan tags: experimental
2010-06-18
18:59
Add tests to pager1.test. check-in: 582fca89 user: dan tags: experimental
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/pager1.test.

    20     20   #
    21     21   # pager1-2.*: Test intra-process locking (multiple clients in this process).
    22     22   #
    23     23   # pager1-3.*: Savepoint related tests.
    24     24   #
    25     25   # pager1-4.*: Hot-journal related tests.
    26     26   #
           27  +# pager1-5.*: Cases related to multi-file commits.
           28  +#
    27     29   
    28     30   proc do_execsql_test {testname sql result} {
    29     31     uplevel do_test $testname [list "execsql {$sql}"] [list $result]
    30     32   }
    31     33   proc do_catchsql_test {testname sql result} {
    32     34     uplevel do_test $testname [list "catchsql {$sql}"] [list $result]
    33     35   }
................................................................................
   208    210   do_catchsql_test pager1-3.3 {
   209    211       INSERT INTO t1 SELECT a+3, randomblob(1500) FROM t1
   210    212   } {1 {constraint failed}}
   211    213   do_execsql_test pager1-3.4 { SELECT * FROM counter } {3 0}
   212    214   do_execsql_test pager1-3.5 { SELECT a FROM t1 } {1 2 3}
   213    215   do_execsql_test pager1-3.6 { COMMIT } {}
   214    216   
          217  +set otn 0
   215    218   testvfs tv -default 1
   216    219   foreach code [list {
   217    220     set s 512
   218         -  set sql { PRAGMA synchronous = off }
   219    221   } {
   220    222     set s 1024
   221    223     set sql { PRAGMA journal_mode = memory }
   222    224   } {
   223    225     set s 2048
   224    226     tv devchar safe_append
   225    227   } {
          228  +  set s 4096
          229  +} {
   226    230     set s 4096
   227    231     set sql { PRAGMA journal_mode = WAL }
          232  +} {
          233  +  set s 8192
          234  +  set sql { PRAGMA synchronous = off }
   228    235   }] {
          236  +
          237  +  incr otn
          238  +  set sql ""
          239  +  tv devchar {}
   229    240     eval $code
   230    241     tv sectorsize $s
   231    242     
   232         -  do_test pager1-3.7.$s.1 {
          243  +  do_test pager1-3.7.$otn.0 {
   233    244       faultsim_delete_and_reopen
   234    245       execsql $sql
   235    246       execsql {
   236    247         PRAGMA cache_size = 10;
   237    248         CREATE TABLE t1(i INTEGER PRIMARY KEY, j blob);
   238    249       }
   239    250     } {}
   240    251   
   241    252     set tn 0
   242    253     set lowpoint 0
   243    254     foreach x {
          255  +    100 x 0 100
          256  +  x
   244    257       70 22 96 59 96 50 22 56 21 16 37 64 43 40  0 38 22 38 55  0  6   
   245    258       43 62 32 93 54 18 13 29 45 66 29 25 61 31 53 82 75 25 96 86 10 69   
   246    259        2 29  6 60 80 95 42 82 85 50 68 96 90 39 78 69 87 97 48 74 65 43   
   247    260     x
   248    261       86 34 26 50 41 85 58 44 89 22  6 51 45 46 58 32 97  6  1 12 32  2   
   249    262       69 39 48 71 33 31  5 58 90 43 24 54 12  9 18 57  4 38 91 42 27 45   
   250    263       50 38 56 29 10  0 26 37 83  1 78 15 47 30 75 62 46 29 68  5 30  4   
................................................................................
   251    264       27 96 33 95 79 75 56 10 29 70 32 75 52 88  5 36 50 57 46 63 88 65   
   252    265     x
   253    266       44 95 64 20 24 35 69 61 61  2 35 92 42 46 23 98 78  1 38 72 79 35   
   254    267       94 37 13 59  5 93 27 58 80 75 58  7 67 13 10 76 84  4  8 70 81 45   
   255    268        8 41 98  5 60 26 92 29 91 90  2 62 40  4  5 22 80 15 83 76 52 88   
   256    269       29  5 68 73 72  7 54 17 89 32 81 94 51 28 53 71  8 42 54 59 70 79   
   257    270     x
   258         -    35 59 37 22  8 72 10 48 79  6 87 96 59 95 45 56  6  4 86 68 25 28   
   259         -    43 75 47  9 53 18 69 51 11 94 86 65 23 87 49 19 20 20 33 14 11 86   
   260         -    42 23  8 40 94 55  4 38 52 30  6 25 44 79 57 82 30 87 86 75 40 92   
   261         -    29 26 82 91 67 64 15 51 17 11 15 27 32  7 38  1 52 82 26 99 17 18   
   262         -    38 13 20 65 91 98 50 81 49 15 94 45 84 35 31 67 13 43 78  3 94 77   
   263         -    47 18 96 66 99 77 11 11 70 18  1 29 79 57 59 86 94 34 91 15 24 53   
   264         -    61 73 58 46 36 79 90 89 12  0 91  0 86 44 71 83 75 76 97 65 13 80   
   265         -    42 39 15 44 90 18 67 69  1 72 17 99 12 72 77 17  3 34 75 59 92 76   
   266         -    18 86 60 12 20 98 48 14 12 67 45 44 10  2  5 88  7 45  5 47 45 75   
   267         -    19 25 42 62 66 17 94 63  0 53 38 81 26 11 97 33 13 36 81 82 73 26   
   268         -    78 90 28 78 26 61  9 74 70 53 17 86 51 90  3 30 99  5 25 44  6 72   
   269         -    84 32 74 46 16 44 74 82 84  9 58 90 85 82 53 40 37 
   270    271     } {
   271    272       incr tn
   272    273       set now [db one {SELECT count(i) FROM t1}]
   273    274       if {$x == "x"} {
   274    275         execsql { COMMIT ; BEGIN }
   275    276         set lowpoint $now
   276         -      do_test pager1.3.7.$s.2.$tn { 
          277  +      do_test pager1.3.7.$otn.$tn { 
   277    278           sqlite3 db2 test.db
   278    279           execsql {
   279    280             SELECT COALESCE(max(i), 0) FROM t1;
   280    281             PRAGMA integrity_check;
   281    282           } 
   282    283         } [list $lowpoint ok]
   283    284         db2 close
................................................................................
   291    292           }
   292    293         } elseif {$now < $x} {
   293    294           for {set k $now} {$k < $x} {incr k} {
   294    295             execsql "SAVEPOINT sp_$k"
   295    296             execsql { INSERT INTO t1(j) VALUES(randomblob(1500)) }
   296    297           }
   297    298         }
   298         -      do_execsql_test pager1.3.7.$s.2.$tn { 
          299  +      do_execsql_test pager1.3.7.$otn.$tn { 
   299    300           SELECT COALESCE(max(i), 0) FROM t1;
   300    301           PRAGMA integrity_check;
   301    302         } [list $x ok]
   302    303       }
   303    304     }
   304    305   }
   305    306   db close
................................................................................
   312    313   #               journal files.
   313    314   #
   314    315   # pager1.4.2.*: Test that if the master journal pointer at the end of a
   315    316   #               hot-journal file appears to be corrupt (checksum does not
   316    317   #               compute) the associated journal is rolled back (and no
   317    318   #               xAccess() call to check for the presence of any master 
   318    319   #               journal file is made).
          320  +#
          321  +# pager1.4.3.*: Test that the contents of a hot-journal are ignored if the
          322  +#               page-size or sector-size in the journal header appear to
          323  +#               be invalid (too large, too small or not a power of 2).
   319    324   # 
   320    325   do_test pager1.4.1.1 {
   321    326     faultsim_delete_and_reopen
   322    327     execsql { 
   323    328       CREATE TABLE x(y, z);
   324    329       INSERT INTO x VALUES(1, 2);
   325    330     }
................................................................................
   398    403     hexio_write test.db-journal [expr [file size test.db-journal]-20] 123456
   399    404     foreach f [glob test.db-mj*] { file delete -force $f }
   400    405     execsql {
   401    406       SELECT count(*) FROM t1;
   402    407       PRAGMA integrity_check;
   403    408     }
   404    409   } {4 ok}
          410  +
          411  +do_test pager1.4.3.1 {
          412  +  testvfs tstvfs -default 1
          413  +  tstvfs filter xSync
          414  +  tstvfs script xSyncCallback
          415  +  proc xSyncCallback {method file args} {
          416  +    set file [file tail $file]
          417  +    if { 0==[string match *journal $file] } { faultsim_save }
          418  +  }
          419  +  faultsim_delete_and_reopen
          420  +  execsql {
          421  +    PRAGMA journal_mode = DELETE;
          422  +    CREATE TABLE t1(a, b);
          423  +    INSERT INTO t1 VALUES(1, 2);
          424  +    INSERT INTO t1 VALUES(3, 4);
          425  +  }
          426  +  db close
          427  +  tstvfs delete
          428  +} {}
          429  +
          430  +foreach {tn ofst value result} {
          431  +          2   20    31       {1 2 3 4}
          432  +          3   20    32       {1 2 3 4}
          433  +          4   20    33       {1 2 3 4}
          434  +          5   20    65536    {1 2 3 4}
          435  +          6   20    131072   {1 2 3 4}
          436  +
          437  +          7   24    511      {1 2 3 4}
          438  +          8   24    513      {1 2 3 4}
          439  +          9   24    65536    {1 2 3 4}
          440  +
          441  +         10   32    65536    {1 2}
          442  +} {
          443  +  do_test pager1.4.3.$tn {
          444  +    faultsim_restore_and_reopen
          445  +    hexio_write test.db-journal $ofst [format %.8x $value]
          446  +    execsql { SELECT * FROM t1 }
          447  +  } $result
          448  +}
          449  +db close
          450  +
          451  +#-------------------------------------------------------------------------
          452  +#
   405    453   
   406    454   finish_test
   407    455   

Changes to test/pagerfault.test.

    49     49   } -test {
    50     50     faultsim_test_result {0 4}
    51     51     faultsim_integrity_check
    52     52     if {[db one { SELECT count(*) FROM t1 }] != 4} {
    53     53       error "Database content appears incorrect"
    54     54     }
    55     55   }
           56  +
           57  +#-------------------------------------------------------------------------
           58  +# Test fault-injection while rolling back a hot-journal file with a 
           59  +# page-size different from the current value stored on page 1 of the
           60  +# database file.
           61  +#
           62  +do_test pagerfault-2-pre1 {
           63  +  testvfs tv -default 1
           64  +  tv filter xSync
           65  +  tv script xSyncCb
           66  +  proc xSyncCb {filename args} {
           67  +    if {[string match *journal filename]==0} faultsim_save
           68  +  }
           69  +  faultsim_delete_and_reopen
           70  +  execsql {
           71  +    PRAGMA page_size = 4096;
           72  +    BEGIN;
           73  +      CREATE TABLE abc(a, b, c);
           74  +      INSERT INTO abc VALUES('o', 't', 't'); 
           75  +      INSERT INTO abc VALUES('f', 'f', 's'); 
           76  +      INSERT INTO abc SELECT * FROM abc; -- 4
           77  +      INSERT INTO abc SELECT * FROM abc; -- 8
           78  +      INSERT INTO abc SELECT * FROM abc; -- 16
           79  +      INSERT INTO abc SELECT * FROM abc; -- 32
           80  +      INSERT INTO abc SELECT * FROM abc; -- 64
           81  +      INSERT INTO abc SELECT * FROM abc; -- 128
           82  +      INSERT INTO abc SELECT * FROM abc; -- 256
           83  +    COMMIT;
           84  +    PRAGMA page_size = 1024;
           85  +    VACUUM;
           86  +  }
           87  +  db close
           88  +  tv delete
           89  +} {}
           90  +do_faultsim_test pagerfault-2 -prep {
           91  +  faultsim_restore_and_reopen
           92  +} -body {
           93  +  execsql { SELECT * FROM abc }
           94  +} -test {
           95  +  set answer [split [string repeat "ottffs" 128] ""]
           96  +  faultsim_test_result [list 0 $answer]
           97  +  faultsim_integrity_check
           98  +  set res [db eval { SELECT * FROM abc }]
           99  +  if {$res != $answer} { error "Database content appears incorrect ($res)" }
          100  +} -faults oom-transient
    56    101   
    57    102   #-------------------------------------------------------------------------
    58    103   # Test fault-injection while rolling back hot-journals that were created
    59    104   # as part of a multi-file transaction.
    60    105   #
    61         -do_test pagerfault-2-pre1 {
          106  +do_test pagerfault-3-pre1 {
    62    107     testvfs tstvfs -default 1
    63    108     tstvfs filter xDelete
    64    109     tstvfs script xDeleteCallback
    65    110   
    66    111     proc xDeleteCallback {method file args} {
    67    112       set file [file tail $file]
    68    113       if { [string match *mj* $file] } { faultsim_save }
................................................................................
    92    137         REPLACE INTO t2 SELECT * FROM t1;
    93    138       COMMIT;
    94    139     }
    95    140   
    96    141     db close
    97    142     tstvfs delete
    98    143   } {}
    99         -do_faultsim_test pagerfault-2 -faults ioerr-persistent -prep {
          144  +do_faultsim_test pagerfault-3 -faults ioerr-persistent -prep {
   100    145     faultsim_restore_and_reopen
   101    146   } -body {
   102    147     execsql { 
   103    148       ATTACH 'test.db2' AS aux;
   104    149       SELECT count(*) FROM t2;
   105    150       SELECT count(*) FROM t1;
   106    151     }
   107    152   } -test {
   108    153     faultsim_test_result {0 {4 4}} {1 {unable to open database: test.db2}}
   109    154     faultsim_integrity_check
   110         -
   111    155     catchsql { ATTACH 'test.db2' AS aux }
   112    156     if {[db one { SELECT count(*) FROM t1 }] != 4
   113    157      || [db one { SELECT count(*) FROM t2 }] != 4
   114    158     } {
   115    159       error "Database content appears incorrect"
   116    160     }
   117    161   }
          162  +
          163  +#-------------------------------------------------------------------------
          164  +# Test fault-injection as part of a vanilla, no-transaction, INSERT
          165  +# statement.
          166  +#
          167  +do_faultsim_test pagerfault-4 -prep {
          168  +  faultsim_delete_and_reopen
          169  +} -body {
          170  +  execsql { 
          171  +    CREATE TABLE x(y);
          172  +    INSERT INTO x VALUES('z');
          173  +    SELECT * FROM x;
          174  +  }
          175  +} -test {
          176  +  faultsim_test_result {0 z}
          177  +  faultsim_integrity_check
          178  +}
          179  +
          180  +#-------------------------------------------------------------------------
          181  +# Test fault-injection as part of a commit when using journal_mode=PERSIST.
          182  +#
          183  +do_test pagerfault-5-pre1 {
          184  +  faultsim_delete_and_reopen
          185  +  db func a_string a_string
          186  +  execsql {
          187  +    CREATE TABLE t1(a UNIQUE, b UNIQUE);
          188  +    INSERT INTO t1 VALUES(a_string(200), a_string(300));
          189  +    INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
          190  +    INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
          191  +  }
          192  +  faultsim_save_and_close
          193  +} {}
          194  +do_faultsim_test pagerfault-5.1 -prep {
          195  +  faultsim_restore_and_reopen
          196  +  db func a_string a_string
          197  +  execsql { PRAGMA journal_mode = PERSIST }
          198  +} -body {
          199  +  execsql { INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1 }
          200  +} -test {
          201  +  faultsim_test_result {0 {}}
          202  +  faultsim_integrity_check
          203  +}
          204  +do_faultsim_test pagerfault-5.2 -prep {
          205  +  faultsim_restore_and_reopen
          206  +  db func a_string a_string
          207  +  execsql { 
          208  +    PRAGMA journal_mode = PERSIST;
          209  +    PRAGMA journal_size_limit = 2048;
          210  +  }
          211  +} -body {
          212  +  execsql { INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1 }
          213  +} -test {
          214  +  faultsim_test_result {0 {}}
          215  +  faultsim_integrity_check
          216  +}
          217  +
          218  +do_faultsim_test pagerfault-5.3 -prep {
          219  +  faultsim_restore_and_reopen
          220  +  db func a_string a_string
          221  +  file delete -force test2.db test2.db-journal test2.db-wal
          222  +  execsql { 
          223  +    PRAGMA journal_mode = PERSIST;
          224  +    ATTACH 'test2.db' AS aux;
          225  +    PRAGMA aux.journal_mode = PERSIST;
          226  +    PRAGMA aux.journal_size_limit = 0;
          227  +  }
          228  +} -body {
          229  +  execsql {
          230  +    BEGIN;
          231  +      INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
          232  +      CREATE TABLE aux.t2 AS SELECT * FROM t1;
          233  +    COMMIT;
          234  +  }
          235  +} -test {
          236  +  faultsim_test_result {0 {}}
          237  +}
   118    238   
   119    239   finish_test