| 1 |
# 2009 January 8 |
| 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 |
# This script attempts to reproduce the circumstances of ticket #2565. |
| 13 |
# |
| 14 |
# More specifically, this script attempts to generate rollback journals |
| 15 |
# that contain headers with nRec==0 that are followed by additional |
| 16 |
# valid headers. |
| 17 |
# |
| 18 |
# $Id: tkt2565.test,v 1.2 2009/04/09 01:23:49 drh Exp $ |
| 19 |
|
| 20 |
set testdir [file dirname $argv0] |
| 21 |
source $testdir/tester.tcl |
| 22 |
|
| 23 |
# Use the alternative pcache and rig it to call pagerStress() |
| 24 |
# very frequently. |
| 25 |
# |
| 26 |
db close |
| 27 |
sqlite3_shutdown |
| 28 |
sqlite3_config_alt_pcache 1 100 0 1 |
| 29 |
|
| 30 |
# Open two database connections to database "test.db". |
| 31 |
# |
| 32 |
proc reopen_database {} { |
| 33 |
catch {db close} |
| 34 |
sqlite3 db test.db |
| 35 |
db cache size 0 |
| 36 |
execsql { |
| 37 |
pragma page_size=512; |
| 38 |
pragma auto_vacuum=2; |
| 39 |
pragma cache_size=16; |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
# Open two database connections and create a single table in the db. |
| 44 |
# |
| 45 |
do_test tkt2565-1.0 { |
| 46 |
reopen_database |
| 47 |
execsql { CREATE TABLE A(Id INTEGER, Name TEXT) } |
| 48 |
} {} |
| 49 |
|
| 50 |
for {set iFail 1} {$iFail<200} {incr iFail} { |
| 51 |
reopen_database |
| 52 |
execsql { pragma locking_mode=exclusive } |
| 53 |
set nRow [db one {SELECT count(*) FROM a}] |
| 54 |
|
| 55 |
# Dirty (at least) one of the pages in the cache. |
| 56 |
do_test tkt2565-1.$iFail.1 { |
| 57 |
execsql { |
| 58 |
BEGIN EXCLUSIVE; |
| 59 |
INSERT INTO a VALUES(1, 'ABCDEFGHIJKLMNOP'); |
| 60 |
} |
| 61 |
} {} |
| 62 |
|
| 63 |
# Now try to commit the transaction. Cause an IO error to occur |
| 64 |
# within this operation, which moves the pager into the error state. |
| 65 |
# |
| 66 |
set ::sqlite_io_error_persist 1 |
| 67 |
set ::sqlite_io_error_pending $iFail |
| 68 |
do_test tkt2565-1.$iFail.2 { |
| 69 |
set rc [catchsql {COMMIT}] |
| 70 |
list |
| 71 |
} {} |
| 72 |
set ::sqlite_io_error_persist 0 |
| 73 |
set ::sqlite_io_error_pending 0 |
| 74 |
if {!$::sqlite_io_error_hit} break |
| 75 |
set ::sqlite_io_error_hit 0 |
| 76 |
} |
| 77 |
|
| 78 |
# Make sure this test script doesn't leave any files open. |
| 79 |
# |
| 80 |
do_test tkt2565-1.X { |
| 81 |
catch { db close } |
| 82 |
set sqlite_open_file_count |
| 83 |
} 0 |
| 84 |
|
| 85 |
# Restore the pcache configuration for subsequent tests. |
| 86 |
# |
| 87 |
sqlite3_shutdown |
| 88 |
sqlite3_config_alt_pcache 0 |
| 89 |
sqlite3_initialize |
| 90 |
autoinstall_test_functions |
| 91 |
|
| 92 |
finish_test |