summaryrefslogtreecommitdiffstats
path: root/test/tkt2565.test
blob: 8df0419c65abd7bbe2fd717bd164eadbaa64a88e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# 2009 January 8
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This script attempts to reproduce the circumstances of ticket #2565.
#
# More specifically, this script attempts to generate rollback journals
# that contain headers with nRec==0 that are followed by additional
# valid headers.
#
# $Id: tkt2565.test,v 1.2 2009/04/09 01:23:49 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Use the alternative pcache and rig it to call pagerStress()
# very frequently.
#
db close
sqlite3_shutdown
sqlite3_config_alt_pcache 1 100 0 1

# Open two database connections to database "test.db".
#
proc reopen_database {} {
  catch {db close}
  sqlite3 db test.db
  db cache size 0
  execsql {
    pragma page_size=512;
    pragma auto_vacuum=2;
    pragma cache_size=16;
  }
}

# Open two database connections and create a single table in the db.
#
do_test tkt2565-1.0 {
  reopen_database
  execsql { CREATE TABLE A(Id INTEGER, Name TEXT) }
} {}

for {set iFail 1} {$iFail<200} {incr iFail} {
  reopen_database
  execsql { pragma locking_mode=exclusive }
  set nRow [db one {SELECT count(*) FROM a}]
  
  # Dirty (at least) one of the pages in the cache.
  do_test tkt2565-1.$iFail.1 {
    execsql {
      BEGIN EXCLUSIVE;
      INSERT INTO a VALUES(1, 'ABCDEFGHIJKLMNOP');
    }
  } {}
  
  # Now try to commit the transaction. Cause an IO error to occur
  # within this operation, which moves the pager into the error state.
  #
  set ::sqlite_io_error_persist 1
  set ::sqlite_io_error_pending $iFail
  do_test tkt2565-1.$iFail.2 {
    set rc [catchsql {COMMIT}]
    list
  } {}
  set ::sqlite_io_error_persist 0
  set ::sqlite_io_error_pending 0
  if {!$::sqlite_io_error_hit} break
  set ::sqlite_io_error_hit 0
}

# Make sure this test script doesn't leave any files open.
#
do_test tkt2565-1.X {
  catch { db close }
  set sqlite_open_file_count
} 0

# Restore the pcache configuration for subsequent tests.
#
sqlite3_shutdown
sqlite3_config_alt_pcache 0
sqlite3_initialize
autoinstall_test_functions

finish_test