fts5fault3.test 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # 2014 June 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. #
  12. # This file is focused on OOM errors.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. source $testdir/malloc_common.tcl
  16. set testprefix fts5fault3
  17. # If SQLITE_ENABLE_FTS3 is defined, omit this file.
  18. ifcapable !fts5 {
  19. finish_test
  20. return
  21. }
  22. #-------------------------------------------------------------------------
  23. # An OOM while resuming a partially completed segment merge.
  24. #
  25. db func rnddoc fts5_rnddoc
  26. do_test 1.0 {
  27. expr srand(0)
  28. execsql {
  29. CREATE VIRTUAL TABLE xx USING fts5(x);
  30. INSERT INTO xx(xx, rank) VALUES('pgsz', 32);
  31. INSERT INTO xx(xx, rank) VALUES('automerge', 16);
  32. }
  33. for {set i 0} {$i < 10} {incr i} {
  34. execsql {
  35. BEGIN;
  36. INSERT INTO xx(x) VALUES(rnddoc(20));
  37. INSERT INTO xx(x) VALUES(rnddoc(20));
  38. INSERT INTO xx(x) VALUES(rnddoc(20));
  39. COMMIT
  40. }
  41. }
  42. execsql {
  43. INSERT INTO xx(xx, rank) VALUES('automerge', 2);
  44. INSERT INTO xx(xx, rank) VALUES('merge', 50);
  45. }
  46. } {}
  47. faultsim_save_and_close
  48. do_faultsim_test 1 -faults oom-* -prep {
  49. faultsim_restore_and_reopen
  50. } -body {
  51. execsql { INSERT INTO xx(xx, rank) VALUES('merge', 1) }
  52. } -test {
  53. faultsim_test_result [list 0 {}]
  54. }
  55. #-------------------------------------------------------------------------
  56. # An OOM while flushing an unusually large term to disk.
  57. #
  58. reset_db
  59. do_execsql_test 2.0 {
  60. CREATE VIRTUAL TABLE xx USING fts5(x);
  61. INSERT INTO xx(xx, rank) VALUES('pgsz', 32);
  62. }
  63. faultsim_save_and_close
  64. set doc "a long term abcdefghijklmnopqrstuvwxyz "
  65. append doc "and then abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz "
  66. append doc [string repeat "abcdefghijklmnopqrstuvwxyz" 10]
  67. do_faultsim_test 2 -faults oom-* -prep {
  68. faultsim_restore_and_reopen
  69. } -body {
  70. execsql { INSERT INTO xx(x) VALUES ($::doc) }
  71. } -test {
  72. faultsim_test_result [list 0 {}]
  73. }
  74. #-------------------------------------------------------------------------
  75. # An OOM while flushing an unusually large term to disk.
  76. #
  77. reset_db
  78. do_execsql_test 3.0 {
  79. CREATE VIRTUAL TABLE xx USING fts5(x);
  80. }
  81. faultsim_save_and_close
  82. set doc [fts5_rnddoc 1000]
  83. do_faultsim_test 3.1 -faults oom-* -prep {
  84. faultsim_restore_and_reopen
  85. } -body {
  86. execsql { INSERT INTO xx(x) VALUES ($::doc) }
  87. } -test {
  88. faultsim_test_result [list 0 {}]
  89. }
  90. set doc [string repeat "abc " 100]
  91. do_faultsim_test 3.2 -faults oom-* -prep {
  92. faultsim_restore_and_reopen
  93. } -body {
  94. execsql { INSERT INTO xx(x) VALUES ($::doc) }
  95. } -test {
  96. faultsim_test_result [list 0 {}]
  97. }
  98. finish_test