sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # sl@0: # $Id: async2.test,v 1.9 2007/11/05 17:01:08 danielk1977 Exp $ sl@0: sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: if { sl@0: [info commands sqlite3async_enable]=="" || sl@0: [info command sqlite3_memdebug_fail]=="" sl@0: } { sl@0: # The async logic is not built into this system sl@0: puts "Skipping async2 tests: not compiled with required features" sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: # Enable asynchronous IO. sl@0: sl@0: set setup_script { sl@0: CREATE TABLE counter(c); sl@0: INSERT INTO counter(c) VALUES (1); sl@0: } sl@0: sl@0: set sql_script { sl@0: BEGIN; sl@0: UPDATE counter SET c = 2; sl@0: CREATE TABLE t1(a PRIMARY KEY, b, c); sl@0: CREATE TABLE t2(a PRIMARY KEY, b, c); sl@0: COMMIT; sl@0: sl@0: BEGIN; sl@0: UPDATE counter SET c = 3; sl@0: INSERT INTO t1 VALUES('abcdefghij', 'four', 'score'); sl@0: INSERT INTO t2 VALUES('klmnopqrst', 'and', 'seven'); sl@0: COMMIT; sl@0: sl@0: UPDATE counter SET c = 'FIN'; sl@0: } sl@0: sl@0: db close sl@0: sl@0: foreach err [list ioerr malloc-transient malloc-persistent] { sl@0: set ::go 1 sl@0: for {set n 1} {$::go} {incr n} { sl@0: set ::sqlite_io_error_pending 0 sl@0: sqlite3_memdebug_fail -1 sl@0: file delete -force test.db test.db-journal sl@0: sqlite3 db test.db sl@0: execsql $::setup_script sl@0: db close sl@0: sl@0: sqlite3async_enable 1 sl@0: sqlite3 db test.db sl@0: sl@0: switch -- $err { sl@0: ioerr { set ::sqlite_io_error_pending $n } sl@0: malloc-persistent { sqlite3_memdebug_fail $n -repeat 1 } sl@0: malloc-transient { sqlite3_memdebug_fail $n -repeat 0 } sl@0: } sl@0: sl@0: catchsql $::sql_script sl@0: db close sl@0: sl@0: sqlite3async_halt idle sl@0: sqlite3async_start sl@0: sqlite3async_wait sl@0: sqlite3async_halt never sl@0: sqlite3async_enable 0 sl@0: sl@0: set ::sqlite_io_error_pending 0 sl@0: sqlite3_memdebug_fail -1 sl@0: sl@0: sqlite3 db test.db sl@0: set c [db eval {SELECT c FROM counter LIMIT 1}] sl@0: switch -- $c { sl@0: 1 { sl@0: do_test async-$err-1.1.$n { sl@0: execsql { sl@0: SELECT name FROM sqlite_master; sl@0: } sl@0: } {counter} sl@0: } sl@0: 2 { sl@0: do_test async-$err-1.2.$n.1 { sl@0: execsql { sl@0: SELECT * FROM t1; sl@0: } sl@0: } {} sl@0: do_test async-$err-1.2.$n.2 { sl@0: execsql { sl@0: SELECT * FROM t2; sl@0: } sl@0: } {} sl@0: } sl@0: 3 { sl@0: do_test async-$err-1.3.$n.1 { sl@0: execsql { sl@0: SELECT * FROM t1; sl@0: } sl@0: } {abcdefghij four score} sl@0: do_test async-$err-1.3.$n.2 { sl@0: execsql { sl@0: SELECT * FROM t2; sl@0: } sl@0: } {klmnopqrst and seven} sl@0: } sl@0: FIN { sl@0: set ::go 0 sl@0: } sl@0: } sl@0: sl@0: db close sl@0: } sl@0: } sl@0: sl@0: catch {db close} sl@0: sqlite3async_halt idle sl@0: sqlite3async_start sl@0: sqlite3async_wait sl@0: sqlite3async_halt never sl@0: sl@0: finish_test