fts5fault7.test 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # 2015 September 3
  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 fts5fault7
  17. # If SQLITE_ENABLE_FTS3 is defined, omit this file.
  18. ifcapable !fts5 {
  19. finish_test
  20. return
  21. }
  22. if 1 {
  23. #-------------------------------------------------------------------------
  24. # Test fault-injection on a query that uses xColumnSize() on columnsize=0
  25. # table.
  26. #
  27. do_execsql_test 1.0 {
  28. CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=0);
  29. INSERT INTO t1 VALUES('a b c d e f g');
  30. INSERT INTO t1 VALUES('a b c d');
  31. INSERT INTO t1 VALUES('a b c d e f g h i j');
  32. }
  33. fts5_aux_test_functions db
  34. do_faultsim_test 1 -faults oom* -body {
  35. execsql { SELECT fts5_test_columnsize(t1) FROM t1 WHERE t1 MATCH 'b' }
  36. } -test {
  37. faultsim_test_result {0 {7 4 10}} {1 SQLITE_NOMEM}
  38. }
  39. }
  40. #-------------------------------------------------------------------------
  41. # Test fault-injection when a segment is promoted.
  42. #
  43. do_execsql_test 1.0 {
  44. CREATE VIRTUAL TABLE t2 USING fts5(a);
  45. INSERT INTO t2(t2, rank) VALUES('automerge', 0);
  46. INSERT INTO t2(t2, rank) VALUES('crisismerge', 4);
  47. INSERT INTO t2(t2, rank) VALUES('pgsz', 40);
  48. INSERT INTO t2 VALUES('a b c');
  49. INSERT INTO t2 VALUES('d e f');
  50. INSERT INTO t2 VALUES('f e d');
  51. INSERT INTO t2 VALUES('c b a');
  52. INSERT INTO t2 VALUES('a b c');
  53. INSERT INTO t2 VALUES('d e f');
  54. INSERT INTO t2 VALUES('f e d');
  55. INSERT INTO t2 VALUES('c b a');
  56. } {}
  57. faultsim_save_and_close
  58. do_faultsim_test 1 -faults oom-t* -prep {
  59. faultsim_restore_and_reopen
  60. db eval {
  61. BEGIN;
  62. INSERT INTO t2 VALUES('c d c g g f');
  63. INSERT INTO t2 VALUES('c d g b f d');
  64. INSERT INTO t2 VALUES('c c f d e d');
  65. INSERT INTO t2 VALUES('e a f c e f');
  66. INSERT INTO t2 VALUES('c g f b b d');
  67. INSERT INTO t2 VALUES('d a g a b b');
  68. INSERT INTO t2 VALUES('e f a b c e');
  69. INSERT INTO t2 VALUES('e c a g c d');
  70. INSERT INTO t2 VALUES('g b d d e b');
  71. INSERT INTO t2 VALUES('e a d a e d');
  72. }
  73. } -body {
  74. db eval COMMIT
  75. } -test {
  76. faultsim_test_result {0 {}}
  77. }
  78. #-------------------------------------------------------------------------
  79. # Test fault-injection when a segment is promoted.
  80. #
  81. reset_db
  82. do_execsql_test 2.0 {
  83. CREATE VIRTUAL TABLE xy USING fts5(x);
  84. INSERT INTO xy(rowid, x) VALUES(1, '1 2 3');
  85. INSERT INTO xy(rowid, x) VALUES(2, '2 3 4');
  86. INSERT INTO xy(rowid, x) VALUES(3, '3 4 5');
  87. }
  88. faultsim_save_and_close
  89. do_faultsim_test 2.1 -faults oom-* -prep {
  90. faultsim_restore_and_reopen
  91. } -body {
  92. db eval { UPDATE OR REPLACE xy SET rowid=3 WHERE rowid = 2 }
  93. } -test {
  94. faultsim_test_result {0 {}}
  95. }
  96. # Test fault-injection when an empty expression is parsed.
  97. #
  98. do_faultsim_test 2.2 -faults oom-* -body {
  99. db eval { SELECT * FROM xy('""') }
  100. } -test {
  101. faultsim_test_result {0 {}}
  102. }
  103. finish_test