blob: 584a4af1bad56aa2c7d798c39b11ef1868178982 [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
97 execsql { pragma integrity_check } db2
98} {{*** in database main ***
99Page 5 is never used}}
100do_test async4.1.16 {
101 db close
102 db2 close
103 sqlite3async_start
104 sqlite3async_wait
105} {}
danielk197774632882009-05-15 14:41:40 +0000106do_test async4.1.17 {
107 sqlite3async_control lockfiles true
108} {1}
danielk19776f050aa2009-04-25 08:39:14 +0000109
110do_test async4.2.1 {
111 sqlite3async_control delay
112} {0}
113do_test async4.2.2 {
114 sqlite3async_control delay 23
115} {23}
116do_test async4.2.3 {
117 sqlite3async_control delay
118} {23}
119do_test async4.2.4 {
120 sqlite3async_control delay 0
121} {0}
122do_test async4.2.5 {
123 sqlite3 db test.db -vfs sqlite3async
124
125 execsql { CREATE TABLE t4(a, b) }
126 set T1 [lindex [time {
127 sqlite3async_start
128 sqlite3async_wait
129 }] 0]
130
131 sqlite3async_control delay 100
132 execsql { CREATE TABLE t5(a, b) }
133 set T2 [lindex [time {
134 sqlite3async_start
135 sqlite3async_wait
136 }] 0]
137
138 expr {($T1+1000000) < $T2}
139} {1}
140
141do_test async4.2.6 {
142 sqlite3async_control delay 0
143 execsql { CREATE TABLE t6(a, b) }
144 set T1 [lindex [time {
145 sqlite3async_start
146 sqlite3async_wait
147 }] 0]
148
149 expr {($T1+1000000) < $T2}
150} {1}
151
152do_test async4.2.7 {
153 list [catch { sqlite3async_control delay -1 } msg] $msg
154} {1 SQLITE_MISUSE}
155
156do_test async4.2.8 {
157 db close
158 sqlite3async_start
159 sqlite3async_wait
160} {}
161
162finish_test