xref: /sqlite-3.40.0/test/lock5.test (revision e339d65a)
1# 2008 June 28
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: lock5.test,v 1.1 2008/06/28 11:23:00 danielk1977 Exp $
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
19# This file is only run if using the unix backend compiled with the
20# SQLITE_ENABLE_LOCKING_STYLE macro.
21db close
22if {[catch {sqlite3 db test.db -vfs unix-none} msg]} {
23puts $msg
24  finish_test
25  return
26}
27db close
28
29do_test lock5-dotfile.1 {
30  sqlite3 db test.db -vfs unix-dotfile
31  execsql {
32    BEGIN;
33    CREATE TABLE t1(a, b);
34  }
35} {}
36
37do_test lock5-dotfile.2 {
38  file exists test.db.lock
39} {1}
40
41do_test lock5-dotfile.3 {
42  execsql COMMIT
43  file exists test.db.lock
44} {0}
45
46do_test lock5-dotfile.4 {
47  sqlite3 db2 test.db -vfs unix-dotfile
48  execsql {
49    INSERT INTO t1 VALUES('a', 'b');
50    SELECT * FROM t1;
51  } db2
52} {a b}
53
54do_test lock5-dotfile.5 {
55  execsql {
56    BEGIN;
57    SELECT * FROM t1;
58  } db2
59} {a b}
60
61do_test lock5-dotfile.6 {
62  file exists test.db.lock
63} {1}
64
65do_test lock5-dotfile.7 {
66  catchsql { SELECT * FROM t1; }
67} {1 {database is locked}}
68
69do_test lock5-dotfile.8 {
70  execsql {
71    SELECT * FROM t1;
72    ROLLBACK;
73  } db2
74} {a b}
75
76do_test lock5-dotfile.9 {
77  catchsql { SELECT * FROM t1; }
78} {0 {a b}}
79
80do_test lock5-dotfile.10 {
81  file exists test.db.lock
82} {0}
83
84do_test lock5-dotfile.X {
85  db2 close
86  execsql {BEGIN EXCLUSIVE}
87  db close
88  file exists test.db.lock
89} {0}
90
91#####################################################################
92
93file delete -force test.db
94
95do_test lock5-flock.1 {
96  sqlite3 db test.db -vfs unix-flock
97  execsql {
98    CREATE TABLE t1(a, b);
99    BEGIN;
100    INSERT INTO t1 VALUES(1, 2);
101  }
102} {}
103
104# Make sure we are not accidentally using the dotfile locking scheme.
105do_test lock5-flock.2 {
106  file exists test.db.lock
107} {0}
108
109do_test lock5-flock.3 {
110  sqlite3 db2 test.db -vfs unix-flock
111  catchsql { SELECT * FROM t1 } db2
112} {1 {database is locked}}
113
114do_test lock5-flock.4 {
115  execsql COMMIT
116  catchsql { SELECT * FROM t1 } db2
117} {0 {1 2}}
118
119do_test lock5-flock.5 {
120  execsql BEGIN
121  catchsql { SELECT * FROM t1 } db2
122} {0 {1 2}}
123
124do_test lock5-flock.6 {
125  execsql {SELECT * FROM t1}
126  catchsql { SELECT * FROM t1 } db2
127} {1 {database is locked}}
128
129do_test lock5-flock.7 {
130  db close
131  catchsql { SELECT * FROM t1 } db2
132} {0 {1 2}}
133
134do_test lock5-flock.8 {
135  db2 close
136} {}
137
138#####################################################################
139
140do_test lock5-none.1 {
141  sqlite3 db test.db -vfs unix-none
142  sqlite3 db2 test.db -vfs unix-none
143  execsql {
144    BEGIN;
145    INSERT INTO t1 VALUES(3, 4);
146  }
147} {}
148do_test lock5-none.2 {
149  execsql { SELECT * FROM t1 }
150} {1 2 3 4}
151do_test lock5-flock.3 {
152  execsql { SELECT * FROM t1 } db2
153} {1 2}
154do_test lock5-none.4 {
155  execsql {
156    BEGIN;
157    SELECT * FROM t1;
158  } db2
159} {1 2}
160do_test lock5-none.5 {
161  execsql COMMIT
162  execsql {SELECT * FROM t1} db2
163} {1 2}
164
165ifcapable memorymanage {
166  do_test lock5-none.6 {
167    sqlite3_release_memory 1000000
168    execsql {SELECT * FROM t1} db2
169  } {1 2 3 4}
170}
171
172do_test lock5-flock.X {
173  db close
174  db2 close
175} {}
176
177finish_test
178
179