xref: /sqlite-3.40.0/test/ioerr4.test (revision fda06bef)
1ef5a2e18Sdrh# 2007 December 19
2ef5a2e18Sdrh#
3ef5a2e18Sdrh# The author disclaims copyright to this source code.  In place of
4ef5a2e18Sdrh# a legal notice, here is a blessing:
5ef5a2e18Sdrh#
6ef5a2e18Sdrh#    May you do good and not evil.
7ef5a2e18Sdrh#    May you find forgiveness for yourself and forgive others.
8ef5a2e18Sdrh#    May you share freely, never taking more than you give.
9ef5a2e18Sdrh#
10ef5a2e18Sdrh#***********************************************************************
11ef5a2e18Sdrh# This file implements regression tests for SQLite library.  The
12ef5a2e18Sdrh# focus of this file is testing for correct handling of I/O errors
13ef5a2e18Sdrh# during incremental vacuum with a shared cache.
14ef5a2e18Sdrh#
1595ed6bc3Sdrh# $Id: ioerr4.test,v 1.2 2008/05/08 01:11:42 drh Exp $
16ef5a2e18Sdrh
17ef5a2e18Sdrhset testdir [file dirname $argv0]
18ef5a2e18Sdrhsource $testdir/tester.tcl
19ef5a2e18Sdrh
20ef5a2e18Sdrh# This test requires both shared cache and incremental vacuum.
21ef5a2e18Sdrh#
22ef5a2e18Sdrhifcapable {!shared_cache || !autovacuum} {
23ef5a2e18Sdrh  finish_test
24ef5a2e18Sdrh  return
25ef5a2e18Sdrh}
26ef5a2e18Sdrh
27ef5a2e18Sdrh# Enable shared cache mode and incremental vacuum.
28ef5a2e18Sdrh#
29ef5a2e18Sdrhdo_test ioerr4-1.1 {
30ef5a2e18Sdrh  db close
3195ed6bc3Sdrh  set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
32ef5a2e18Sdrh} {0}
33ef5a2e18Sdrhdo_test ioerr4-1.2 {
34*fda06befSmistachkin  forcedelete test.db test.db-journal
35ef5a2e18Sdrh  sqlite3 db test.db
36ef5a2e18Sdrh  sqlite3 db2 test.db
37ef5a2e18Sdrh  db eval {
38ef5a2e18Sdrh    PRAGMA auto_vacuum=INCREMENTAL;
39ef5a2e18Sdrh    CREATE TABLE a(i INTEGER, b BLOB);
40ef5a2e18Sdrh  }
41ef5a2e18Sdrh  db2 eval {
42ef5a2e18Sdrh    SELECT name FROM sqlite_master
43ef5a2e18Sdrh  }
44ef5a2e18Sdrh} {a}
45ef5a2e18Sdrhdo_test ioerr4-1.3 {
46ef5a2e18Sdrh  db eval {
47ef5a2e18Sdrh    PRAGMA auto_vacuum;
48ef5a2e18Sdrh  }
49ef5a2e18Sdrh} {2}
50ef5a2e18Sdrh
51ef5a2e18Sdrh# Insert and delete many records in order to put lots of pages
52ef5a2e18Sdrh# on the freelist.
53ef5a2e18Sdrh#
54ef5a2e18Sdrhdo_test ioerr4-1.4 {
55ef5a2e18Sdrh  db eval {
56ef5a2e18Sdrh    INSERT INTO a VALUES(1, zeroblob(2000));
57ef5a2e18Sdrh    INSERT INTO a VALUES(2, zeroblob(2000));
58ef5a2e18Sdrh    INSERT INTO a SELECT i+2, zeroblob(2000) FROM a;
59ef5a2e18Sdrh    INSERT INTO a SELECT i+4, zeroblob(2000) FROM a;
60ef5a2e18Sdrh    INSERT INTO a SELECT i+8, zeroblob(2000) FROM a;
61ef5a2e18Sdrh    INSERT INTO a SELECT i+16, zeroblob(2000) FROM a;
62ef5a2e18Sdrh    SELECT count(*) FROM a;
63ef5a2e18Sdrh  }
64ef5a2e18Sdrh} {32}
65ef5a2e18Sdrhdo_test ioerr4-1.5 {
66ef5a2e18Sdrh  db eval {
67ef5a2e18Sdrh    PRAGMA freelist_count
68ef5a2e18Sdrh  }
69ef5a2e18Sdrh} {0}
70ef5a2e18Sdrhdo_test ioerr4-1.6 {
71ef5a2e18Sdrh  db eval {
72ef5a2e18Sdrh    DELETE FROM a;
73ef5a2e18Sdrh    PRAGMA freelist_count;
74ef5a2e18Sdrh  }
75ef5a2e18Sdrh} {64}
76ef5a2e18Sdrh
77ef5a2e18Sdrh# Set up for an I/O error on incremental vacuum
78ef5a2e18Sdrh# with two connections on shared cache.
79ef5a2e18Sdrh#
80ef5a2e18Sdrhdb close
81ef5a2e18Sdrhdb2 close
82*fda06befSmistachkinforcecopy test.db test.db-bu
83ef5a2e18Sdrhdo_ioerr_test ioerr4-2 -tclprep {
84ef5a2e18Sdrh  catch {db2 close}
85ef5a2e18Sdrh  db close
86*fda06befSmistachkin  forcedelete test.db test.db-journal
87*fda06befSmistachkin  forcecopy test.db-bu test.db
88ef5a2e18Sdrh  sqlite3_enable_shared_cache 1
89ef5a2e18Sdrh  set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db]
90ef5a2e18Sdrh  db eval {PRAGMA auto_vacuum=INCREMENTAL}
91ef5a2e18Sdrh  sqlite3 db2 test.db
92ef5a2e18Sdrh} -tclbody {
93ef5a2e18Sdrh  db eval {PRAGMA incremental_vacuum(5)}
94ef5a2e18Sdrh}
95ef5a2e18Sdrh
9695ed6bc3Sdrhdb2 close
97*fda06befSmistachkinforcedelete test.db-bu
9895ed6bc3Sdrhsqlite3_enable_shared_cache $::enable_shared_cache
9995ed6bc3Sdrh
100ef5a2e18Sdrhfinish_test
101