walslow.test 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # 2010 March 17
  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 the operation of the library in
  13. # "PRAGMA journal_mode=WAL" mode. The tests in this file use
  14. # brute force methods, so may take a while to run.
  15. #
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. ifcapable !wal {finish_test ; return }
  19. proc reopen_db {} {
  20. catch { db close }
  21. forcedelete test.db test.db-wal
  22. sqlite3 db test.db
  23. execsql { PRAGMA journal_mode = wal }
  24. }
  25. db close
  26. save_prng_state
  27. for {set seed 1} {$seed<10} {incr seed} {
  28. expr srand($seed)
  29. restore_prng_state
  30. reopen_db
  31. do_test walslow-1.seed=$seed.0 {
  32. execsql { CREATE TABLE t1(a, b) }
  33. execsql { CREATE INDEX i1 ON t1(a) }
  34. execsql { CREATE INDEX i2 ON t1(b) }
  35. } {}
  36. for {set iTest 1} {$iTest < 100} {incr iTest} {
  37. do_test walslow-1.seed=$seed.$iTest.1 {
  38. set w [expr int(rand()*2000)]
  39. set x [expr int(rand()*2000)]
  40. execsql { INSERT INTO t1 VALUES(randomblob($w), randomblob($x)) }
  41. execsql { PRAGMA integrity_check }
  42. } {ok}
  43. do_test walslow-1.seed=$seed.$iTest.2 {
  44. execsql "PRAGMA wal_checkpoint;"
  45. execsql { PRAGMA integrity_check }
  46. } {ok}
  47. do_test walslow-1.seed=$seed.$iTest.3 {
  48. forcedelete testX.db testX.db-wal
  49. copy_file test.db testX.db
  50. copy_file test.db-wal testX.db-wal
  51. sqlite3 db2 testX.db
  52. execsql { PRAGMA journal_mode = WAL } db2
  53. execsql { PRAGMA integrity_check } db2
  54. } {ok}
  55. do_test walslow-1.seed=$seed.$iTest.4 {
  56. execsql { SELECT count(*) FROM t1 WHERE a!=b } db2
  57. } [execsql { SELECT count(*) FROM t1 WHERE a!=b }]
  58. db2 close
  59. }
  60. }
  61. finish_test