blob: 83d3c7f7925a64d4c416db9c49103fc74fc6ea75 [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#
danielk19772d9fcaa2006-02-14 14:02:08 +00008# $Id: async2.test,v 1.3 2006/02/14 14:02:08 danielk1977 Exp $
danielk1977be29bfc2006-02-14 13:25:43 +00009
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
danielk1977be29bfc2006-02-14 13:25:43 +000044
danielk19772d9fcaa2006-02-14 14:02:08 +000045foreach err [list ioerr malloc] {
46 set ::go 1
47 for {set n 1} {$::go} {incr n} {
48 set ::sqlite_io_error_pending 0
49 sqlite_malloc_fail 0
50 file delete -force test.db test.db-journal
51 sqlite3 db test.db
52 execsql $::setup_script
53 db close
54
55 sqlite3async_enable 1
56 sqlite3 db test.db
57 execsql $::sql_script
58 db close
59
60 switch -- $err {
61 ioerr { set ::sqlite_io_error_pending $n }
62 malloc { sqlite_malloc_fail $n }
63 }
64 sqlite3async_halt idle
65 sqlite3async_start
66 sqlite3async_wait
67
68 set ::sqlite_io_error_pending 0
69 sqlite_malloc_fail 0
danielk1977be29bfc2006-02-14 13:25:43 +000070
danielk19772d9fcaa2006-02-14 14:02:08 +000071 sqlite3 db test.db
72 set c [db eval {SELECT c FROM counter LIMIT 1}]
73 switch -- $c {
74 1 {
75 do_test async-$err-1.1.$n {
76 execsql {
77 SELECT name FROM sqlite_master;
78 }
79 } {counter}
80 }
81 2 {
82 do_test async-$err-1.2.$n.1 {
83 execsql {
84 SELECT * FROM t1;
85 }
86 } {}
87 do_test async-$err-1.2.$n.2 {
88 execsql {
89 SELECT * FROM t2;
90 }
91 } {}
92 }
93 3 {
94 do_test async-$err-1.3.$n.1 {
95 execsql {
96 SELECT * FROM t1;
97 }
98 } {abcdefghij four score}
99 do_test async-$err-1.3.$n.2 {
100 execsql {
101 SELECT * FROM t2;
102 }
103 } {klmnopqrst and seven}
104 }
105 FIN {
106 set ::go 0
107 }
danielk1977be29bfc2006-02-14 13:25:43 +0000108 }
danielk19772d9fcaa2006-02-14 14:02:08 +0000109
110 sqlite3async_enable 0
danielk1977be29bfc2006-02-14 13:25:43 +0000111 }
danielk1977be29bfc2006-02-14 13:25:43 +0000112}
113
114catch {db close}
115sqlite3async_halt idle
116sqlite3async_start
117sqlite3async_wait
118
119finish_test