wal4.test 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # 2010 July 1
  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. # Verify that an empty database and a non-empty WAL file do not
  12. # result in database corruption
  13. #
  14. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. source $testdir/malloc_common.tcl
  17. ifcapable !wal {finish_test ; return }
  18. do_test wal4-1.1 {
  19. execsql {
  20. PRAGMA journal_mode=WAL;
  21. CREATE TABLE t1(x);
  22. INSERT INTO t1 VALUES(1);
  23. INSERT INTO t1 VALUES(2);
  24. SELECT x FROM t1 ORDER BY x;
  25. }
  26. } {wal 1 2}
  27. do_test wal4-1.2 {
  28. # Save a copy of the file-system containing the wal and wal-index files
  29. # only (no database file).
  30. faultsim_save_and_close
  31. forcedelete sv_test.db
  32. } {}
  33. do_test wal4-1.3 {
  34. faultsim_restore_and_reopen
  35. catchsql { SELECT * FROM t1 }
  36. } {1 {no such table: t1}}
  37. do_faultsim_test wal4-2 -prep {
  38. faultsim_restore_and_reopen
  39. } -body {
  40. execsql { SELECT name FROM sqlite_master }
  41. } -test {
  42. # Result should be zero rows (empty db file).
  43. #
  44. faultsim_test_result {0 {}}
  45. # If the SELECT finished successfully, the WAL file should have been
  46. # deleted. In no case should the database file have been written, so
  47. # it should still be zero bytes in size regardless of whether or not
  48. # a fault was injected. Test these assertions:
  49. #
  50. if { $testrc==0 && [file exists test.db-wal] } {
  51. error "Wal file was not deleted"
  52. }
  53. if { [file size test.db]!=0 } {
  54. error "Db file grew to [file size test.db] bytes"
  55. }
  56. }
  57. finish_test