/ Check-in [9e129542]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add a different form of I/O tests. So far has failed to expose new bugs. (CVS 3802)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9e1295428f476dba21c28149c7983f66a9134559
User & Date: danielk1977 2007-04-02 16:46:23
Context
2007-04-02
17:54
Fix a union initializer so that it works with the Borland compiler. (CVS 3803) check-in: a067f78b user: drh tags: trunk
16:46
Add a different form of I/O tests. So far has failed to expose new bugs. (CVS 3802) check-in: 9e129542 user: danielk1977 tags: trunk
16:45
If preprocessor macro OS_OTHER is defined, then ignore OS_UNIX, OS_WIN, and OS_OS2. This makes it easier to add proprietary backends.. (CVS 3801) check-in: 4fdafd3f user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Added test/ioerr2.test.

            1  +# 2007 April 2
            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  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this file is testing for correct handling of I/O errors
           13  +# such as writes failing because the disk is full.
           14  +# 
           15  +# The tests in this file use special facilities that are only
           16  +# available in the SQLite test fixture.
           17  +#
           18  +# $Id: ioerr2.test,v 1.1 2007/04/02 16:46:23 danielk1977 Exp $
           19  +
           20  +set testdir [file dirname $argv0]
           21  +source $testdir/tester.tcl
           22  +
           23  +do_test ioerr2-1.1 {
           24  +  execsql {
           25  +    PRAGMA cache_size = 10;
           26  +    PRAGMA default_cache_size = 10;
           27  +    CREATE TABLE t1(a, b, PRIMARY KEY(a, b));
           28  +    INSERT INTO t1 VALUES(randstr(400,400),randstr(400,400));
           29  +    INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2
           30  +    INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 4
           31  +    INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 8
           32  +    INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 16
           33  +    INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 32
           34  +  }
           35  +} {}
           36  +
           37  +set ::cksum [execsql {SELECT md5sum(a, b) FROM t1}]
           38  +proc check_db {testname} {
           39  +
           40  +  # Make sure no I/O errors are simulated in this proc.
           41  +  set ::sqlite_io_error_hit 0
           42  +  set ::sqlite_io_error_persist 0
           43  +  set ::sqlite_io_error_pending 0
           44  +
           45  +  # Run an integrity-check. If "disk I/O error" is returned, the
           46  +  # pager must be in error state. In this case open a new database
           47  +  # connection. Otherwise, try a ROLLBACK, in case a transaction 
           48  +  # is still active.
           49  +  set rc [catch {execsql {PRAGMA integrity_check}} msg]
           50  +  if {$rc && $msg eq "disk I/O error"} {
           51  +    db close
           52  +    sqlite3 db test.db
           53  +  } else {
           54  +    if {$rc} {error $msg}
           55  +    catch {execsql ROLLBACK}
           56  +  }
           57  +
           58  +  # Check that the database checksum is still $::cksum, and that
           59  +  # the integrity-check passes.
           60  +  set ck [execsql {SELECT md5sum(a, b) FROM t1}]
           61  +  do_test ${testname}.cksum [list set ck $ck] $::cksum
           62  +  integrity_check ${testname}.integrity
           63  +}
           64  +
           65  +check_db ioerr2-2
           66  +
           67  +set sql {
           68  +  PRAGMA cache_size = 10;
           69  +  PRAGMA default_cache_size = 10;
           70  +  BEGIN;
           71  +  DELETE FROM t1 WHERE (oid%7)==0;
           72  +  INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) 
           73  +    WHERE (random()%7)==0;
           74  +  UPDATE t1 SET a = randstr(400,400), b = randstr(400,400) 
           75  +    WHERE (random()%7)==0;
           76  +  ROLLBACK;
           77  +}
           78  +
           79  +foreach bPersist [list 0 1] {
           80  +  set ::go 1
           81  +  for {set ::N 1} {$::go} {incr ::N} {
           82  +    set ::sqlite_io_error_hit 0
           83  +    set ::sqlite_io_error_persist $bPersist
           84  +    set ::sqlite_io_error_pending $::N
           85  +
           86  +    foreach {::go res} [catchsql $sql] {}
           87  +    check_db ioerr2-3.$bPersist.$::N
           88  +  }
           89  +}
           90  +
           91  +finish_test