3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
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.
15 # The tests in this file use special facilities that are only
16 # available in the SQLite test fixture.
18 # $Id: incrvacuum_ioerr.test,v 1.6 2008/07/12 14:52:20 drh Exp $
20 set testdir [file dirname $argv0]
21 source $testdir/tester.tcl
23 # If this build of the library does not support auto-vacuum, omit this
25 ifcapable {!autovacuum} {
30 do_ioerr_test incrvacuum-ioerr-1 -cksum 1 -sqlprep {
31 PRAGMA auto_vacuum = 'incremental';
33 INSERT INTO abc VALUES(randstr(1500,1500));
38 PRAGMA incremental_vacuum;
42 # do_ioerr_test incrvacuum-ioerr-3 -start 1 -cksum 1 -tclprep {
44 # PRAGMA auto_vacuum = 'full';
45 # PRAGMA cache_size = 10;
47 # CREATE TABLE abc(a, UNIQUE(a));
49 # for {set ii 0} {$ii < 25} {incr ii} {
50 # db eval {INSERT INTO abc VALUES(randstr(1500,1500))}
55 # DELETE FROM abc WHERE (oid%3)==0;
56 # INSERT INTO abc SELECT a || '1234567890' FROM abc WHERE oid%2;
57 # CREATE INDEX abc_i ON abc(a);
58 # DELETE FROM abc WHERE (oid%2)==0;
63 do_ioerr_test incrvacuum-ioerr-2 -start 1 -cksum 1 -tclprep {
65 PRAGMA auto_vacuum = 'full';
66 PRAGMA cache_size = 10;
68 CREATE TABLE abc(a, UNIQUE(a));
70 for {set ii 0} {$ii < 25} {incr ii} {
71 db eval {INSERT INTO abc VALUES(randstr(1500,1500))}
76 PRAGMA incremental_vacuum;
77 DELETE FROM abc WHERE (oid%3)==0;
78 PRAGMA incremental_vacuum;
79 INSERT INTO abc SELECT a || '1234567890' FROM abc WHERE oid%2;
80 PRAGMA incremental_vacuum;
81 CREATE INDEX abc_i ON abc(a);
82 DELETE FROM abc WHERE (oid%2)==0;
83 PRAGMA incremental_vacuum;
85 PRAGMA incremental_vacuum;
89 do_ioerr_test incrvacuum-ioerr-3 -start 1 -cksum 1 -tclprep {
91 PRAGMA auto_vacuum = 'incremental';
93 CREATE TABLE a(i integer, b blob);
94 INSERT INTO a VALUES(1, randstr(1500,1500));
95 INSERT INTO a VALUES(2, randstr(1500,1500));
98 db eval {DELETE FROM a WHERE oid}
100 PRAGMA incremental_vacuum(5);
103 integrity_check incrvacuum-ioerr-2.$n.integritycheck
108 ifcapable shared_cache {
112 set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
114 # Create two connections to a single shared-cache:
119 # Create a database with around 20 free pages.
121 do_test incrvacuum-ioerr-4.0 {
123 PRAGMA page_size = 1024;
124 PRAGMA locking_mode = exclusive;
125 PRAGMA auto_vacuum = 'incremental';
127 CREATE TABLE a(i integer, b blob);
129 for {set ii 0} {$ii < 20} {incr ii} {
130 execsql { INSERT INTO a VALUES($ii, randstr(800,1500)); } db1
133 execsql {DELETE FROM a WHERE oid} db1
137 for {set iTest 1} {$::rc && $iTest<2000} {incr iTest} {
139 # Figure out how big the database is and how many free pages it
140 # has before running incremental-vacuum.
142 set nFree [execsql {pragma freelist_count} db1]
143 set nPage [execsql {pragma page_count} db1]
144 puts "nFree=$nFree nPage=$nPage"
146 # Now run incremental-vacuum to vacuum 5 pages from the db file.
147 # The iTest'th I/O call is set to fail.
149 set ::sqlite_io_error_pending $iTest
150 set ::sqlite_io_error_persist 1
151 do_test incrvacuum-ioerr-4.$iTest.1 {
152 set ::rc [catch {execsql {pragma incremental_vacuum(5)} db1} msg]
153 expr {$::rc==0 || $msg eq "disk I/O error"}
156 set ::sqlite_io_error_pending 0
157 set ::sqlite_io_error_persist 0
158 set ::sqlite_io_error_hit 0
159 set ::sqlite_io_error_hardhit 0
161 set nFree2 [execsql {pragma freelist_count} db1]
162 set nPage2 [execsql {pragma page_count} db1]
164 do_test incrvacuum-ioerr-4.$iTest.2 {
165 set shrink [expr {$nPage-$nPage2}]
166 expr {$shrink==0 || $shrink==5 || ($nFree<5 && $shrink==$nFree)}
169 do_test incrvacuum-ioerr-4.$iTest.3 {
170 expr {$nPage - $nPage2}
171 } [expr {$nFree - $nFree2}]
174 # Close the two database connections and restore the default
175 # shared-cache mode setting.
179 sqlite3_enable_shared_cache $::enable_shared_cache