blob: bd69913b9fe29fa7b0094398cf8fd5da7b429ad3 [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#
danielk1977df7ca222007-08-25 12:39:28 +00008# $Id: async2.test,v 1.5 2007/08/25 12:39:29 danielk1977 Exp $
danielk1977be29bfc2006-02-14 13:25:43 +00009
10
danielk1977be29bfc2006-02-14 13:25:43 +000011set testdir [file dirname $argv0]
12source $testdir/tester.tcl
13
danielk19770e87b702007-08-25 12:29:30 +000014if {
15 [info commands sqlite3async_enable]=="" ||
danielk1977df7ca222007-08-25 12:39:28 +000016 [info command sqlite3_memdebug_fail]==""
danielk19770e87b702007-08-25 12:29:30 +000017} {
18 # The async logic is not built into this system
19 puts "Skipping async2 tests: not compiled with required features"
20 finish_test
21 return
22}
23
danielk1977be29bfc2006-02-14 13:25:43 +000024# Enable asynchronous IO.
25
26set setup_script {
27 CREATE TABLE counter(c);
28 INSERT INTO counter(c) VALUES (1);
29}
30
31set sql_script {
32 BEGIN;
33 UPDATE counter SET c = 2;
34 CREATE TABLE t1(a PRIMARY KEY, b, c);
35 CREATE TABLE t2(a PRIMARY KEY, b, c);
36 COMMIT;
37
38 BEGIN;
39 UPDATE counter SET c = 3;
40 INSERT INTO t1 VALUES('abcdefghij', 'four', 'score');
41 INSERT INTO t2 VALUES('klmnopqrst', 'and', 'seven');
42 COMMIT;
43
44 UPDATE counter SET c = 'FIN';
45}
46
47db close
48
danielk1977be29bfc2006-02-14 13:25:43 +000049
danielk19772d9fcaa2006-02-14 14:02:08 +000050foreach err [list ioerr malloc] {
51 set ::go 1
52 for {set n 1} {$::go} {incr n} {
53 set ::sqlite_io_error_pending 0
danielk1977df7ca222007-08-25 12:39:28 +000054 sqlite3_memdebug_fail -1 0
danielk19772d9fcaa2006-02-14 14:02:08 +000055 file delete -force test.db test.db-journal
56 sqlite3 db test.db
57 execsql $::setup_script
58 db close
59
60 sqlite3async_enable 1
61 sqlite3 db test.db
62 execsql $::sql_script
63 db close
64
65 switch -- $err {
66 ioerr { set ::sqlite_io_error_pending $n }
danielk1977df7ca222007-08-25 12:39:28 +000067 malloc { sqlite3_memdebug_fail $n 1 }
danielk19772d9fcaa2006-02-14 14:02:08 +000068 }
69 sqlite3async_halt idle
70 sqlite3async_start
71 sqlite3async_wait
72
73 set ::sqlite_io_error_pending 0
danielk1977df7ca222007-08-25 12:39:28 +000074 sqlite3_memdebug_fail -1 0
danielk1977be29bfc2006-02-14 13:25:43 +000075
danielk19772d9fcaa2006-02-14 14:02:08 +000076 sqlite3 db test.db
77 set c [db eval {SELECT c FROM counter LIMIT 1}]
78 switch -- $c {
79 1 {
80 do_test async-$err-1.1.$n {
81 execsql {
82 SELECT name FROM sqlite_master;
83 }
84 } {counter}
85 }
86 2 {
87 do_test async-$err-1.2.$n.1 {
88 execsql {
89 SELECT * FROM t1;
90 }
91 } {}
92 do_test async-$err-1.2.$n.2 {
93 execsql {
94 SELECT * FROM t2;
95 }
96 } {}
97 }
98 3 {
99 do_test async-$err-1.3.$n.1 {
100 execsql {
101 SELECT * FROM t1;
102 }
103 } {abcdefghij four score}
104 do_test async-$err-1.3.$n.2 {
105 execsql {
106 SELECT * FROM t2;
107 }
108 } {klmnopqrst and seven}
109 }
110 FIN {
111 set ::go 0
112 }
danielk1977be29bfc2006-02-14 13:25:43 +0000113 }
danielk19772d9fcaa2006-02-14 14:02:08 +0000114
115 sqlite3async_enable 0
danielk1977be29bfc2006-02-14 13:25:43 +0000116 }
danielk1977be29bfc2006-02-14 13:25:43 +0000117}
118
119catch {db close}
120sqlite3async_halt idle
121sqlite3async_start
122sqlite3async_wait
123
124finish_test