sl@0: # 2008 May 2 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # sl@0: # Ticket #3093 sl@0: # sl@0: # Verify that a busy callback waiting on a reserved lock resolves sl@0: # once the lock clears. sl@0: # sl@0: # $Id: tkt3093.test,v 1.2 2008/05/02 14:23:55 drh Exp $ sl@0: # sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # Set up a test database sl@0: # sl@0: do_test tkt3093.1 { sl@0: db eval { sl@0: CREATE TABLE t1(x); sl@0: INSERT INTO t1 VALUES(1); sl@0: SELECT * FROM t1 sl@0: } sl@0: } {1} sl@0: sl@0: # Establish a separate, independent connection to that database. sl@0: # sl@0: do_test tkt3093.2 { sl@0: catch {sqlite3_enable_shared_cache 0} sl@0: sqlite3 db2 test.db sl@0: db2 eval { sl@0: SELECT * FROM t1 sl@0: } sl@0: } {1} sl@0: sl@0: # Make sure that clearing a lock allows a pending request for sl@0: # a reserved lock to continue. sl@0: # sl@0: do_test tkt3093.3 { sl@0: # This will be the busy callback for connection db2. On the first sl@0: # busy callback, commit the transaction in db. This should clear sl@0: # the lock so that there should not be a second callback. If the sl@0: # busy handler is called a second time, then fail so that we get sl@0: # timeout. sl@0: proc busy_callback {cnt} { sl@0: if {$cnt==0} { sl@0: db eval COMMIT sl@0: return 0 sl@0: } else { sl@0: return 1 sl@0: } sl@0: } sl@0: db2 busy ::busy_callback sl@0: sl@0: # Start a write transaction on db. sl@0: db eval { sl@0: BEGIN; sl@0: INSERT INTO t1 VALUES(2); sl@0: } sl@0: sl@0: # Attempt to modify the database on db2 sl@0: catchsql { sl@0: UPDATE t1 SET x=x+1; sl@0: } db2 sl@0: } {0 {}} sl@0: sl@0: # Verify that everything worked as expected. The db transaction should sl@0: # have gone first and added entry 2. Then the db2 transaction would have sl@0: # run and added one to each entry. sl@0: # sl@0: do_test tkt3093.4 { sl@0: db eval {SELECT * FROM t1} sl@0: } {2 3} sl@0: do_test tkt3093.5 { sl@0: db2 eval {SELECT * FROM t1} sl@0: } {2 3} sl@0: db2 close sl@0: sl@0: finish_test