2006-02-14 13:25:43 +00:00
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
2009-04-25 08:39:14 +00:00
# $Id: async2.test,v 1.12 2009/04/25 08:39:15 danielk1977 Exp $
2006-02-14 13:25:43 +00:00
2007-08-25 12:29:30 +00:00
set testdir [file dirname $argv0]
source $testdir/tester.tcl
if {
2009-04-25 08:39:14 +00:00
[info commands sqlite3async_initialize]=="" ||
2007-08-25 12:39:28 +00:00
[info command sqlite3_memdebug_fail]==""
2007-08-25 12:29:30 +00:00
} {
2006-02-14 13:25:43 +00:00
# The async logic is not built into this system
2007-08-25 12:29:30 +00:00
puts "Skipping async2 tests: not compiled with required features"
finish_test
2006-02-14 13:25:43 +00:00
return
}
# Enable asynchronous IO.
set setup_script {
CREATE TABLE counter(c);
INSERT INTO counter(c) VALUES (1);
}
set sql_script {
BEGIN;
UPDATE counter SET c = 2;
CREATE TABLE t1(a PRIMARY KEY, b, c);
CREATE TABLE t2(a PRIMARY KEY, b, c);
COMMIT;
BEGIN;
UPDATE counter SET c = 3;
INSERT INTO t1 VALUES('abcdefghij', 'four', 'score');
INSERT INTO t2 VALUES('klmnopqrst', 'and', 'seven');
COMMIT;
UPDATE counter SET c = 'FIN';
}
db close
2007-08-30 10:49:54 +00:00
foreach err [list ioerr malloc-transient malloc-persistent] {
2009-03-24 17:43:56 +00:00
set ::go 10
2006-02-14 14:02:08 +00:00
for {set n 1} {$::go} {incr n} {
set ::sqlite_io_error_pending 0
2007-08-30 10:49:54 +00:00
sqlite3_memdebug_fail -1
2011-08-02 00:57:34 +00:00
forcedelete test.db test.db-journal
2006-02-14 14:02:08 +00:00
sqlite3 db test.db
execsql $::setup_script
db close
2009-04-25 08:39:14 +00:00
sqlite3async_initialize "" 1
2006-02-14 14:02:08 +00:00
sqlite3 db test.db
2009-03-24 17:43:56 +00:00
sqlite3_db_config_lookaside db 0 0 0
2006-02-14 14:02:08 +00:00
switch -- $err {
2007-08-30 10:49:54 +00:00
ioerr { set ::sqlite_io_error_pending $n }
malloc-persistent { sqlite3_memdebug_fail $n -repeat 1 }
malloc-transient { sqlite3_memdebug_fail $n -repeat 0 }
2006-02-14 13:25:43 +00:00
}
2007-09-05 16:54:41 +00:00
catchsql $::sql_script
db close
2009-04-25 08:39:14 +00:00
sqlite3async_control halt idle
2006-02-14 14:02:08 +00:00
sqlite3async_start
sqlite3async_wait
2009-04-25 08:39:14 +00:00
sqlite3async_control halt never
sqlite3async_shutdown
2007-09-05 11:34:54 +00:00
2006-02-14 14:02:08 +00:00
set ::sqlite_io_error_pending 0
2007-08-30 10:49:54 +00:00
sqlite3_memdebug_fail -1
2006-02-14 14:02:08 +00:00
sqlite3 db test.db
2009-03-24 17:43:56 +00:00
set c [db one {SELECT c FROM counter LIMIT 1}]
2006-02-14 14:02:08 +00:00
switch -- $c {
1 {
do_test async-$err-1.1.$n {
execsql {
SELECT name FROM sqlite_master;
}
} {counter}
}
2 {
do_test async-$err-1.2.$n.1 {
execsql {
SELECT * FROM t1;
}
} {}
do_test async-$err-1.2.$n.2 {
execsql {
SELECT * FROM t2;
}
} {}
}
3 {
do_test async-$err-1.3.$n.1 {
execsql {
SELECT * FROM t1;
}
} {abcdefghij four score}
do_test async-$err-1.3.$n.2 {
execsql {
SELECT * FROM t2;
}
} {klmnopqrst and seven}
}
FIN {
2009-03-24 17:43:56 +00:00
incr ::go -1
2006-02-14 14:02:08 +00:00
}
2006-02-14 13:25:43 +00:00
}
2006-02-14 14:02:08 +00:00
2007-09-05 11:34:54 +00:00
db close
2006-02-14 13:25:43 +00:00
}
}
catch {db close}
finish_test