rbucrash2.test 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # 2017 March 02
  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. source [file join [file dirname [info script]] rbu_common.tcl]
  13. if_no_rbu_support { finish_test ; return }
  14. set ::testprefix rbucrash2
  15. # Set up a target database and an rbu update database. The target
  16. # db is the usual "test.db", the rbu db is "test.db2".
  17. #
  18. forcedelete test.db2
  19. do_execsql_test 1.0 {
  20. CREATE TABLE t1(a, b, c, PRIMARY KEY(a), UNIQUE(b));
  21. INSERT INTO t1 VALUES(1, 2, 3);
  22. INSERT INTO t1 VALUES(4, 5, 6);
  23. INSERT INTO t1 VALUES(7, 8, 9);
  24. ATTACH 'test.db2' AS rbu;
  25. CREATE TABLE rbu.data_t1(a, b, c, rbu_control);
  26. INSERT INTO data_t1 VALUES('one', randomblob(3500), NULL, 0);
  27. INSERT INTO data_t1 VALUES('two', randomblob(3500), NULL, 0);
  28. INSERT INTO data_t1 VALUES('three', randomblob(3500), NULL, 0);
  29. INSERT INTO data_t1 VALUES('four', randomblob(3500), NULL, 0);
  30. INSERT INTO data_t1 VALUES('five', randomblob(3500), NULL, 0);
  31. INSERT INTO data_t1 VALUES('six', randomblob(3500), NULL, 0);
  32. }
  33. db_save_and_close
  34. proc do_rbu_crash_test2 {tn script} {
  35. foreach {f blksz} {
  36. test.db 512
  37. test.db2 512
  38. test.db 4096
  39. test.db2 4096
  40. } {
  41. set bDone 0
  42. for {set iDelay 1} {$bDone==0} {incr iDelay} {
  43. forcedelete test.db2 test.db2-journal test.db test.db-oal test.db-wal
  44. db_restore
  45. set res [
  46. crashsql -file $f -delay $iDelay -tclbody $script -dflt 1 -opendb {} \
  47. -blocksize $blksz {}
  48. ]
  49. set bDone 1
  50. if {$res == "1 {child process exited abnormally}"} {
  51. set bDone 0
  52. } elseif {$res != "0 {}"} {
  53. error "unexected catchsql result: $res"
  54. }
  55. sqlite3rbu rbu test.db test.db2
  56. while {[rbu step]=="SQLITE_OK"} {}
  57. rbu close
  58. sqlite3 db test.db
  59. do_execsql_test $tn.delay=$iDelay.f=$f.blksz=$blksz {
  60. PRAGMA integrity_check;
  61. } {ok}
  62. db close
  63. }
  64. }
  65. }
  66. for {set x 1} {$x < 10} {incr x} {
  67. do_rbu_crash_test2 1.$x {
  68. sqlite3rbu rbu test.db test.db2
  69. while {[rbu step]=="SQLITE_OK"} {
  70. rbu savestate
  71. }
  72. rbu close
  73. }
  74. }
  75. for {set x 1} {$x < 2} {incr x} {
  76. do_rbu_crash_test2 2.$x {
  77. sqlite3rbu rbu test.db test.db2
  78. while {[rbu step]=="SQLITE_OK"} {
  79. rbu close
  80. sqlite3rbu rbu test.db test.db2
  81. }
  82. rbu close
  83. }
  84. }
  85. finish_test