tkt-fc62af4523.test 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # 2010 June 16
  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. Specifically,
  12. # it tests that ticket [fc62af4523] has been resolved.
  13. #
  14. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. source $testdir/lock_common.tcl
  17. source $testdir/malloc_common.tcl
  18. do_test tkt-fc62af4523.1 {
  19. execsql {
  20. PRAGMA cache_size = 10;
  21. PRAGMA journal_mode = persist;
  22. CREATE TABLE t1(a UNIQUE, b UNIQUE);
  23. INSERT INTO t1 SELECT randomblob(200), randomblob(300);
  24. INSERT INTO t1 SELECT randomblob(200), randomblob(300) FROM t1; -- 2
  25. INSERT INTO t1 SELECT randomblob(200), randomblob(300) FROM t1; -- 4
  26. INSERT INTO t1 SELECT randomblob(200), randomblob(300) FROM t1; -- 8
  27. INSERT INTO t1 SELECT randomblob(200), randomblob(300) FROM t1; -- 16
  28. INSERT INTO t1 SELECT randomblob(200), randomblob(300) FROM t1; -- 32
  29. INSERT INTO t1 SELECT randomblob(200), randomblob(300) FROM t1; -- 64
  30. }
  31. execsql {
  32. PRAGMA integrity_check;
  33. SELECT count(*) FROM t1;
  34. }
  35. } {ok 64}
  36. # Launch an external process. Have it write (but not commit) a large
  37. # transaction to the database.
  38. #
  39. set ::chan [launch_testfixture]
  40. proc buddy {code} { testfixture $::chan $code }
  41. do_test tkt-fc62af4523.2 {
  42. testfixture $::chan {
  43. sqlite3 db test.db
  44. db eval {
  45. PRAGMA cache_size = 10;
  46. BEGIN;
  47. UPDATE t1 SET b = randomblob(400);
  48. UPDATE t1 SET a = randomblob(201);
  49. }
  50. }
  51. file exists test.db-journal
  52. } {1}
  53. # Now do "PRAGMA journal_mode = DELETE" in this process. At one point
  54. # this was causing SQLite to delete the journal file from the file-system,
  55. # even though the external process is currently using it.
  56. #
  57. do_test tkt-fc62af4523.3 { execsql { PRAGMA journal_mode = DELETE } } {delete}
  58. do_test tkt-fc62af4523.4 { file exists test.db-journal } {1}
  59. # Cause the external process to crash. Since it has already written
  60. # uncommitted data into the database file, the next reader will have
  61. # to do a hot-journal rollback to recover the database.
  62. #
  63. # Or, if this test is run in a version with the bug present, the journal
  64. # file has already been deleted. In this case we are left with a corrupt
  65. # database file and no hot-journal to fix it with.
  66. #
  67. do_test tkt-fc62af4523.5 {
  68. testfixture $::chan sqlite_abort
  69. } {ERROR: Child process hung up}
  70. after 200
  71. do_test tkt-fc62af4523.6 {
  72. execsql {
  73. PRAGMA integrity_check;
  74. SELECT count(*) FROM t1;
  75. }
  76. } {ok 64}
  77. catch { close $::chan }
  78. finish_test