xref: /sqlite-3.40.0/test/diskfull.test (revision 74217cc0)
1# 2001 October 12
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 disk full
13# errors.
14#
15# $Id: diskfull.test,v 1.3 2005/09/09 10:46:19 drh Exp $
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20do_test diskfull-1.1 {
21  execsql {
22    CREATE TABLE t1(x);
23    INSERT INTO t1 VALUES(randstr(1000,1000));
24    INSERT INTO t1 SELECT * FROM t1;
25    INSERT INTO t1 SELECT * FROM t1;
26    INSERT INTO t1 SELECT * FROM t1;
27    INSERT INTO t1 SELECT * FROM t1;
28    CREATE INDEX t1i1 ON t1(x);
29    CREATE TABLE t2 AS SELECT x AS a, x AS b FROM t1;
30    CREATE INDEX t2i1 ON t2(b);
31  }
32} {}
33set sqlite_diskfull_pending 0
34integrity_check diskfull-1.2
35do_test diskfull-1.3 {
36  set sqlite_diskfull_pending 1
37  catchsql {
38    INSERT INTO t1 SELECT * FROM t1;
39  }
40} {1 {database or disk is full}}
41set sqlite_diskfull_pending 0
42integrity_check diskfull-1.4
43do_test diskfull-1.5 {
44  set sqlite_diskfull_pending 1
45  catchsql {
46    DELETE FROM t1;
47  }
48} {1 {database or disk is full}}
49set sqlite_diskfull_pending 0
50integrity_check diskfull-1.6
51
52set go 1
53set i 0
54while {$go} {
55  incr i
56  do_test diskfull-2.$i.1 {
57    set sqlite_diskfull_pending $i
58    set sqlite_diskfull 0
59    set r [catchsql {VACUUM}]
60    if {!$sqlite_diskfull} {
61      set r {1 {database or disk is full}}
62      set go 0
63    }
64    if {$r=="1 {disk I/O error}"} {
65      set r {1 {database or disk is full}}
66    }
67    set r
68  } {1 {database or disk is full}}
69  set sqlite_diskfull_pending 0
70  db close
71  sqlite3 db test.db
72  integrity_check diskfull-2.$i.2
73}
74
75finish_test
76