tkt2565.test 2.3 KB

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