summaryrefslogtreecommitdiffstats
path: root/test/async4.test
blob: 92a820173ea281de71e2baecbbb181d46a01a0b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# 2009 April 25
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# $Id: async4.test,v 1.4 2009/06/05 17:09:12 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Do not use a codec for tests in this file, as the database file is
# manipulated directly using tcl scripts (using the [hexio_write] command).
#
do_not_use_codec

# These tests only work for Tcl version 8.5 and later on Windows (for now)
#
if {$tcl_platform(platform)=="windows"} {
  scan $::tcl_version %f vx
  if {$vx<8.5} {
    finish_test
    return
  }
}

if {[info commands sqlite3async_initialize] eq ""} {
  # The async logic is not built into this system
  finish_test
  return
}
db close

# Test layout:
#
#   async4.1.*: Test the lockfiles parameter.
#   async4.2.*: Test the delay parameter.

do_test async4.1.1 {
  sqlite3async_initialize {} 0
  sqlite3async_control lockfiles
} {1}
do_test async4.1.2 {
  sqlite3async_control lockfiles false
} {0}
do_test async4.1.3 {
  sqlite3async_control lockfiles
} {0}
do_test async4.1.4 {
  sqlite3async_control lockfiles true
} {1}

do_test async4.1.5 {
  sqlite3 db test.db -vfs sqlite3async
  execsql { CREATE TABLE t1(a, b, c) }
} {}
do_test async4.1.6 {
  list [file exists test.db] [file size test.db]
} {1 0}
do_test async4.1.7 {
  sqlite3 db2 test.db
  catchsql { CREATE TABLE t2(a, b, c) } db2
} {1 {database is locked}}
do_test async4.1.8 {
  sqlite3async_control halt idle
  sqlite3async_start
  sqlite3async_wait
} {}
do_test async4.1.9 {
  catchsql { CREATE TABLE t2(a, b, c) } db2
} {0 {}}
do_test async4.1.10 {
  list [catch {sqlite3async_control lockfiles false} msg] $msg
} {1 SQLITE_MISUSE}
do_test async4.1.11 {
  db close
  list [catch {sqlite3async_control lockfiles false} msg] $msg
} {1 SQLITE_MISUSE}
do_test async4.1.12 {
  sqlite3async_start
  sqlite3async_wait
  sqlite3async_control lockfiles false
} {0}
do_test async4.1.13 {
  sqlite3 db test.db -vfs sqlite3async
  execsql { CREATE TABLE t3(a, b, c) } db
} {}
do_test async4.1.14 {
  execsql { 
    CREATE INDEX i1 ON t2(a);
    CREATE INDEX i2 ON t1(a);
  } db2
} {}
do_test async4.1.15 {
  sqlite3async_start
  sqlite3async_wait
  hexio_write test.db 28 00000000
  execsql { pragma integrity_check } db2
} {{*** in database main ***
Page 5 is never used}}
do_test async4.1.16 {
  db close
  db2 close
  sqlite3async_start
  sqlite3async_wait
} {}
do_test async4.1.17 {
  sqlite3async_control lockfiles true
} {1}

do_test async4.2.1 {
  sqlite3async_control delay
} {0}
do_test async4.2.2 {
  sqlite3async_control delay 23
} {23}
do_test async4.2.3 {
  sqlite3async_control delay
} {23}
do_test async4.2.4 {
  sqlite3async_control delay 0
} {0}
do_test async4.2.5 {
  sqlite3 db test.db -vfs sqlite3async

  execsql { CREATE TABLE t4(a, b) }
  set T1 [lindex [time {
    sqlite3async_start
    sqlite3async_wait
  }] 0]

  sqlite3async_control delay 100
  execsql { CREATE TABLE t5(a, b) }
  set T2 [lindex [time {
    sqlite3async_start
    sqlite3async_wait
  }] 0]

  expr {($T1+1000000) < $T2}
} {1}

do_test async4.2.6 {
  sqlite3async_control delay 0
  execsql { CREATE TABLE t6(a, b) }
  set T1 [lindex [time {
    sqlite3async_start
    sqlite3async_wait
  }] 0]

  expr {($T1+1000000) < $T2}
} {1}

do_test async4.2.7 {
  list [catch { sqlite3async_control delay -1 } msg] $msg
} {1 SQLITE_MISUSE}

do_test async4.2.8 {
  db close
  sqlite3async_start
  sqlite3async_wait
} {}

finish_test