/ Check-in [6cae5529]
Login

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

Overview
Comment:Add test cases to restore coverage of pager.c and wal.c.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6cae552927392d8b735aa118c318d7468097ebeb
User & Date: dan 2010-11-01 18:45:09
Context
2010-11-02
15:26
Add evidence marks for the sqlite3_blob_reopen() interface. Fix compiler warnings in test1.c. Fix incorrect evidence marks on e_select.tcl. check-in: 3771faa8 user: drh tags: trunk
2010-11-01
18:45
Add test cases to restore coverage of pager.c and wal.c. check-in: 6cae5529 user: dan tags: trunk
17:38
If a database file with the WAL flag set is opened in exclusive-locking mode, use heap memory to store the wal-index instead of shared-memory. check-in: 8dd5c691 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/pager1.test.

  2348   2348   do_test pager1-29.2 {
  2349   2349     execsql {
  2350   2350       PRAGMA page_size = 4096;
  2351   2351       VACUUM;
  2352   2352     }
  2353   2353     file size test.db
  2354   2354   } [expr 4096*3]
         2355  +
         2356  +#-------------------------------------------------------------------------
         2357  +# Test that if an empty database file (size 0 bytes) is opened in 
         2358  +# exclusive-locking mode, any journal file is deleted from the file-system
         2359  +# without being rolled back. And that the RESERVED lock obtained while
         2360  +# doing this is not released.
         2361  +#
         2362  +do_test pager1-30.1 {
         2363  +  db close
         2364  +  file delete test.db
         2365  +  file delete test.db-journal
         2366  +  set fd [open test.db-journal w]
         2367  +  seek $fd [expr 512+1032*2]
         2368  +  puts -nonewline $fd x
         2369  +  close $fd
         2370  +
         2371  +  sqlite3 db test.db
         2372  +  execsql {
         2373  +    PRAGMA locking_mode=EXCLUSIVE;
         2374  +    SELECT count(*) FROM sqlite_master;
         2375  +    PRAGMA lock_status;
         2376  +  }
         2377  +} {exclusive 0 main reserved temp closed}
         2378  +
         2379  +#-------------------------------------------------------------------------
         2380  +# Test that if the "page-size" field in a journal-header is 0, the journal
         2381  +# file can still be rolled back. This is required for backward compatibility -
         2382  +# versions of SQLite prior to 3.5.8 always set this field to zero.
         2383  +#
         2384  +do_test pager1-31.1 {
         2385  +  faultsim_delete_and_reopen
         2386  +  execsql {
         2387  +    PRAGMA cache_size = 10;
         2388  +    PRAGMA page_size = 1024;
         2389  +    CREATE TABLE t1(x, y, UNIQUE(x, y));
         2390  +    INSERT INTO t1 VALUES(randomblob(1500), randomblob(1500));
         2391  +    INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
         2392  +    INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
         2393  +    INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
         2394  +    INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
         2395  +    INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
         2396  +    INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
         2397  +    INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
         2398  +    INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
         2399  +    INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
         2400  +    INSERT INTO t1 SELECT randomblob(1500), randomblob(1500) FROM t1;
         2401  +    BEGIN;
         2402  +      UPDATE t1 SET y = randomblob(1499);
         2403  +  }
         2404  +  file copy test.db test.db2
         2405  +  file copy test.db-journal test.db2-journal
         2406  +  
         2407  +  hexio_write test.db2-journal 24 00000000
         2408  +  sqlite3 db2 test.db2
         2409  +  execsql { PRAGMA integrity_check } db2
         2410  +} {ok}
         2411  +
  2355   2412   
  2356   2413   
  2357   2414   finish_test

