/ Check-in [c6e75950]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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 | trunk
Files: files | file ages | folders
SHA1: c6e75950928954fbb1590f952e3cdbcb0753b745
User & Date: dan 2010-07-01 19:01:56
Context
2010-07-01
19:45
If you delete a database file but not its *-wal file, then open the database (thus creating a new empty database file) the *-wal file is automatically deleted. check-in: 95c69dfb user: drh tags: trunk
19:01
Add tests to pager1.test and pagerfault.test. check-in: c6e75950 user: dan tags: trunk
15:09
Add pager test cases. Change a condition in pager.c to NEVER(). check-in: a8f6341d user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/pager1.test.

  1218   1218   } {SQLITE_DONE SQLITE_OK}
  1219   1219   do_test pager1-9.2.3 {
  1220   1220    db one {SELECT md5sum(a, b) FROM ab}
  1221   1221   } [db2 one {SELECT md5sum(a, b) FROM ab}]
  1222   1222   do_test pager1-9.2.4 { execsql { SELECT count(*) FROM ab } } {128}
  1223   1223   db close
  1224   1224   db2 close
         1225  +
         1226  +proc recursive_select {id table {script {}}} {
         1227  +  set cnt 0
         1228  +  db eval "SELECT rowid, * FROM $table WHERE rowid = ($id-1)" {
         1229  +    recursive_select $rowid $table $script
         1230  +    incr cnt
         1231  +  }
         1232  +  if {$cnt==0} { eval $script }
         1233  +}
  1225   1234   
  1226   1235   #-------------------------------------------------------------------------
  1227   1236   # Test that regardless of the value returned by xSectorSize(), the
  1228   1237   # minimum effective sector-size is 512 and the maximum 65536 bytes.
  1229   1238   #
  1230   1239   testvfs tv -default 1
  1231   1240   foreach sectorsize {
................................................................................
  1233   1242       4096 8192 16384 32768 65536 131072 262144
  1234   1243   } {
  1235   1244     tv sectorsize $sectorsize
  1236   1245     set eff $sectorsize
  1237   1246     if {$sectorsize < 512}   { set eff 512 }
  1238   1247     if {$sectorsize > 65536} { set eff 65536 }
  1239   1248   
  1240         -  do_test pager1-10.$sectorsize {
         1249  +  do_test pager1-10.$sectorsize.1 {
  1241   1250       faultsim_delete_and_reopen
         1251  +    db func a_string a_string
  1242   1252       execsql {
  1243   1253         PRAGMA journal_mode = PERSIST;
  1244   1254         PRAGMA page_size = 1024;
  1245         -      CREATE TABLE t1(a, b);
         1255  +      BEGIN;
         1256  +        CREATE TABLE t1(a, b);
         1257  +        CREATE TABLE t2(a, b);
         1258  +        CREATE TABLE t3(a, b);
         1259  +      COMMIT;
  1246   1260       }
  1247   1261       file size test.db-journal
  1248   1262     } [expr $sectorsize > 65536 ? 65536 : $sectorsize]
         1263  +
         1264  +  do_test pager1-10.$sectorsize.2 {
         1265  +    execsql { 
         1266  +      INSERT INTO t3 VALUES(a_string(300), a_string(300));
         1267  +      INSERT INTO t3 SELECT * FROM t3;        /*  2 */
         1268  +      INSERT INTO t3 SELECT * FROM t3;        /*  4 */
         1269  +      INSERT INTO t3 SELECT * FROM t3;        /*  8 */
         1270  +      INSERT INTO t3 SELECT * FROM t3;        /* 16 */
         1271  +      INSERT INTO t3 SELECT * FROM t3;        /* 32 */
         1272  +    }
         1273  +  } {}
         1274  +
         1275  +  do_test pager1-10.$sectorsize.3 {
         1276  +    db close
         1277  +    sqlite3 db test.db
         1278  +    execsql { 
         1279  +      PRAGMA cache_size = 10;
         1280  +      BEGIN;
         1281  +    }
         1282  +    recursive_select 32 t3 {db eval "INSERT INTO t2 VALUES(1, 2)"}
         1283  +    execsql {
         1284  +      COMMIT;
         1285  +      SELECT * FROM t2;
         1286  +    }
         1287  +  } {1 2}
         1288  +
         1289  +  do_test pager1-10.$sectorsize.4 {
         1290  +    execsql {
         1291  +      CREATE TABLE t6(a, b);
         1292  +      CREATE TABLE t7(a, b);
         1293  +      CREATE TABLE t5(a, b);
         1294  +      DROP TABLE t6;
         1295  +      DROP TABLE t7;
         1296  +    }
         1297  +    if {$eff==65536} breakpoint
         1298  +    execsql {
         1299  +      BEGIN;
         1300  +        CREATE TABLE t6(a, b);
         1301  +    }
         1302  +    recursive_select 32 t3 {db eval "INSERT INTO t5 VALUES(1, 2)"}
         1303  +    execsql {
         1304  +      COMMIT;
         1305  +      SELECT * FROM t5;
         1306  +    }
         1307  +  } {1 2}
         1308  +  
  1249   1309   }
         1310  +db close
         1311  +
         1312  +tv sectorsize 4096
         1313  +do_test pager1.10.x.1 {
         1314  +  faultsim_delete_and_reopen
         1315  +  execsql {
         1316  +    PRAGMA page_size = 1024;
         1317  +    CREATE TABLE t1(x);
         1318  +  }
         1319  +  for {set i 0} {$i<30} {incr i} {
         1320  +    execsql { INSERT INTO t1 VALUES(zeroblob(900)) }
         1321  +  }
         1322  +  file size test.db
         1323  +} {32768}
         1324  +do_test pager1.10.x.2 {
         1325  +  execsql {
         1326  +    CREATE TABLE t2(x);
         1327  +    DROP TABLE t2;
         1328  +  }
         1329  +  file size test.db
         1330  +} {33792}
         1331  +do_test pager1.10.x.3 {
         1332  +  execsql {
         1333  +    BEGIN;
         1334  +    CREATE TABLE t2(x);
         1335  +  }
         1336  +  recursive_select 30 t1
         1337  +  execsql {
         1338  +    CREATE TABLE t3(x);
         1339  +    COMMIT;
         1340  +  }
         1341  +} {}
         1342  +
  1250   1343   db close
  1251   1344   tv delete
  1252   1345   
  1253   1346   testvfs tv -default 1
  1254   1347   faultsim_delete_and_reopen
  1255   1348   db func a_string a_string
  1256   1349   do_execsql_test pager1-11.1 {
................................................................................
  1796   1889     testvfs tv -noshm 1
  1797   1890     sqlite3 db2 test.db -vfs tv
  1798   1891     catchsql { SELECT * FROM ko } db2
  1799   1892   } {1 {unable to open database file}}
  1800   1893   db2 close
  1801   1894   tv delete
  1802   1895   do_test pager1-21.2 {
  1803         -breakpoint
  1804   1896     testvfs tv -iversion 1
  1805   1897     sqlite3 db2 test.db -vfs tv
  1806   1898     catchsql { SELECT * FROM ko } db2
  1807   1899   } {1 {unable to open database file}}
  1808   1900   db2 close
  1809   1901   tv delete
  1810   1902   
................................................................................
  1852   1944   #   pager1-23.3.*: Same test as above, but while a reserved lock is held
  1853   1945   #                  on the database file.
  1854   1946   #
  1855   1947   #   pager1-23.4.*: And, for fun, while holding an exclusive lock.
  1856   1948   #
  1857   1949   #   pager1-23.5.*: Try to set various different journal modes with an
  1858   1950   #                  in-memory database (only MEMORY and OFF should work).
         1951  +#
         1952  +#   pager1-23.6.*: Try to set locking_mode=normal on an in-memory database
         1953  +#                  (doesn't work - in-memory databases always use
         1954  +#                  locking_mode=exclusive).
  1859   1955   #
  1860   1956   do_test pager1-23.1.1 {
  1861   1957     faultsim_delete_and_reopen
  1862   1958     execsql {
  1863   1959       PRAGMA journal_mode = PERSIST;
  1864   1960       CREATE TABLE t1(a, b);
  1865   1961     }
................................................................................
  1933   2029       execsql "PRAGMA journal_mode = $mode"
  1934   2030     } [if $possible {list $mode} {list off}]
  1935   2031     do_test pager1-23.5.$tn.2 {
  1936   2032       execsql "PRAGMA journal_mode = memory"
  1937   2033       execsql "PRAGMA journal_mode = $mode"
  1938   2034     } [if $possible {list $mode} {list memory}]
  1939   2035   }
  1940         -do_test pager1-23.8.1 {
         2036  +do_test pager1-23.6.1 {
  1941   2037     execsql {PRAGMA locking_mode = normal}
  1942   2038   } {exclusive}
  1943         -do_test pager1-23.8.2 {
         2039  +do_test pager1-23.6.2 {
  1944   2040     execsql {PRAGMA locking_mode = exclusive}
  1945   2041   } {exclusive}
  1946         -do_test pager1-23.8.3 {
         2042  +do_test pager1-23.6.3 {
  1947   2043     execsql {PRAGMA locking_mode}
  1948   2044   } {exclusive}
  1949         -do_test pager1-23.8.4 {
         2045  +do_test pager1-23.6.4 {
  1950   2046     execsql {PRAGMA main.locking_mode}
  1951   2047   } {exclusive}
  1952   2048   
         2049  +#-------------------------------------------------------------------------
         2050  +#
         2051  +do_test pager1-24.1.1 {
         2052  +  faultsim_delete_and_reopen
         2053  +  db func a_string a_string
         2054  +  execsql {
         2055  +    PRAGMA cache_size = 10;
         2056  +    PRAGMA auto_vacuum = FULL;
         2057  +    CREATE TABLE x1(x, y, z, PRIMARY KEY(y, z));
         2058  +    CREATE TABLE x2(x, y, z, PRIMARY KEY(y, z));
         2059  +    INSERT INTO x2 VALUES(a_string(400), a_string(500), a_string(600));
         2060  +    INSERT INTO x2 SELECT a_string(600), a_string(400), a_string(500) FROM x2;
         2061  +    INSERT INTO x2 SELECT a_string(500), a_string(600), a_string(400) FROM x2;
         2062  +    INSERT INTO x2 SELECT a_string(400), a_string(500), a_string(600) FROM x2;
         2063  +    INSERT INTO x2 SELECT a_string(600), a_string(400), a_string(500) FROM x2;
         2064  +    INSERT INTO x2 SELECT a_string(500), a_string(600), a_string(400) FROM x2;
         2065  +    INSERT INTO x2 SELECT a_string(400), a_string(500), a_string(600) FROM x2;
         2066  +    INSERT INTO x1 SELECT * FROM x2;
         2067  +  }
         2068  +} {}
         2069  +proc recursive_select {id {script {}}} {
         2070  +  set cnt 0
         2071  +  db eval {SELECT rowid, x,y,z FROM x2 WHERE rowid = ($id-1)} {
         2072  +    recursive_select $rowid $script
         2073  +    incr cnt
         2074  +  }
         2075  +  if {$cnt==0} { eval $script }
         2076  +}
         2077  +do_test pager1-24.1.2 {
         2078  +  execsql {
         2079  +    BEGIN;
         2080  +      DELETE FROM x1 WHERE rowid<32;
         2081  +  }
         2082  +  recursive_select 64
         2083  +} {}
         2084  +do_test pager1-24.1.3 {
         2085  +  execsql { 
         2086  +      UPDATE x1 SET z = a_string(300) WHERE rowid>40;
         2087  +    COMMIT;
         2088  +    PRAGMA integrity_check;
         2089  +    SELECT count(*) FROM x1;
         2090  +  }
         2091  +} {ok 33}
         2092  +
         2093  +do_test pager1-24.1.4 {
         2094  +  execsql {
         2095  +    DELETE FROM x1;
         2096  +    INSERT INTO x1 SELECT * FROM x2;
         2097  +    BEGIN;
         2098  +      DELETE FROM x1 WHERE rowid<32;
         2099  +      UPDATE x1 SET z = a_string(299) WHERE rowid>40;
         2100  +  }
         2101  +  recursive_select 64 {db eval COMMIT}
         2102  +  execsql {
         2103  +    PRAGMA integrity_check;
         2104  +    SELECT count(*) FROM x1;
         2105  +  }
         2106  +} {ok 33}
         2107  +
         2108  +do_test pager1-24.1.5 {
         2109  +  execsql {
         2110  +    DELETE FROM x1;
         2111  +    INSERT INTO x1 SELECT * FROM x2;
         2112  +  }
         2113  +  recursive_select 64 { db eval {CREATE TABLE x3(x, y, z)} }
         2114  +  execsql { SELECT * FROM x3 }
         2115  +} {}
         2116  +
         2117  +#-------------------------------------------------------------------------
         2118  +#
         2119  +do_test pager1-25-1 {
         2120  +  faultsim_delete_and_reopen
         2121  +  execsql {
         2122  +    BEGIN;
         2123  +      SAVEPOINT abc;
         2124  +        CREATE TABLE t1(a, b);
         2125  +      ROLLBACK TO abc;
         2126  +    COMMIT;
         2127  +  }
         2128  +  db close
         2129  +} {}
         2130  +breakpoint
         2131  +do_test pager1-25-2 {
         2132  +  faultsim_delete_and_reopen
         2133  +  execsql {
         2134  +    SAVEPOINT abc;
         2135  +      CREATE TABLE t1(a, b);
         2136  +    ROLLBACK TO abc;
         2137  +    COMMIT;
         2138  +  }
         2139  +  db close
         2140  +} {}
  1953   2141   
  1954   2142   finish_test
  1955         -

Changes to test/pagerfault.test.

   610    610     faultsim_restore_and_reopen
   611    611   } -body {
   612    612     execsql { CREATE TABLE xx(a, b) }
   613    613   } -test {
   614    614     faultsim_test_result {0 {}}
   615    615   }
   616    616   
   617         -
   618    617   #---------------------------------------------------------------------------
   619    618   # Test fault injection into a small backup operation.
   620    619   #
   621    620   do_test pagerfault-14-pre1 {
   622    621     faultsim_delete_and_reopen
   623    622     db func a_string a_string;
   624    623     execsql {
................................................................................
   641    640   } -test {
   642    641     faultsim_test_result {0 {}} {1 {}} {1 {SQL logic error or missing database}}
   643    642   }
   644    643   do_faultsim_test pagerfault-14b -prep {
   645    644     faultsim_restore_and_reopen
   646    645     sqlite3 db2 ""
   647    646     db2 eval { PRAGMA page_size = 4096; CREATE TABLE xx(a) }
          647  +} -body {
          648  +  sqlite3_backup B db2 main db main
          649  +  B step 200
          650  +  set rc [B finish]
          651  +  if {[string match SQLITE_IOERR_* $rc]} {set rc SQLITE_IOERR}
          652  +  if {$rc != "SQLITE_OK"} { error [sqlite3_test_errstr $rc] }
          653  +  set {} {}
          654  +} -test {
          655  +  faultsim_test_result {0 {}}
          656  +}
          657  +do_faultsim_test pagerfault-14c -prep {
          658  +  faultsim_restore_and_reopen
          659  +  sqlite3 db2 test.db2
          660  +  db2 eval { 
          661  +    PRAGMA synchronous = off; 
          662  +    PRAGMA page_size = 4096; 
          663  +    CREATE TABLE xx(a);
          664  +  }
   648    665   } -body {
   649    666     sqlite3_backup B db2 main db main
   650    667     B step 200
   651    668     set rc [B finish]
   652    669     if {[string match SQLITE_IOERR_* $rc]} {set rc SQLITE_IOERR}
   653    670     if {$rc != "SQLITE_OK"} { error [sqlite3_test_errstr $rc] }
   654    671     set {} {}
................................................................................
   815    832   } -body {
   816    833     execsql { PRAGMA journal_mode = delete }
   817    834   } -test {
   818    835     faultsim_test_result {0 delete}
   819    836     faultsim_integrity_check
   820    837   }
   821    838   
   822         -}
   823         -
   824    839   do_faultsim_test pagerfault-19a -prep {
   825    840     sqlite3 db :memory:
   826    841     db func a_string a_string
   827    842     execsql {
   828    843       PRAGMA auto_vacuum = FULL;
   829    844       BEGIN;
   830    845         CREATE TABLE t1(a, b);
................................................................................
   871    886       SELECT * FROM t4;
   872    887       SELECT * FROM t6;
   873    888     }
   874    889   } -test {
   875    890     faultsim_test_result {0 {3 5 7}}
   876    891   }
   877    892   
          893  +#-------------------------------------------------------------------------
          894  +# This tests fault-injection in a special case in the auto-vacuum code.
          895  +#
   878    896   do_test pagerfault-20-pre1 {
   879    897     faultsim_delete_and_reopen
   880         -  db func a_string a_string
   881    898     execsql {
   882         -    CREATE TABLE x1(x, y, z, PRIMARY KEY(y, z));
   883         -    INSERT INTO x1 VALUES(a_string(400), a_string(500), a_string(600));
   884         -    INSERT INTO x1 SELECT a_string(600), a_string(400), a_string(500) FROM x1;
   885         -    INSERT INTO x1 SELECT a_string(500), a_string(600), a_string(400) FROM x1;
   886         -    INSERT INTO x1 SELECT a_string(400), a_string(500), a_string(600) FROM x1;
   887         -    INSERT INTO x1 SELECT a_string(600), a_string(400), a_string(500) FROM x1;
   888         -    INSERT INTO x1 SELECT a_string(500), a_string(600), a_string(400) FROM x1;
   889         -    INSERT INTO x1 SELECT a_string(400), a_string(500), a_string(600) FROM x1;
          899  +    PRAGMA cache_size = 10;
          900  +    PRAGMA auto_vacuum = FULL;
          901  +    CREATE TABLE t0(a, b);
   890    902     }
   891    903     faultsim_save_and_close
   892    904   } {}
   893    905   do_faultsim_test pagerfault-20 -prep {
   894    906     faultsim_restore_and_reopen
   895         -  db func a_string a_string
   896    907   } -body {
   897    908     execsql { 
   898    909       BEGIN;
   899         -    UPDATE x1 SET z = a_string(300);
   900         -    DELETE FROM x1 WHERE rowid<32;
          910  +      CREATE TABLE t1(a, b);
          911  +      CREATE TABLE t2(a, b);
          912  +      DROP TABLE t1;
   901    913       COMMIT;
   902    914     }
   903    915   } -test {
   904    916     faultsim_test_result {0 {}}
   905         -  faultsim_integrity_check
   906         -  set nRow [db one {SELECT count(*) FROM x1}]
   907         -  if {$nRow!=33 && $nRow!=64} {error "Wrong number of rows $nRow"}
          917  +}
          918  +
          919  +do_test pagerfault-21-pre1 {
          920  +  faultsim_delete_and_reopen
          921  +  execsql {
          922  +    PRAGMA cache_size = 10;
          923  +    CREATE TABLE t0(a PRIMARY KEY, b);
          924  +    INSERT INTO t0 VALUES(1, 2);
          925  +  }
          926  +  faultsim_save_and_close
          927  +} {}
          928  +do_faultsim_test pagerfault-21 -prep {
          929  +  faultsim_restore_and_reopen
          930  +} -body {
          931  +  db eval { SELECT * FROM t0 LIMIT 1 } {
          932  +    db eval { INSERT INTO t0 SELECT a+1, b FROM t0 }
          933  +    db eval { INSERT INTO t0 SELECT a+2, b FROM t0 }
          934  +  }
          935  +} -test {
          936  +  faultsim_test_result {0 {}}
          937  +}
          938  +
   908    939   }
          940  +
   909    941   
   910    942   finish_test