xref: /sqlite-3.40.0/test/async4.test (revision 6f050aa2)
1# 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#
12# $Id: async4.test,v 1.1 2009/04/25 08:39:15 danielk1977 Exp $
13
14set testdir [file dirname $argv0]
15source $testdir/tester.tcl
16if {[info commands sqlite3async_initialize] eq ""} {
17  # The async logic is not built into this system
18  finish_test
19  return
20}
21db close
22
23# Test layout:
24#
25#   async4.1.*: Test the lockfiles parameter.
26#   async4.2.*: Test the delay parameter.
27
28do_test async4.1.1 {
29  sqlite3async_initialize {} 0
30  sqlite3async_control lockfiles
31} {1}
32do_test async4.1.2 {
33  sqlite3async_control lockfiles false
34} {0}
35do_test async4.1.3 {
36  sqlite3async_control lockfiles
37} {0}
38do_test async4.1.4 {
39  sqlite3async_control lockfiles true
40} {1}
41
42do_test async4.1.5 {
43  sqlite3 db test.db -vfs sqlite3async
44  execsql { CREATE TABLE t1(a, b, c) }
45} {}
46do_test async4.1.6 {
47  list [file exists test.db] [file size test.db]
48} {1 0}
49do_test async4.1.7 {
50  sqlite3 db2 test.db
51  catchsql { CREATE TABLE t2(a, b, c) } db2
52} {1 {database is locked}}
53do_test async4.1.8 {
54  sqlite3async_control halt idle
55  sqlite3async_start
56  sqlite3async_wait
57} {}
58do_test async4.1.9 {
59  catchsql { CREATE TABLE t2(a, b, c) } db2
60} {0 {}}
61do_test async4.1.10 {
62  list [catch {sqlite3async_control lockfiles false} msg] $msg
63} {1 SQLITE_MISUSE}
64do_test async4.1.11 {
65  db close
66  list [catch {sqlite3async_control lockfiles false} msg] $msg
67} {1 SQLITE_MISUSE}
68do_test async4.1.12 {
69  sqlite3async_start
70  sqlite3async_wait
71  sqlite3async_control lockfiles false
72} {0}
73do_test async4.1.13 {
74  sqlite3 db test.db -vfs sqlite3async
75  execsql { CREATE TABLE t3(a, b, c) } db
76} {}
77do_test async4.1.14 {
78  execsql {
79    CREATE INDEX i1 ON t2(a);
80    CREATE INDEX i2 ON t1(a);
81  } db2
82} {}
83do_test async4.1.15 {
84  sqlite3async_start
85  sqlite3async_wait
86  execsql { pragma integrity_check } db2
87} {{*** in database main ***
88Page 5 is never used}}
89do_test async4.1.16 {
90  db close
91  db2 close
92  sqlite3async_start
93  sqlite3async_wait
94} {}
95
96do_test async4.2.1 {
97  sqlite3async_control delay
98} {0}
99do_test async4.2.2 {
100  sqlite3async_control delay 23
101} {23}
102do_test async4.2.3 {
103  sqlite3async_control delay
104} {23}
105do_test async4.2.4 {
106  sqlite3async_control delay 0
107} {0}
108do_test async4.2.5 {
109  sqlite3 db test.db -vfs sqlite3async
110
111  execsql { CREATE TABLE t4(a, b) }
112  set T1 [lindex [time {
113    sqlite3async_start
114    sqlite3async_wait
115  }] 0]
116
117  sqlite3async_control delay 100
118  execsql { CREATE TABLE t5(a, b) }
119  set T2 [lindex [time {
120    sqlite3async_start
121    sqlite3async_wait
122  }] 0]
123
124  expr {($T1+1000000) < $T2}
125} {1}
126
127do_test async4.2.6 {
128  sqlite3async_control delay 0
129  execsql { CREATE TABLE t6(a, b) }
130  set T1 [lindex [time {
131    sqlite3async_start
132    sqlite3async_wait
133  }] 0]
134
135  expr {($T1+1000000) < $T2}
136} {1}
137
138do_test async4.2.7 {
139  list [catch { sqlite3async_control delay -1 } msg] $msg
140} {1 SQLITE_MISUSE}
141
142do_test async4.2.8 {
143  db close
144  sqlite3async_start
145  sqlite3async_wait
146} {}
147
148finish_test
149
150