danielk1977 | be29bfc | 2006-02-14 13:25:43 +0000 | [diff] [blame] | 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 | # |
danielk1977 | 6f050aa | 2009-04-25 08:39:14 +0000 | [diff] [blame^] | 8 | # $Id: async2.test,v 1.12 2009/04/25 08:39:15 danielk1977 Exp $ |
danielk1977 | be29bfc | 2006-02-14 13:25:43 +0000 | [diff] [blame] | 9 | |
| 10 | |
danielk1977 | be29bfc | 2006-02-14 13:25:43 +0000 | [diff] [blame] | 11 | set testdir [file dirname $argv0] |
| 12 | source $testdir/tester.tcl |
| 13 | |
danielk1977 | 0e87b70 | 2007-08-25 12:29:30 +0000 | [diff] [blame] | 14 | if { |
danielk1977 | 6f050aa | 2009-04-25 08:39:14 +0000 | [diff] [blame^] | 15 | [info commands sqlite3async_initialize]=="" || |
danielk1977 | df7ca22 | 2007-08-25 12:39:28 +0000 | [diff] [blame] | 16 | [info command sqlite3_memdebug_fail]=="" |
danielk1977 | 0e87b70 | 2007-08-25 12:29:30 +0000 | [diff] [blame] | 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 | |
danielk1977 | be29bfc | 2006-02-14 13:25:43 +0000 | [diff] [blame] | 24 | # Enable asynchronous IO. |
| 25 | |
| 26 | set setup_script { |
| 27 | CREATE TABLE counter(c); |
| 28 | INSERT INTO counter(c) VALUES (1); |
| 29 | } |
| 30 | |
| 31 | set 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 | |
| 47 | db close |
| 48 | |
danielk1977 | eacb6c5 | 2007-08-30 10:49:54 +0000 | [diff] [blame] | 49 | foreach err [list ioerr malloc-transient malloc-persistent] { |
drh | 86d7a31 | 2009-03-24 17:43:56 +0000 | [diff] [blame] | 50 | set ::go 10 |
danielk1977 | 2d9fcaa | 2006-02-14 14:02:08 +0000 | [diff] [blame] | 51 | for {set n 1} {$::go} {incr n} { |
| 52 | set ::sqlite_io_error_pending 0 |
danielk1977 | eacb6c5 | 2007-08-30 10:49:54 +0000 | [diff] [blame] | 53 | sqlite3_memdebug_fail -1 |
danielk1977 | 2d9fcaa | 2006-02-14 14:02:08 +0000 | [diff] [blame] | 54 | file delete -force test.db test.db-journal |
| 55 | sqlite3 db test.db |
| 56 | execsql $::setup_script |
| 57 | db close |
| 58 | |
danielk1977 | 6f050aa | 2009-04-25 08:39:14 +0000 | [diff] [blame^] | 59 | sqlite3async_initialize "" 1 |
danielk1977 | 2d9fcaa | 2006-02-14 14:02:08 +0000 | [diff] [blame] | 60 | sqlite3 db test.db |
drh | 86d7a31 | 2009-03-24 17:43:56 +0000 | [diff] [blame] | 61 | sqlite3_db_config_lookaside db 0 0 0 |
danielk1977 | 2d9fcaa | 2006-02-14 14:02:08 +0000 | [diff] [blame] | 62 | |
| 63 | switch -- $err { |
danielk1977 | eacb6c5 | 2007-08-30 10:49:54 +0000 | [diff] [blame] | 64 | ioerr { set ::sqlite_io_error_pending $n } |
| 65 | malloc-persistent { sqlite3_memdebug_fail $n -repeat 1 } |
| 66 | malloc-transient { sqlite3_memdebug_fail $n -repeat 0 } |
danielk1977 | 2d9fcaa | 2006-02-14 14:02:08 +0000 | [diff] [blame] | 67 | } |
danielk1977 | 7a4252b | 2007-09-05 16:54:41 +0000 | [diff] [blame] | 68 | |
| 69 | catchsql $::sql_script |
| 70 | db close |
| 71 | |
danielk1977 | 6f050aa | 2009-04-25 08:39:14 +0000 | [diff] [blame^] | 72 | sqlite3async_control halt idle |
danielk1977 | 2d9fcaa | 2006-02-14 14:02:08 +0000 | [diff] [blame] | 73 | sqlite3async_start |
| 74 | sqlite3async_wait |
danielk1977 | 6f050aa | 2009-04-25 08:39:14 +0000 | [diff] [blame^] | 75 | sqlite3async_control halt never |
| 76 | sqlite3async_shutdown |
danielk1977 | b6be675 | 2007-09-05 11:34:54 +0000 | [diff] [blame] | 77 | |
danielk1977 | 2d9fcaa | 2006-02-14 14:02:08 +0000 | [diff] [blame] | 78 | set ::sqlite_io_error_pending 0 |
danielk1977 | eacb6c5 | 2007-08-30 10:49:54 +0000 | [diff] [blame] | 79 | sqlite3_memdebug_fail -1 |
danielk1977 | be29bfc | 2006-02-14 13:25:43 +0000 | [diff] [blame] | 80 | |
danielk1977 | 2d9fcaa | 2006-02-14 14:02:08 +0000 | [diff] [blame] | 81 | sqlite3 db test.db |
drh | 86d7a31 | 2009-03-24 17:43:56 +0000 | [diff] [blame] | 82 | set c [db one {SELECT c FROM counter LIMIT 1}] |
danielk1977 | 2d9fcaa | 2006-02-14 14:02:08 +0000 | [diff] [blame] | 83 | switch -- $c { |
| 84 | 1 { |
| 85 | do_test async-$err-1.1.$n { |
| 86 | execsql { |
| 87 | SELECT name FROM sqlite_master; |
| 88 | } |
| 89 | } {counter} |
| 90 | } |
| 91 | 2 { |
| 92 | do_test async-$err-1.2.$n.1 { |
| 93 | execsql { |
| 94 | SELECT * FROM t1; |
| 95 | } |
| 96 | } {} |
| 97 | do_test async-$err-1.2.$n.2 { |
| 98 | execsql { |
| 99 | SELECT * FROM t2; |
| 100 | } |
| 101 | } {} |
| 102 | } |
| 103 | 3 { |
| 104 | do_test async-$err-1.3.$n.1 { |
| 105 | execsql { |
| 106 | SELECT * FROM t1; |
| 107 | } |
| 108 | } {abcdefghij four score} |
| 109 | do_test async-$err-1.3.$n.2 { |
| 110 | execsql { |
| 111 | SELECT * FROM t2; |
| 112 | } |
| 113 | } {klmnopqrst and seven} |
| 114 | } |
| 115 | FIN { |
drh | 86d7a31 | 2009-03-24 17:43:56 +0000 | [diff] [blame] | 116 | incr ::go -1 |
danielk1977 | 2d9fcaa | 2006-02-14 14:02:08 +0000 | [diff] [blame] | 117 | } |
danielk1977 | be29bfc | 2006-02-14 13:25:43 +0000 | [diff] [blame] | 118 | } |
danielk1977 | 2d9fcaa | 2006-02-14 14:02:08 +0000 | [diff] [blame] | 119 | |
danielk1977 | b6be675 | 2007-09-05 11:34:54 +0000 | [diff] [blame] | 120 | db close |
danielk1977 | be29bfc | 2006-02-14 13:25:43 +0000 | [diff] [blame] | 121 | } |
danielk1977 | be29bfc | 2006-02-14 13:25:43 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | catch {db close} |
danielk1977 | be29bfc | 2006-02-14 13:25:43 +0000 | [diff] [blame] | 125 | |
| 126 | finish_test |