AryaWu/sqlite
0
1# 2008 May 22#3# The author disclaims copyright to this source code. In place of4# a legal notice, here is a blessing:5#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.9#10#***********************************************************************11#12# Ticket #309313#14# Verify that a busy callback waiting on a reserved lock resolves15# once the lock clears.16#17# $Id: tkt3093.test,v 1.2 2008/05/02 14:23:55 drh Exp $18#19 20set testdir [file dirname $argv0]21source $testdir/tester.tcl22 23# Set up a test database24#25do_test tkt3093.1 {26 db eval {27 CREATE TABLE t1(x);28 INSERT INTO t1 VALUES(1);29 SELECT * FROM t130 }31} {1}32 33# Establish a separate, independent connection to that database.34#35do_test tkt3093.2 {36 catch {sqlite3_enable_shared_cache 0}37 sqlite3 db2 test.db38 db2 eval {39 SELECT * FROM t140 }41} {1}42 43# Make sure that clearing a lock allows a pending request for44# a reserved lock to continue.45#46do_test tkt3093.3 {47 # This will be the busy callback for connection db2. On the first48 # busy callback, commit the transaction in db. This should clear49 # the lock so that there should not be a second callback. If the50 # busy handler is called a second time, then fail so that we get51 # timeout.52 proc busy_callback {cnt} {53 if {$cnt==0} {54 db eval COMMIT55 return 056 } else {57 return 158 }59 }60 db2 busy ::busy_callback61 62 # Start a write transaction on db.63 db eval {64 BEGIN;65 INSERT INTO t1 VALUES(2);66 }67 68 # Attempt to modify the database on db269 catchsql {70 UPDATE t1 SET x=x+1;71 } db272} {0 {}}73 74# Verify that everything worked as expected. The db transaction should75# have gone first and added entry 2. Then the db2 transaction would have76# run and added one to each entry.77#78do_test tkt3093.4 {79 db eval {SELECT * FROM t1}80} {2 3}81do_test tkt3093.5 {82 db2 eval {SELECT * FROM t1}83} {2 3}84db2 close85 86finish_test87 