blob: 99214afb19b487c9c1fe3086d7f38d02c4f6cc8a [file] [log] [blame]
danielk1977e339d652008-06-28 11:23:00 +00001# 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#
drh947bd802008-12-04 12:34:15 +000014# $Id: lock5.test,v 1.6 2008/12/04 12:34:16 drh Exp $
danielk1977e339d652008-06-28 11:23:00 +000015
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]} {
danielk1977e339d652008-06-28 11:23:00 +000023 finish_test
24 return
25}
26db close
mistachkinfda06be2011-08-02 00:57:34 +000027forcedelete test.db.lock
danielk1977e339d652008-06-28 11:23:00 +000028
aswiftaebf4132008-11-21 00:10:35 +000029ifcapable lock_proxy_pragmas {
30 set ::using_proxy 0
31 foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
32 set ::using_proxy $value
33 }
34 # Disable the proxy locking for these tests
35 set env(SQLITE_FORCE_PROXY_LOCKING) "0"
36}
37
38
danielk1977e339d652008-06-28 11:23:00 +000039do_test lock5-dotfile.1 {
40 sqlite3 db test.db -vfs unix-dotfile
41 execsql {
42 BEGIN;
43 CREATE TABLE t1(a, b);
44 }
45} {}
46
47do_test lock5-dotfile.2 {
48 file exists test.db.lock
49} {1}
50
51do_test lock5-dotfile.3 {
52 execsql COMMIT
53 file exists test.db.lock
54} {0}
55
56do_test lock5-dotfile.4 {
57 sqlite3 db2 test.db -vfs unix-dotfile
58 execsql {
59 INSERT INTO t1 VALUES('a', 'b');
60 SELECT * FROM t1;
61 } db2
62} {a b}
63
64do_test lock5-dotfile.5 {
65 execsql {
66 BEGIN;
67 SELECT * FROM t1;
68 } db2
69} {a b}
70
71do_test lock5-dotfile.6 {
72 file exists test.db.lock
73} {1}
74
75do_test lock5-dotfile.7 {
76 catchsql { SELECT * FROM t1; }
77} {1 {database is locked}}
78
79do_test lock5-dotfile.8 {
80 execsql {
81 SELECT * FROM t1;
82 ROLLBACK;
83 } db2
84} {a b}
85
86do_test lock5-dotfile.9 {
87 catchsql { SELECT * FROM t1; }
88} {0 {a b}}
89
90do_test lock5-dotfile.10 {
91 file exists test.db.lock
92} {0}
93
94do_test lock5-dotfile.X {
95 db2 close
96 execsql {BEGIN EXCLUSIVE}
97 db close
98 file exists test.db.lock
99} {0}
100
101#####################################################################
102
mistachkinfda06be2011-08-02 00:57:34 +0000103forcedelete test.db
drh947bd802008-12-04 12:34:15 +0000104if {[catch {sqlite3 db test.db -vfs unix-flock} msg]} {
105 finish_test
106 return
107}
danielk1977e339d652008-06-28 11:23:00 +0000108
109do_test lock5-flock.1 {
110 sqlite3 db test.db -vfs unix-flock
111 execsql {
112 CREATE TABLE t1(a, b);
113 BEGIN;
114 INSERT INTO t1 VALUES(1, 2);
115 }
116} {}
117
118# Make sure we are not accidentally using the dotfile locking scheme.
119do_test lock5-flock.2 {
120 file exists test.db.lock
121} {0}
122
123do_test lock5-flock.3 {
danf0ab1f12010-07-08 14:59:01 +0000124 catch { sqlite3 db2 test.db -vfs unix-flock }
danielk1977e339d652008-06-28 11:23:00 +0000125 catchsql { SELECT * FROM t1 } db2
126} {1 {database is locked}}
127
128do_test lock5-flock.4 {
129 execsql COMMIT
130 catchsql { SELECT * FROM t1 } db2
131} {0 {1 2}}
132
133do_test lock5-flock.5 {
134 execsql BEGIN
135 catchsql { SELECT * FROM t1 } db2
136} {0 {1 2}}
137
138do_test lock5-flock.6 {
139 execsql {SELECT * FROM t1}
140 catchsql { SELECT * FROM t1 } db2
141} {1 {database is locked}}
142
143do_test lock5-flock.7 {
144 db close
145 catchsql { SELECT * FROM t1 } db2
146} {0 {1 2}}
147
148do_test lock5-flock.8 {
149 db2 close
150} {}
151
152#####################################################################
153
154do_test lock5-none.1 {
155 sqlite3 db test.db -vfs unix-none
156 sqlite3 db2 test.db -vfs unix-none
danf4165242014-10-15 14:45:34 +0000157 execsql { PRAGMA mmap_size = 0 } db2
danielk1977e339d652008-06-28 11:23:00 +0000158 execsql {
159 BEGIN;
160 INSERT INTO t1 VALUES(3, 4);
161 }
162} {}
163do_test lock5-none.2 {
164 execsql { SELECT * FROM t1 }
165} {1 2 3 4}
danf4165242014-10-15 14:45:34 +0000166do_test lock5-none.3 {
167 execsql { SELECT * FROM t1; } db2
danielk1977e339d652008-06-28 11:23:00 +0000168} {1 2}
169do_test lock5-none.4 {
170 execsql {
171 BEGIN;
172 SELECT * FROM t1;
173 } db2
174} {1 2}
175do_test lock5-none.5 {
176 execsql COMMIT
177 execsql {SELECT * FROM t1} db2
178} {1 2}
179
180ifcapable memorymanage {
181 do_test lock5-none.6 {
182 sqlite3_release_memory 1000000
183 execsql {SELECT * FROM t1} db2
184 } {1 2 3 4}
185}
186
danf4165242014-10-15 14:45:34 +0000187do_test lock5-none.X {
danielk1977e339d652008-06-28 11:23:00 +0000188 db close
189 db2 close
190} {}
191
aswiftaebf4132008-11-21 00:10:35 +0000192ifcapable lock_proxy_pragmas {
193 set env(SQLITE_FORCE_PROXY_LOCKING) $::using_proxy
194}
195
danielk1977e339d652008-06-28 11:23:00 +0000196finish_test