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