/ Check-in [1c4e58e7]
Login

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

Overview
Comment:Add extra tests for test_superlock.c.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1c4e58e7211522f0e7dfddd3a2b52f1d0c5421e7
User & Date: dan 2010-11-20 10:57:45
Context
2010-11-20
12:01
Extra tests for "PRAGMA checkpoint_fullfsync". check-in: e38c81cc user: dan tags: trunk
10:57
Add extra tests for test_superlock.c. check-in: 1c4e58e7 user: dan tags: trunk
2010-11-19
18:48
Add tests for "PRAGMA checkpoint_fullfsync". check-in: 765aa1b8 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/superlock.test.

    11     11   #
    12     12   
    13     13   set testdir [file dirname $argv0]
    14     14   source $testdir/tester.tcl
    15     15   source $testdir/lock_common.tcl
    16     16   
    17     17   set testprefix superlock
           18  +
           19  +# Test organization:
           20  +#
           21  +#   1.*: Test superlock on a rollback database. Test that once the db is
           22  +#        superlocked, it is not possible for a second client to read from
           23  +#        it.
           24  +#
           25  +#   2.*: Test superlock on a WAL database with zero frames in the WAL file.
           26  +#        Test that once the db is superlocked, it is not possible to read,
           27  +#        write or checkpoint the db.
           28  +#
           29  +#   3.*: As 2.*, for WAL databases with one or more frames in the WAL.
           30  +#
           31  +#   4.*: As 2.*, for WAL databases with one or more checkpointed frames 
           32  +#        in the WAL.
           33  +#
           34  +#   5.*: Test that a call to sqlite3demo_superlock() uses the busy handler
           35  +#        correctly to wait for existing clients to clear on a WAL database.
           36  +#        And returns SQLITE_BUSY if no busy handler is defined or the busy
           37  +#        handler returns 0 before said clients relinquish their locks.
           38  +#
           39  +#   6.*: Test that if a superlocked WAL database is overwritten, existing
           40  +#        clients run the recovery to build the new wal-index after the 
           41  +#        superlock is released.
           42  +#        
           43  +#
    18     44   
    19     45   do_execsql_test 1.1 {
    20     46     CREATE TABLE t1(a, b);
    21     47     INSERT INTO t1 VALUES(1, 2);
    22     48     PRAGMA journal_mode = DELETE;
    23     49   } {delete}
    24     50   
