blob: d08fb66812e71739f977cfdadbc00ab495c55f30 [file] [log] [blame]
danielk1977be29bfc2006-02-14 13:25:43 +00001#
2# May you do good and not evil.
3# May you find forgiveness for yourself and forgive others.
4# May you share freely, never taking more than you give.
5#
6#***********************************************************************
7#
8# $Id: async2.test,v 1.1 2006/02/14 13:25:45 danielk1977 Exp $
9
10
11if {[info commands sqlite3async_enable]==""} {
12 # The async logic is not built into this system
13 return
14}
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
19# Enable asynchronous IO.
20
21set setup_script {
22 CREATE TABLE counter(c);
23 INSERT INTO counter(c) VALUES (1);
24}
25
26set sql_script {
27 BEGIN;
28 UPDATE counter SET c = 2;
29 CREATE TABLE t1(a PRIMARY KEY, b, c);
30 CREATE TABLE t2(a PRIMARY KEY, b, c);
31 COMMIT;
32
33 BEGIN;
34 UPDATE counter SET c = 3;
35 INSERT INTO t1 VALUES('abcdefghij', 'four', 'score');
36 INSERT INTO t2 VALUES('klmnopqrst', 'and', 'seven');
37 COMMIT;
38
39 UPDATE counter SET c = 'FIN';
40}
41
42db close
43
44set ::go 1
45for {set n 3} {$::go} {incr n} {
46 set ::sqlite_io_error_pending 0
47 file delete -force test.db test.db-journal
48 sqlite3 db test.db
49 execsql $::setup_script
50 db close
51
52 sqlite3async_enable 1
53 sqlite3 db test.db
54 execsql $::sql_script
55 db close
56
57 set ::sqlite_io_error_pending $n
58 sqlite3async_halt idle
59 sqlite3async_start
60 sqlite3async_wait
61
62 sqlite3async_enable 0
63 set ::sqlite_io_error_pending 0
64 sqlite3 db test.db
65 set c [db eval {SELECT c FROM counter LIMIT 1}]
66 switch -- $c {
67 1 {
68 do_test async-ioerr-1.1.$n {
69 execsql {
70 SELECT name FROM sqlite_master;
71 }
72 } {counter}
73 }
74 2 {
75 do_test async-ioerr-1.2.$n.1 {
76 execsql {
77 SELECT * FROM t1;
78 }
79 } {}
80 do_test async-ioerr-1.2.$n.2 {
81 execsql {
82 SELECT * FROM t2;
83 }
84 } {}
85 }
86 3 {
87 do_test async-ioerr-1.3.$n.1 {
88 execsql {
89 SELECT * FROM t1;
90 }
91 } {abcdefghij four score}
92 do_test async-ioerr-1.3.$n.2 {
93 execsql {
94 SELECT * FROM t2;
95 }
96 } {klmnopqrst and seven}
97 }
98 FIN {
99 set ::go 0
100 }
101 }
102
103 sqlite3async_enable 0
104}
105
106catch {db close}
107sqlite3async_halt idle
108sqlite3async_start
109sqlite3async_wait
110
111finish_test