blob: 3403ea44c03f114a41bf78f21a78fb0fac8fcf44 [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#
danielk1977b6be6752007-09-05 11:34:54 +00008# $Id: async2.test,v 1.7 2007/09/05 11:34:54 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
danielk1977eacb6c52007-08-30 10:49:54 +000050foreach err [list ioerr malloc-transient malloc-persistent] {
danielk19772d9fcaa2006-02-14 14:02:08 +000051 set ::go 1
52 for {set n 1} {$::go} {incr n} {
53 set ::sqlite_io_error_pending 0
danielk1977eacb6c52007-08-30 10:49:54 +000054 sqlite3_memdebug_fail -1
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 {
danielk1977eacb6c52007-08-30 10:49:54 +000066 ioerr { set ::sqlite_io_error_pending $n }
67 malloc-persistent { sqlite3_memdebug_fail $n -repeat 1 }
68 malloc-transient { sqlite3_memdebug_fail $n -repeat 0 }
danielk19772d9fcaa2006-02-14 14:02:08 +000069 }
70 sqlite3async_halt idle
71 sqlite3async_start
72 sqlite3async_wait
danielk1977b6be6752007-09-05 11:34:54 +000073 sqlite3async_enable 0
74
danielk19772d9fcaa2006-02-14 14:02:08 +000075 set ::sqlite_io_error_pending 0
danielk1977eacb6c52007-08-30 10:49:54 +000076 sqlite3_memdebug_fail -1
danielk1977be29bfc2006-02-14 13:25:43 +000077
danielk19772d9fcaa2006-02-14 14:02:08 +000078 sqlite3 db test.db
79 set c [db eval {SELECT c FROM counter LIMIT 1}]
80 switch -- $c {
81 1 {
82 do_test async-$err-1.1.$n {
83 execsql {
84 SELECT name FROM sqlite_master;
85 }
86 } {counter}
87 }
88 2 {
89 do_test async-$err-1.2.$n.1 {
90 execsql {
91 SELECT * FROM t1;
92 }
93 } {}
94 do_test async-$err-1.2.$n.2 {
95 execsql {
96 SELECT * FROM t2;
97 }
98 } {}
99 }
100 3 {
101 do_test async-$err-1.3.$n.1 {
102 execsql {
103 SELECT * FROM t1;
104 }
105 } {abcdefghij four score}
106 do_test async-$err-1.3.$n.2 {
107 execsql {
108 SELECT * FROM t2;
109 }
110 } {klmnopqrst and seven}
111 }
112 FIN {
113 set ::go 0
114 }
danielk1977be29bfc2006-02-14 13:25:43 +0000115 }
danielk19772d9fcaa2006-02-14 14:02:08 +0000116
danielk1977b6be6752007-09-05 11:34:54 +0000117 db close
danielk1977be29bfc2006-02-14 13:25:43 +0000118 }
danielk1977be29bfc2006-02-14 13:25:43 +0000119}
120
121catch {db close}
122sqlite3async_halt idle
123sqlite3async_start
124sqlite3async_wait
125
126finish_test