os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/tkt3093.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/tkt3093.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,86 @@
     1.4 +# 2008 May 2
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +#
    1.15 +# Ticket #3093
    1.16 +#
    1.17 +# Verify that a busy callback waiting on a reserved lock resolves
    1.18 +# once the lock clears.
    1.19 +#
    1.20 +# $Id: tkt3093.test,v 1.2 2008/05/02 14:23:55 drh Exp $
    1.21 +#
    1.22 +
    1.23 +set testdir [file dirname $argv0]
    1.24 +source $testdir/tester.tcl
    1.25 +
    1.26 +# Set up a test database
    1.27 +#
    1.28 +do_test tkt3093.1 {
    1.29 +  db eval {
    1.30 +    CREATE TABLE t1(x);
    1.31 +    INSERT INTO t1 VALUES(1);
    1.32 +    SELECT * FROM t1
    1.33 +  }
    1.34 +} {1}
    1.35 +
    1.36 +# Establish a separate, independent connection to that database.
    1.37 +#
    1.38 +do_test tkt3093.2 {
    1.39 +  catch {sqlite3_enable_shared_cache 0}
    1.40 +  sqlite3 db2 test.db
    1.41 +  db2 eval {
    1.42 +    SELECT * FROM t1
    1.43 +  }
    1.44 +} {1}
    1.45 +
    1.46 +# Make sure that clearing a lock allows a pending request for
    1.47 +# a reserved lock to continue.
    1.48 +#
    1.49 +do_test tkt3093.3 {
    1.50 +  # This will be the busy callback for connection db2.  On the first
    1.51 +  # busy callback, commit the transaction in db.  This should clear
    1.52 +  # the lock so that there should not be a second callback.  If the
    1.53 +  # busy handler is called a second time, then fail so that we get
    1.54 +  # timeout.
    1.55 +  proc busy_callback {cnt} {
    1.56 +    if {$cnt==0} {
    1.57 +      db eval COMMIT
    1.58 +      return 0
    1.59 +    } else {
    1.60 +      return 1
    1.61 +    }
    1.62 +  }
    1.63 +  db2 busy ::busy_callback
    1.64 +
    1.65 +  # Start a write transaction on db.
    1.66 +  db eval {
    1.67 +     BEGIN;
    1.68 +     INSERT INTO t1 VALUES(2);
    1.69 +  }
    1.70 +
    1.71 +  # Attempt to modify the database on db2
    1.72 +  catchsql {
    1.73 +     UPDATE t1 SET x=x+1;
    1.74 +  } db2
    1.75 +} {0 {}}
    1.76 +
    1.77 +# Verify that everything worked as expected.  The db transaction should
    1.78 +# have gone first and added entry 2.  Then the db2 transaction would have
    1.79 +# run and added one to each entry.
    1.80 +#
    1.81 +do_test tkt3093.4 {
    1.82 +  db eval {SELECT * FROM t1}
    1.83 +} {2 3}
    1.84 +do_test tkt3093.5 {
    1.85 +  db2 eval {SELECT * FROM t1}
    1.86 +} {2 3}
    1.87 +db2 close
    1.88 +
    1.89 +finish_test