Changes to test/walfault.test.

   506    506       PRAGMA locking_mode = exclusive;
   507    507       PRAGMA journal_mode = WAL;
   508    508       INSERT INTO abc VALUES(randomblob(1500));
   509    509     }
   510    510   } -test {
   511    511     faultsim_test_result {0 {exclusive wal}}
   512    512     if {[file exists test.db-shm]} { error "Not using heap-memory mode" }
          513  +  faultsim_integrity_check
          514  +  set nRow [db eval {SELECT count(*) FROM abc}]
          515  +  if {!(($nRow==2 && $testrc) || $nRow==3)} { error "Bad db content" }
          516  +}
          517  +
          518  +#-------------------------------------------------------------------------
          519  +# Test fault-handling when wrapping around to the start of a WAL file.
          520  +#
          521  +do_test walfault-14-pre {
          522  +  faultsim_delete_and_reopen
          523  +  execsql {
          524  +    PRAGMA journal_mode = WAL;
          525  +    BEGIN;
          526  +      CREATE TABLE abc(a PRIMARY KEY);
          527  +      INSERT INTO abc VALUES(randomblob(1500));
          528  +      INSERT INTO abc VALUES(randomblob(1500));
          529  +    COMMIT;
          530  +  }
          531  +  faultsim_save_and_close
          532  +} {}
          533  +do_faultsim_test walfault-14 -prep {
          534  +  faultsim_restore_and_reopen
          535  +} -body {
          536  +  db eval { 
          537  +    PRAGMA wal_checkpoint;
          538  +    INSERT INTO abc VALUES(randomblob(1500));
          539  +  }
          540  +} -test {
          541  +  faultsim_test_result {0 {}}
   513    542     faultsim_integrity_check
   514    543     set nRow [db eval {SELECT count(*) FROM abc}]
   515    544     if {!(($nRow==2 && $testrc) || $nRow==3)} { error "Bad db content" }
   516    545   }
   517    546   
   518    547   finish_test

Changes to test/walnoshm.test.

   136    136   do_test 2.2.6 {
   137    137     db3 close
   138    138     db4 close
   139    139     execsql { SELECT * FROM t2 } db2
   140    140   } {a b c d e f g h}
   141    141   
   142    142   db2 close
          143  +db close
          144  +
          145  +#-------------------------------------------------------------------------
          146  +#
          147  +# 3.1: Test that if locking_mode=EXCLUSIVE is set after the wal file is
          148  +#      opened, it is possible to drop back to locking_mode=NORMAL.
          149  +#
          150  +# 3.2: Test that if locking_mode=EXCLUSIVE is set before the wal file is
          151  +#      opened, it is not.
          152  +#
          153  +do_test 3.1 {
          154  +  sqlite3 db test.db -vfs tvfsshm
          155  +  execsql { 
          156  +    SELECT * FROM t1;
          157  +    PRAGMA locking_mode = EXCLUSIVE;
          158  +    INSERT INTO t1 VALUES(5, 6);
          159  +    PRAGMA locking_mode = NORMAL;
          160  +    INSERT INTO t1 VALUES(7, 8);
          161  +  }
          162  +  sqlite3 db2 test.db -vfs tvfsshm
          163  +  execsql { SELECT * FROM t1 } db2
          164  +} {1 2 3 4 5 6 7 8}
          165  +db close
          166  +db2 close
          167  +do_test 3.2 {
          168  +  sqlite3 db  test.db -vfs tvfsshm
          169  +  execsql { 
          170  +    PRAGMA locking_mode = EXCLUSIVE;
          171  +    INSERT INTO t1 VALUES(9, 10);
          172  +    PRAGMA locking_mode = NORMAL;
          173  +    INSERT INTO t1 VALUES(11, 12);
          174  +  }
          175  +  sqlite3 db2 test.db -vfs tvfsshm
          176  +  catchsql { SELECT * FROM t1 } db2
          177  +} {1 {database is locked}}
          178  +db close
          179  +db2 close
   143    180   
          181  +tvfs delete
          182  +tvfsshm delete
   144    183   
   145    184   finish_test
   146         -