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.
13 # This file implements tests to verify that ticket #3793 has been
16 # $Id: tkt3793.test,v 1.2 2009/06/01 16:42:18 shane Exp $
19 set testdir [file dirname $argv0]
20 source $testdir/tester.tcl
22 ifcapable !shared_cache||!attach {
26 set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
29 # This is taken from shared.test. The Windows VFS expands
30 # ./test.db (and test.db) to be the same thing so the path
31 # matches and they share a cache. By changing the case
32 # for Windows platform, we get around this and get a separate
34 if {$::tcl_platform(platform)=="unix"} {
43 CREATE TABLE t1(a, b);
44 CREATE TABLE t2(a PRIMARY KEY, b);
45 INSERT INTO t1 VALUES(randstr(50,50), randstr(50,50));
46 INSERT INTO t1 SELECT randstr(50,50), randstr(50,50) FROM t1;
47 INSERT INTO t1 SELECT randstr(50,50), randstr(50,50) FROM t1;
48 INSERT INTO t1 SELECT randstr(50,50), randstr(50,50) FROM t1;
49 INSERT INTO t1 SELECT randstr(50,50), randstr(50,50) FROM t1;
50 INSERT INTO t1 SELECT randstr(50,50), randstr(50,50) FROM t1;
51 INSERT INTO t1 SELECT randstr(50,50), randstr(50,50) FROM t1;
52 INSERT INTO t1 SELECT randstr(50,50), randstr(50,50) FROM t1;
53 INSERT INTO t1 SELECT randstr(50,50), randstr(50,50) FROM t1;
54 INSERT INTO t1 SELECT randstr(50,50), randstr(50,50) FROM t1;
55 INSERT INTO t1 SELECT randstr(50,50), randstr(50,50) FROM t1;
56 INSERT INTO t2 SELECT * FROM t1;
61 proc busyhandler {db args} { set ::busyconnection $db ; return 1 }
62 db2 busy {busyhandler db2}
63 db1 busy {busyhandler db1}
65 # Establish a read-lock on the database file using connection [db].
70 SELECT count(*) FROM t1;
74 # Set the size of the cache shared by [db1] and [db2] to 10. Then update
75 # more than 10 pages of table t1. At this point the shared-cache will
76 # hold a RESERVED lock on the database file. Even though there are now
77 # more than 10 dirty pages in memory, it cannot upgrade to an EXCLUSIVE
78 # lock because of the read-lock held by [db].
82 PRAGMA cache_size = 10;
84 UPDATE t1 SET b = randstr(50,50);
90 # Run one SELECT query on the shared-cache using [db1], then from within
91 # the callback run another via [db2]. Because of the large number of dirty
92 # pages within the cache, each time a new page is read from the database
93 # SQLite will attempt to upgrade to an EXCLUSIVE lock, and hence invoke
94 # the busy-handler. The tests here verify that the correct busy-handler
95 # function is invoked (the busy-handler associated with the database
96 # connection that called sqlite3_step()). When bug #3793 existed, sometimes
97 # the [db2] busy-handler was invoked from within the call to sqlite3_step()
98 # associated with [db1].
100 # Note: Before the bug was fixed, if [db2] was opened with the "-fullmutex 1"
101 # option, then this test case would cause an assert() to fail.
103 ifcapable threadsafe {
104 set ::busyconnection db1
105 db1 eval {SELECT * FROM t2 ORDER BY a LIMIT 20} {
106 do_test tkt3793-2.[incr x] { set ::busyconnection } db1
107 set ::busyconnection db2
109 db2 eval { SELECT count(*) FROM t2 }
110 do_test tkt3793-2.[incr x] { set ::busyconnection } db2
111 set ::busyconnection db1
120 sqlite3_enable_shared_cache $::enable_shared_cache