aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/sqlite/unix/sqlite-3.5.1/test/lock4.test
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/lock4.test')
-rw-r--r--libraries/sqlite/unix/sqlite-3.5.1/test/lock4.test99
1 files changed, 99 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/lock4.test b/libraries/sqlite/unix/sqlite-3.5.1/test/lock4.test
new file mode 100644
index 0000000..3820476
--- /dev/null
+++ b/libraries/sqlite/unix/sqlite-3.5.1/test/lock4.test
@@ -0,0 +1,99 @@
1# 2007 April 6
2#
3# The author disclaims copyright to this source code. In place of
4# 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# This file implements regression tests for SQLite library. The
12# focus of this script is database locks.
13#
14# $Id: lock4.test,v 1.6 2007/09/06 23:28:25 drh Exp $
15
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20# Initialize the test.db database so that it is non-empty
21#
22do_test lock4-1.1 {
23 db eval {
24 PRAGMA auto_vacuum=OFF;
25 CREATE TABLE t1(x);
26 }
27 file delete -force test2.db test2.db-journal
28 sqlite3 db2 test2.db
29 db2 eval {
30 PRAGMA auto_vacuum=OFF;
31 CREATE TABLE t2(x)
32 }
33 db2 close
34 list [file size test.db] [file size test2.db]
35} {2048 2048}
36
37# Create a script to drive a separate process that will
38#
39# 1. Create a second database test2.db
40# 2. Get an exclusive lock on test2.db
41# 3. Add an entry to test.db in table t1, waiting as necessary.
42# 4. Commit the change to test2.db.
43#
44# Meanwhile, this process will:
45#
46# A. Get an exclusive lock on test.db
47# B. Attempt to read from test2.db but get an SQLITE_BUSY error.
48# C. Commit the changes to test.db thus alloing the other process
49# to continue.
50#
51do_test lock4-1.2 {
52 set out [open test2-script.tcl w]
53 puts $out "set sqlite_pending_byte [set sqlite_pending_byte]"
54 puts $out {
55 sqlite3 db2 test2.db
56 db2 eval {
57 BEGIN;
58 INSERT INTO t2 VALUES(2);
59 }
60 sqlite3 db test.db
61 db timeout 1000000
62 db eval {
63 INSERT INTO t1 VALUES(2);
64 }
65 db2 eval COMMIT
66 exit
67 }
68 close $out
69 db eval {
70 BEGIN;
71 INSERT INTO t1 VALUES(1);
72 }
73 exec [info nameofexec] ./test2-script.tcl &
74 while {![file exists test2.db-journal]} {
75 after 10
76 }
77 sqlite3 db2 test2.db
78 catchsql {
79 INSERT INTO t2 VALUES(1)
80 } db2
81} {1 {database is locked}}
82do_test lock4-1.3 {
83 db eval {
84 COMMIT;
85 }
86 while {[file exists test2.db-journal]} {
87 after 10
88 }
89 db2 eval {
90 SELECT * FROM t2
91 }
92} {2}
93
94
95do_test lock4-999.1 {
96 rename db2 {}
97} {}
98
99finish_test