xref: /sqlite-3.40.0/test/async2.test (revision df7ca22a)
1#
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.5 2007/08/25 12:39:29 danielk1977 Exp $
9
10
11set testdir [file dirname $argv0]
12source $testdir/tester.tcl
13
14if {
15  [info commands sqlite3async_enable]=="" ||
16  [info command sqlite3_memdebug_fail]==""
17} {
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
24# 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
49
50foreach err [list ioerr malloc] {
51  set ::go 1
52  for {set n 1} {$::go} {incr n} {
53    set ::sqlite_io_error_pending 0
54    sqlite3_memdebug_fail -1 0
55    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 }
67      malloc { sqlite3_memdebug_fail $n 1 }
68    }
69    sqlite3async_halt idle
70    sqlite3async_start
71    sqlite3async_wait
72
73    set ::sqlite_io_error_pending 0
74    sqlite3_memdebug_fail -1 0
75
76    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      }
113    }
114
115    sqlite3async_enable 0
116  }
117}
118
119catch {db close}
120sqlite3async_halt idle
121sqlite3async_start
122sqlite3async_wait
123
124finish_test
125