ioerr4.test 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # 2007 December 19
  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. # This file implements regression tests for SQLite library. The
  12. # focus of this file is testing for correct handling of I/O errors
  13. # during incremental vacuum with a shared cache.
  14. #
  15. # $Id: ioerr4.test,v 1.2 2008/05/08 01:11:42 drh Exp $
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. # This test requires both shared cache and incremental vacuum.
  19. #
  20. ifcapable {!shared_cache || !autovacuum} {
  21. finish_test
  22. return
  23. }
  24. # Enable shared cache mode and incremental vacuum.
  25. #
  26. do_test ioerr4-1.1 {
  27. db close
  28. set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
  29. } {0}
  30. do_test ioerr4-1.2 {
  31. forcedelete test.db test.db-journal
  32. sqlite3 db test.db
  33. sqlite3 db2 test.db
  34. db eval {
  35. PRAGMA auto_vacuum=INCREMENTAL;
  36. CREATE TABLE a(i INTEGER, b BLOB);
  37. }
  38. db2 eval {
  39. SELECT name FROM sqlite_master
  40. }
  41. } {a}
  42. do_test ioerr4-1.3 {
  43. db eval {
  44. PRAGMA auto_vacuum;
  45. }
  46. } {2}
  47. # Insert and delete many records in order to put lots of pages
  48. # on the freelist.
  49. #
  50. do_test ioerr4-1.4 {
  51. db eval {
  52. INSERT INTO a VALUES(1, zeroblob(2000));
  53. INSERT INTO a VALUES(2, zeroblob(2000));
  54. INSERT INTO a SELECT i+2, zeroblob(2000) FROM a;
  55. INSERT INTO a SELECT i+4, zeroblob(2000) FROM a;
  56. INSERT INTO a SELECT i+8, zeroblob(2000) FROM a;
  57. INSERT INTO a SELECT i+16, zeroblob(2000) FROM a;
  58. SELECT count(*) FROM a;
  59. }
  60. } {32}
  61. do_test ioerr4-1.5 {
  62. db eval {
  63. PRAGMA freelist_count
  64. }
  65. } {0}
  66. do_test ioerr4-1.6 {
  67. db eval {
  68. DELETE FROM a;
  69. PRAGMA freelist_count;
  70. }
  71. } {64}
  72. # Set up for an I/O error on incremental vacuum
  73. # with two connections on shared cache.
  74. #
  75. db close
  76. db2 close
  77. forcecopy test.db test.db-bu
  78. do_ioerr_test ioerr4-2 -tclprep {
  79. catch {db2 close}
  80. db close
  81. forcedelete test.db test.db-journal
  82. forcecopy test.db-bu test.db
  83. sqlite3_enable_shared_cache 1
  84. set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db]
  85. db eval {PRAGMA auto_vacuum=INCREMENTAL}
  86. sqlite3 db2 test.db
  87. } -tclbody {
  88. db eval {PRAGMA incremental_vacuum(5)}
  89. }
  90. db2 close
  91. forcedelete test.db-bu
  92. sqlite3_enable_shared_cache $::enable_shared_cache
  93. finish_test