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.6 2007/08/30 10:49:55 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-transient malloc-persistent] { 51 set ::go 1 52 for {set n 1} {$::go} {incr n} { 53 set ::sqlite_io_error_pending 0 54 sqlite3_memdebug_fail -1 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-persistent { sqlite3_memdebug_fail $n -repeat 1 } 68 malloc-transient { sqlite3_memdebug_fail $n -repeat 0 } 69 } 70 sqlite3async_halt idle 71 sqlite3async_start 72 sqlite3async_wait 73 74 set ::sqlite_io_error_pending 0 75 sqlite3_memdebug_fail -1 76 77 sqlite3 db test.db 78 set c [db eval {SELECT c FROM counter LIMIT 1}] 79 switch -- $c { 80 1 { 81 do_test async-$err-1.1.$n { 82 execsql { 83 SELECT name FROM sqlite_master; 84 } 85 } {counter} 86 } 87 2 { 88 do_test async-$err-1.2.$n.1 { 89 execsql { 90 SELECT * FROM t1; 91 } 92 } {} 93 do_test async-$err-1.2.$n.2 { 94 execsql { 95 SELECT * FROM t2; 96 } 97 } {} 98 } 99 3 { 100 do_test async-$err-1.3.$n.1 { 101 execsql { 102 SELECT * FROM t1; 103 } 104 } {abcdefghij four score} 105 do_test async-$err-1.3.$n.2 { 106 execsql { 107 SELECT * FROM t2; 108 } 109 } {klmnopqrst and seven} 110 } 111 FIN { 112 set ::go 0 113 } 114 } 115 116 sqlite3async_enable 0 117 } 118} 119 120catch {db close} 121sqlite3async_halt idle 122sqlite3async_start 123sqlite3async_wait 124 125finish_test 126