OLD | NEW |
| (Empty) |
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.6 2008/12/04 12:34:16 drh Exp $ | |
15 | |
16 set testdir [file dirname $argv0] | |
17 source $testdir/tester.tcl | |
18 | |
19 # This file is only run if using the unix backend compiled with the | |
20 # SQLITE_ENABLE_LOCKING_STYLE macro. | |
21 db close | |
22 if {[catch {sqlite3 db test.db -vfs unix-none} msg]} { | |
23 finish_test | |
24 return | |
25 } | |
26 db close | |
27 forcedelete test.db.lock | |
28 | |
29 ifcapable 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 | |
39 do_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 | |
47 do_test lock5-dotfile.2 { | |
48 file exists test.db.lock | |
49 } {1} | |
50 | |
51 do_test lock5-dotfile.3 { | |
52 execsql COMMIT | |
53 file exists test.db.lock | |
54 } {0} | |
55 | |
56 do_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 | |
64 do_test lock5-dotfile.5 { | |
65 execsql { | |
66 BEGIN; | |
67 SELECT * FROM t1; | |
68 } db2 | |
69 } {a b} | |
70 | |
71 do_test lock5-dotfile.6 { | |
72 file exists test.db.lock | |
73 } {1} | |
74 | |
75 do_test lock5-dotfile.7 { | |
76 catchsql { SELECT * FROM t1; } | |
77 } {1 {database is locked}} | |
78 | |
79 do_test lock5-dotfile.8 { | |
80 execsql { | |
81 SELECT * FROM t1; | |
82 ROLLBACK; | |
83 } db2 | |
84 } {a b} | |
85 | |
86 do_test lock5-dotfile.9 { | |
87 catchsql { SELECT * FROM t1; } | |
88 } {0 {a b}} | |
89 | |
90 do_test lock5-dotfile.10 { | |
91 file exists test.db.lock | |
92 } {0} | |
93 | |
94 do_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 | |
103 forcedelete test.db | |
104 if {[catch {sqlite3 db test.db -vfs unix-flock} msg]} { | |
105 finish_test | |
106 return | |
107 } | |
108 | |
109 do_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. | |
119 do_test lock5-flock.2 { | |
120 file exists test.db.lock | |
121 } {0} | |
122 | |
123 do_test lock5-flock.3 { | |
124 catch { sqlite3 db2 test.db -vfs unix-flock } | |
125 catchsql { SELECT * FROM t1 } db2 | |
126 } {1 {database is locked}} | |
127 | |
128 do_test lock5-flock.4 { | |
129 execsql COMMIT | |
130 catchsql { SELECT * FROM t1 } db2 | |
131 } {0 {1 2}} | |
132 | |
133 do_test lock5-flock.5 { | |
134 execsql BEGIN | |
135 catchsql { SELECT * FROM t1 } db2 | |
136 } {0 {1 2}} | |
137 | |
138 do_test lock5-flock.6 { | |
139 execsql {SELECT * FROM t1} | |
140 catchsql { SELECT * FROM t1 } db2 | |
141 } {1 {database is locked}} | |
142 | |
143 do_test lock5-flock.7 { | |
144 db close | |
145 catchsql { SELECT * FROM t1 } db2 | |
146 } {0 {1 2}} | |
147 | |
148 do_test lock5-flock.8 { | |
149 db2 close | |
150 } {} | |
151 | |
152 ##################################################################### | |
153 | |
154 do_test lock5-none.1 { | |
155 sqlite3 db test.db -vfs unix-none | |
156 sqlite3 db2 test.db -vfs unix-none | |
157 execsql { PRAGMA mmap_size = 0 } db2 | |
158 execsql { | |
159 BEGIN; | |
160 INSERT INTO t1 VALUES(3, 4); | |
161 } | |
162 } {} | |
163 do_test lock5-none.2 { | |
164 execsql { SELECT * FROM t1 } | |
165 } {1 2 3 4} | |
166 do_test lock5-none.3 { | |
167 execsql { SELECT * FROM t1; } db2 | |
168 } {1 2} | |
169 do_test lock5-none.4 { | |
170 execsql { | |
171 BEGIN; | |
172 SELECT * FROM t1; | |
173 } db2 | |
174 } {1 2} | |
175 do_test lock5-none.5 { | |
176 execsql COMMIT | |
177 execsql {SELECT * FROM t1} db2 | |
178 } {1 2} | |
179 | |
180 ifcapable 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 | |
187 do_test lock5-none.X { | |
188 db close | |
189 db2 close | |
190 } {} | |
191 | |
192 ifcapable lock_proxy_pragmas { | |
193 set env(SQLITE_FORCE_PROXY_LOCKING) $::using_proxy | |
194 } | |
195 | |
196 finish_test | |
OLD | NEW |