blob: 2e6e7ce5c8e0d1e8059ce6fcea9bca0afdff67f9 [file] [log] [blame]
danielk19776f050aa2009-04-25 08:39:14 +00001# 2009 April 25
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#
drhdda70fe2009-06-05 17:09:11 +000012# $Id: async4.test,v 1.4 2009/06/05 17:09:12 drh Exp $
danielk19776f050aa2009-04-25 08:39:14 +000013
14set testdir [file dirname $argv0]
15source $testdir/tester.tcl
shane739a2772009-06-01 16:42:17 +000016
17# These tests only work for Tcl version 8.5 and later on Windows (for now)
18#
19if {$tcl_platform(platform)=="windows"} {
20 scan $::tcl_version %f vx
21 if {$vx<8.5} {
22 finish_test
23 return
24 }
25}
26
danielk19776f050aa2009-04-25 08:39:14 +000027if {[info commands sqlite3async_initialize] eq ""} {
28 # The async logic is not built into this system
29 finish_test
30 return
31}
32db close
33
34# Test layout:
35#
36# async4.1.*: Test the lockfiles parameter.
37# async4.2.*: Test the delay parameter.
38
39do_test async4.1.1 {
40 sqlite3async_initialize {} 0
41 sqlite3async_control lockfiles
42} {1}
43do_test async4.1.2 {
44 sqlite3async_control lockfiles false
45} {0}
46do_test async4.1.3 {
47 sqlite3async_control lockfiles
48} {0}
49do_test async4.1.4 {
50 sqlite3async_control lockfiles true
51} {1}
52
53do_test async4.1.5 {
54 sqlite3 db test.db -vfs sqlite3async
55 execsql { CREATE TABLE t1(a, b, c) }
56} {}
57do_test async4.1.6 {
58 list [file exists test.db] [file size test.db]
59} {1 0}
60do_test async4.1.7 {
61 sqlite3 db2 test.db
62 catchsql { CREATE TABLE t2(a, b, c) } db2
63} {1 {database is locked}}
64do_test async4.1.8 {
65 sqlite3async_control halt idle
66 sqlite3async_start
67 sqlite3async_wait
68} {}
69do_test async4.1.9 {
70 catchsql { CREATE TABLE t2(a, b, c) } db2
71} {0 {}}
72do_test async4.1.10 {
73 list [catch {sqlite3async_control lockfiles false} msg] $msg
74} {1 SQLITE_MISUSE}
75do_test async4.1.11 {
76 db close
77 list [catch {sqlite3async_control lockfiles false} msg] $msg
78} {1 SQLITE_MISUSE}
79do_test async4.1.12 {
80 sqlite3async_start
81 sqlite3async_wait
82 sqlite3async_control lockfiles false
83} {0}
84do_test async4.1.13 {
85 sqlite3 db test.db -vfs sqlite3async
86 execsql { CREATE TABLE t3(a, b, c) } db
87} {}
88do_test async4.1.14 {
89 execsql {
90 CREATE INDEX i1 ON t2(a);
91 CREATE INDEX i2 ON t1(a);
92 } db2
93} {}
94do_test async4.1.15 {
95 sqlite3async_start
96 sqlite3async_wait
drhb1299152010-03-30 22:58:33 +000097 hexio_write test.db 28 00000000
danielk19776f050aa2009-04-25 08:39:14 +000098 execsql { pragma integrity_check } db2
99} {{*** in database main ***
100Page 5 is never used}}
101do_test async4.1.16 {
102 db close
103 db2 close
104 sqlite3async_start
105 sqlite3async_wait
106} {}
danielk197774632882009-05-15 14:41:40 +0000107do_test async4.1.17 {
108 sqlite3async_control lockfiles true
109} {1}
danielk19776f050aa2009-04-25 08:39:14 +0000110
111do_test async4.2.1 {
112 sqlite3async_control delay
113} {0}
114do_test async4.2.2 {
115 sqlite3async_control delay 23
116} {23}
117do_test async4.2.3 {
118 sqlite3async_control delay
119} {23}
120do_test async4.2.4 {
121 sqlite3async_control delay 0
122} {0}
123do_test async4.2.5 {
124 sqlite3 db test.db -vfs sqlite3async
125
126 execsql { CREATE TABLE t4(a, b) }
127 set T1 [lindex [time {
128 sqlite3async_start
129 sqlite3async_wait
130 }] 0]
131
132 sqlite3async_control delay 100
133 execsql { CREATE TABLE t5(a, b) }
134 set T2 [lindex [time {
135 sqlite3async_start
136 sqlite3async_wait
137 }] 0]
138
139 expr {($T1+1000000) < $T2}
140} {1}
141
142do_test async4.2.6 {
143 sqlite3async_control delay 0
144 execsql { CREATE TABLE t6(a, b) }
145 set T1 [lindex [time {
146 sqlite3async_start
147 sqlite3async_wait
148 }] 0]
149
150 expr {($T1+1000000) < $T2}
151} {1}
152
153do_test async4.2.7 {
154 list [catch { sqlite3async_control delay -1 } msg] $msg
155} {1 SQLITE_MISUSE}
156
157do_test async4.2.8 {
158 db close
159 sqlite3async_start
160 sqlite3async_wait
161} {}
162
163finish_test