danielk1977 | 07cb560 | 2006-01-20 10:55:05 +0000 | [diff] [blame^] | 1 | # 2005 December 30 |
| 2 | # |
| 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
| 5 | # |
| 6 | # May you do good and not evil. |
| 7 | # May you find forgiveness for yourself and forgive others. |
| 8 | # May you share freely, never taking more than you give. |
| 9 | # |
| 10 | #*********************************************************************** |
| 11 | # |
| 12 | # The focus of the tests in this file are IO errors that occur in a shared |
| 13 | # cache context. What happens to connection B if one connection A encounters |
| 14 | # an IO-error whilst reading or writing the file-system? |
| 15 | # |
| 16 | # $Id: shared_err.test,v 1.1 2006/01/20 10:55:05 danielk1977 Exp $ |
| 17 | |
| 18 | proc skip {args} {} |
| 19 | |
| 20 | |
| 21 | set testdir [file dirname $argv0] |
| 22 | source $testdir/tester.tcl |
| 23 | db close |
| 24 | |
| 25 | ifcapable !shared_cache||!subquery { |
| 26 | finish_test |
| 27 | return |
| 28 | } |
| 29 | set ::enable_shared_cache [sqlite3_enable_shared_cache 1] |
| 30 | |
| 31 | skip \ |
| 32 | do_ioerr_test shared_ioerr-1 -tclprep { |
| 33 | sqlite3 db2 test.db |
| 34 | execsql { |
| 35 | PRAGMA read_uncommitted = 1; |
| 36 | CREATE TABLE t1(a,b,c); |
| 37 | BEGIN; |
| 38 | SELECT * FROM sqlite_master; |
| 39 | } db2 |
| 40 | } -sqlbody { |
| 41 | SELECT * FROM sqlite_master; |
| 42 | INSERT INTO t1 VALUES(1,2,3); |
| 43 | BEGIN TRANSACTION; |
| 44 | INSERT INTO t1 VALUES(1,2,3); |
| 45 | INSERT INTO t1 VALUES(4,5,6); |
| 46 | ROLLBACK; |
| 47 | SELECT * FROM t1; |
| 48 | BEGIN TRANSACTION; |
| 49 | INSERT INTO t1 VALUES(1,2,3); |
| 50 | INSERT INTO t1 VALUES(4,5,6); |
| 51 | COMMIT; |
| 52 | SELECT * FROM t1; |
| 53 | DELETE FROM t1 WHERE a<100; |
| 54 | } -cleanup { |
| 55 | do_test shared_ioerr-$n.cleanup.1 { |
| 56 | set res [catchsql { |
| 57 | SELECT * FROM t1; |
| 58 | } db2] |
| 59 | set possible_results [list \ |
| 60 | "1 {disk I/O error}" \ |
| 61 | "0 {1 2 3}" \ |
| 62 | "0 {1 2 3 1 2 3 4 5 6}" \ |
| 63 | "0 {1 2 3 1 2 3 4 5 6 1 2 3 4 5 6}" \ |
| 64 | "0 {}" \ |
| 65 | ] |
| 66 | set rc [expr [lsearch -exact $possible_results $res] >= 0] |
| 67 | if {$rc != 1} { |
| 68 | puts "" |
| 69 | puts "Result: $res" |
| 70 | } |
| 71 | set rc |
| 72 | } {1} |
| 73 | db2 close |
| 74 | } |
| 75 | |
| 76 | do_ioerr_test shared_ioerr-2 -tclprep { |
| 77 | sqlite3 db2 test.db |
| 78 | execsql { |
| 79 | PRAGMA read_uncommitted = 1; |
| 80 | BEGIN; |
| 81 | CREATE TABLE t1(a, b); |
| 82 | INSERT INTO t1(oid) VALUES(NULL); |
| 83 | INSERT INTO t1(oid) SELECT NULL FROM t1; |
| 84 | INSERT INTO t1(oid) SELECT NULL FROM t1; |
| 85 | INSERT INTO t1(oid) SELECT NULL FROM t1; |
| 86 | INSERT INTO t1(oid) SELECT NULL FROM t1; |
| 87 | INSERT INTO t1(oid) SELECT NULL FROM t1; |
| 88 | INSERT INTO t1(oid) SELECT NULL FROM t1; |
| 89 | INSERT INTO t1(oid) SELECT NULL FROM t1; |
| 90 | INSERT INTO t1(oid) SELECT NULL FROM t1; |
| 91 | INSERT INTO t1(oid) SELECT NULL FROM t1; |
| 92 | INSERT INTO t1(oid) SELECT NULL FROM t1; |
| 93 | UPDATE t1 set a = oid, b = 'abcdefghijklmnopqrstuvwxyz0123456789'; |
| 94 | CREATE INDEX i1 ON t1(a); |
| 95 | COMMIT; |
| 96 | BEGIN; |
| 97 | SELECT * FROM sqlite_master; |
| 98 | } db2 |
| 99 | } -tclbody { |
| 100 | set ::residx 0 |
| 101 | execsql {DELETE FROM t1 WHERE 0 = (a % 2);} |
| 102 | incr ::residx |
| 103 | |
| 104 | # When this transaction begins the table contains 512 entries. The |
| 105 | # two statements together add 512+146 more if it succeeds. |
| 106 | # (1024/7==146) |
| 107 | execsql {BEGIN;} |
| 108 | execsql {INSERT INTO t1 SELECT a+1, b FROM t1;} |
| 109 | execsql {INSERT INTO t1 SELECT 'string' || a, b FROM t1 WHERE 0 = (a%7);} |
| 110 | execsql {COMMIT;} |
| 111 | |
| 112 | incr ::residx |
| 113 | } -cleanup { |
| 114 | do_test shared_ioerr-2.$n.cleanup.1 { |
| 115 | set res [catchsql { |
| 116 | SELECT max(a), min(a), count(*) FROM (SELECT a FROM t1 order by a); |
| 117 | } db2] |
| 118 | set possible_results [list \ |
| 119 | {0 {1024 1 1024}} \ |
| 120 | {0 {1023 1 512}} \ |
| 121 | {0 {string994 1 1170}} \ |
| 122 | ] |
| 123 | set idx [lsearch -exact $possible_results $res] |
| 124 | set success [expr {$idx==$::residx || $res=="1 {disk I/O error}"}] |
| 125 | if {!$success} { |
| 126 | puts "" |
| 127 | puts "Result: \"$res\" ($::residx)" |
| 128 | } |
| 129 | set success |
| 130 | } {1} |
| 131 | db2 close |
| 132 | } |
| 133 | |
| 134 | catch {db close} |
| 135 | sqlite3_enable_shared_cache $::enable_shared_cache |
| 136 | finish_test |
| 137 | |