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 between competing processes.
14 # $Id: lock2.test,v 1.11 2009/05/01 10:55:34 danielk1977 Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
19 source $testdir/lock_common.tcl
22 # Simple locking test case:
24 # lock2-1.1: Connect a second process to the database.
25 # lock2-1.2: Establish a RESERVED lock with this process.
26 # lock2-1.3: Get a SHARED lock with the second process.
27 # lock2-1.4: Try for a RESERVED lock with process 2. This fails.
28 # lock2-1.5: Try to upgrade the first process to EXCLUSIVE, this fails so
30 # lock2-1.6: Release the SHARED lock held by the second process.
31 # lock2-1.7: Attempt to reaquire a SHARED lock with the second process.
32 # this fails due to the PENDING lock.
33 # lock2-1.8: Ensure the first process can now upgrade to EXCLUSIVE.
36 set ::tf1 [launch_testfixture]
38 sqlite3 db test.db -key xyzzy
39 db eval {select * from sqlite_master}
43 execsql {pragma lock_status}
44 } {main unlocked temp closed}
45 sqlite3_soft_heap_limit 0
49 CREATE TABLE abc(a, b, c);
56 SELECT * FROM sqlite_master;
62 catch { db eval { CREATE TABLE def(d, e, f) } } msg
65 } {database is locked}
70 } {1 {database is locked}}
74 SELECT * FROM sqlite_master;
83 SELECT * FROM sqlite_master;
87 } {database is locked}
95 SELECT * FROM sqlite_master;
97 } "table abc abc [expr $AUTOVACUUM?3:2] {CREATE TABLE abc(a, b, c)}"
98 catch flush_async_queue
102 SELECT * FROM sqlite_master;
105 } "table abc abc [expr $AUTOVACUUM?3:2] {CREATE TABLE abc(a, b, c)}"
107 catch {testfixture $::tf1 {db close}}
109 sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit)