/ Check-in [e62858b9]
Login

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

Overview
Comment:Fix a second race condition in lock4.test. (CVS 4861)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e62858b9b8a12ecbad8037868d03469d27418377
User & Date: danielk1977 2008-03-14 08:57:42
Context
2008-03-14
13:02
Revise Bitvec struct sizing to prevent assertion failure on 64-bit systems (CVS 4862) check-in: a3c12dbe user: mlcreech tags: trunk
08:57
Fix a second race condition in lock4.test. (CVS 4861) check-in: e62858b9 user: danielk1977 tags: trunk
04:11
Allow the testfixture to be built even when using the amalgamation (CVS 4860) check-in: 8a726e37 user: mlcreech tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/lock4.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is database locks.
    13     13   #
    14         -# $Id: lock4.test,v 1.7 2008/03/13 04:53:53 danielk1977 Exp $
           14  +# $Id: lock4.test,v 1.8 2008/03/14 08:57:42 danielk1977 Exp $
    15     15   
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Initialize the test.db database so that it is non-empty
    21     21   #
................................................................................
    45     45   # 
    46     46   #     A.  Get an exclusive lock on test.db
    47     47   #     B.  Attempt to read from test2.db but get an SQLITE_BUSY error.
    48     48   #     C.  Commit the changes to test.db thus alloing the other process
    49     49   #         to continue.
    50     50   #
    51     51   do_test lock4-1.2 {
           52  + 
           53  +  # Create a script for the second process to run.
           54  +  #
    52     55     set out [open test2-script.tcl w]
    53     56     puts $out "set sqlite_pending_byte [set sqlite_pending_byte]"
    54     57     puts $out {
    55     58        sqlite3 db2 test2.db
    56     59        db2 eval {
    57     60           BEGIN;
    58     61           INSERT INTO t2 VALUES(2);
................................................................................
    63     66           INSERT INTO t1 VALUES(2);
    64     67        }
    65     68        db close
    66     69        db2 eval COMMIT
    67     70        exit
    68     71     }
    69     72     close $out
           73  +
           74  +  # Begin a transaction on test.db.
    70     75     db eval {
    71         -     BEGIN;
           76  +     BEGIN EXCLUSIVE;
    72     77        INSERT INTO t1 VALUES(1);
    73     78     }
           79  +
           80  +  # Kick off the second process.
    74     81     exec [info nameofexec] ./test2-script.tcl &
           82  +
           83  +  # Wait until the second process has started its transaction on test2.db.
    75     84     while {![file exists test2.db-journal]} {
    76     85       after 10
    77     86     }
           87  +
           88  +  # Try to write to test2.db. We are locked out.
    78     89     sqlite3 db2 test2.db
    79     90     catchsql {
    80     91       INSERT INTO t2 VALUES(1)
    81     92     } db2
    82     93   } {1 {database is locked}}
    83     94   do_test lock4-1.3 {
    84     95     db eval {
    85     96        COMMIT;
    86     97     }
    87     98     while {[file exists test2.db-journal]} {
    88     99       after 10
    89    100     }
          101  +  # The other process has committed its transaction on test2.db by 
          102  +  # deleting the journal file. But it might retain the lock for a 
          103  +  # fraction longer 
          104  +  #
    90    105     db2 eval {
    91    106        SELECT * FROM t2
    92    107     }
    93    108   } {2}
    94    109   
    95    110       
    96    111   do_test lock4-999.1 {
    97    112     rename db2 {}
    98    113   } {}
    99    114   
   100    115   finish_test