................................................................................
    50     76   do_test 4.2 { sqlite3demo_superlock unlock test.db } {unlock}
    51     77   do_catchsql_test 4.3 { SELECT * FROM t1 }           {1 {database is locked}}
    52     78   do_catchsql_test 4.4 { INSERT INTO t1 VALUES(5, 6)} {1 {database is locked}}
    53     79   do_catchsql_test 4.5 { PRAGMA wal_checkpoint }      {1 {database is locked}}
    54     80   do_test 4.6 { unlock } {}
    55     81   
    56     82   do_multiclient_test tn {
           83  +
    57     84     proc busyhandler {x} {
    58     85       switch -- $x {
    59     86         1 { sql1 "COMMIT" }
    60     87         2 { sql2 "COMMIT" }
    61     88         3 { sql3 "COMMIT" }
    62     89       }
    63     90       lappend ::busylist $x
................................................................................
    88    115     do_test 5.$tn.4 { csql2 { SELECT * FROM t1 } } {1 {database is locked}}
    89    116     do_test 5.$tn.5 { 
    90    117       csql3 { INSERT INTO t1 VALUES(5, 6) } 
    91    118     } {1 {database is locked}}
    92    119     do_test 5.$tn.6 { csql1 "PRAGMA wal_checkpoint" } {1 {database is locked}}
    93    120   
    94    121     do_test 5.$tn.7 { unlock } {}
          122  +
          123  +  
          124  +  do_test 5.$tn.8 {
          125  +    sql1 { BEGIN ; SELECT * FROM t1 }
          126  +    sql2 { BEGIN ; INSERT INTO t1 VALUES(5, 6) }
          127  +    sql3 { BEGIN ; SELECT * FROM t1 }
          128  +  } {1 2 3 4}
          129  +
          130  +  do_test 5.$tn.9 { 
          131  +    list [catch {sqlite3demo_superlock unlock test.db} msg] $msg
          132  +  } {1 {database is locked}}
          133  +  do_test 5.$tn.10 { 
          134  +    sql1 COMMIT
          135  +    list [catch {sqlite3demo_superlock unlock test.db} msg] $msg
          136  +  } {1 {database is locked}}
          137  +  do_test 5.$tn.11 { 
          138  +    sql2 COMMIT
          139  +    list [catch {sqlite3demo_superlock unlock test.db} msg] $msg
          140  +  } {1 {database is locked}}
          141  +  do_test 5.$tn.12 { 
          142  +    sql3 COMMIT
          143  +    list [catch {sqlite3demo_superlock unlock test.db} msg] $msg
          144  +  } {0 unlock}
          145  +  unlock
          146  +}
          147  +
          148  +proc read_content {file} {
          149  +  if {[file exists $file]==0} {return ""}
          150  +  set fd [open $file]
          151  +  fconfigure $fd -encoding binary -translation binary
          152  +  set content [read $fd]
          153  +  close $fd
          154  +  return $content
          155  +}
          156  +
          157  +proc write_content {file content} {
          158  +  set fd [open $file w+]
          159  +  fconfigure $fd -encoding binary -translation binary
          160  +  puts -nonewline $fd $content
          161  +  close $fd
          162  +}
          163  +
          164  +# Both $file1 and $file2 are database files. This function takes a 
          165  +# superlock on each, then exchanges the content of the two files (i.e.
          166  +# overwrites $file1 with the initial contents of $file2, and overwrites
          167  +# $file2 with the initial contents of $file1). The contents of any WAL 
          168  +# file is also exchanged.
          169  +#
          170  +proc db_swap {file1 file2} {
          171  +  sqlite3demo_superlock unlock1 $file1
          172  +  sqlite3demo_superlock unlock2 $file2
          173  +
          174  +  set db1 [read_content $file1]
          175  +  set db2 [read_content $file2]
          176  +  write_content $file1 $db2
          177  +  write_content $file2 $db1
          178  +
          179  +  set wal1 [read_content ${file1}-wal]
          180  +  set wal2 [read_content ${file2}-wal]
          181  +  write_content ${file1}-wal $wal2
          182  +  write_content ${file2}-wal $wal1
          183  +
          184  +  unlock1
          185  +  unlock2
    95    186   }
    96    187   
          188  +forcedelete test.db
          189  +sqlite3 db  test.db
          190  +do_execsql_test 6.1 {
          191  +  ATTACH 'test.db2' AS aux;
          192  +  PRAGMA aux.journal_mode = wal;
          193  +  CREATE TABLE aux.t2(x, y);
          194  +  INSERT INTO aux.t2 VALUES('a', 'b');
          195  +  PRAGMA schema_version = 450;
          196  +  DETACH aux;
          197  +
          198  +  PRAGMA main.journal_mode = wal;
          199  +  CREATE TABLE t1(a, b);
          200  +  INSERT INTO t1 VALUES(1, 2);
          201  +  INSERT INTO t1 VALUES(3, 4);
          202  +  SELECT * FROM t1;
          203  +} {wal wal 1 2 3 4}
          204  +
          205  +
          206  +db_swap test.db2 test.db
          207  +do_catchsql_test 6.2 { SELECT * FROM t1 } {1 {no such table: t1}}
          208  +do_catchsql_test 6.3 { SELECT * FROM t2 } {0 {a b}}
          209  +
          210  +db_swap test.db2 test.db
          211  +do_catchsql_test 6.4 { SELECT * FROM t1 } {0 {1 2 3 4}}
          212  +do_catchsql_test 6.5 { SELECT * FROM t2 } {1 {no such table: t2}}
          213  +
          214  +do_execsql_test  6.6 { PRAGMA wal_checkpoint }
          215  +
          216  +db_swap test.db2 test.db
          217  +do_catchsql_test 6.7 { SELECT * FROM t1 } {1 {no such table: t1}}
          218  +do_catchsql_test 6.8 { SELECT * FROM t2 } {0 {a b}}
          219  +
          220  +db_swap test.db2 test.db
          221  +do_catchsql_test 6.9 { SELECT * FROM t1 } {0 {1 2 3 4}}
          222  +do_catchsql_test 6.10 { SELECT * FROM t2 } {1 {no such table: t2}}
          223  +
          224  +do_execsql_test  6.11 { 
          225  +  PRAGMA journal_mode = delete;
          226  +  PRAGMA page_size = 512;
          227  +  VACUUM;
          228  +  PRAGMA journal_mode = wal;
          229  +  INSERT INTO t1 VALUES(5, 6);
          230  +} {delete wal}
          231  +
          232  +db_swap test.db2 test.db
          233  +do_catchsql_test 6.12 { SELECT * FROM t1 } {1 {no such table: t1}}
          234  +do_catchsql_test 6.13 { SELECT * FROM t2 } {0 {a b}}
          235  +
          236  +db_swap test.db2 test.db
          237  +do_catchsql_test 6.14 { SELECT * FROM t1 } {0 {1 2 3 4 5 6}}
          238  +do_catchsql_test 6.15 { SELECT * FROM t2 } {1 {no such table: t2}}
    97    239   
    98    240   finish_test