3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this script is database locks.
14 # $Id: lock4.test,v 1.10 2009/05/06 00:52:41 drh Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
22 # Initialize the test.db database so that it is non-empty
26 PRAGMA auto_vacuum=OFF;
29 forcedelete test2.db test2.db-journal
32 PRAGMA auto_vacuum=OFF;
36 list [file size test.db] [file size test2.db]
39 # Create a script to drive a separate process that will
41 # 1. Create a second database test2.db
42 # 2. Get an exclusive lock on test2.db
43 # 3. Add an entry to test.db in table t1, waiting as necessary.
44 # 4. Commit the change to test2.db.
46 # Meanwhile, this process will:
48 # A. Get an exclusive lock on test.db
49 # B. Attempt to read from test2.db but get an SQLITE_BUSY error.
50 # C. Commit the changes to test.db thus alloing the other process
55 # Create a script for the second process to run.
57 set out [open test2-script.tcl w]
58 puts $out "sqlite3_test_control_pending_byte [set sqlite_pending_byte]"
63 INSERT INTO t2 VALUES(2);
68 INSERT INTO t1 VALUES(2);
76 # Begin a transaction on test.db.
79 INSERT INTO t1 VALUES(1);
82 # Kick off the second process.
83 exec [info nameofexec] ./test2-script.tcl &
85 # Wait until the second process has started its transaction on test2.db.
86 while {![file exists test2.db-journal]} {
90 # Try to write to test2.db. We are locked out.
93 INSERT INTO t2 VALUES(1)
95 } {1 {database is locked}}
100 while {[file exists test2.db-journal]} {
103 # The other process has committed its transaction on test2.db by
104 # deleting the journal file. But it might retain the lock for a
114 do_test lock4-999.1 {