fts5faultF.test 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # 2023 July 20
  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. Particularly those that may occur
  13. # when using contentless_delete=1 databases.
  14. #
  15. source [file join [file dirname [info script]] fts5_common.tcl]
  16. source $testdir/malloc_common.tcl
  17. set testprefix fts5faultF
  18. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  19. ifcapable !fts5 {
  20. finish_test
  21. return
  22. }
  23. faultsim_save_and_close
  24. do_faultsim_test 1 -prep {
  25. faultsim_restore_and_reopen
  26. } -body {
  27. execsql {
  28. CREATE VIRTUAL TABLE t1 USING fts5(x, y, content=, contentless_delete=1)
  29. }
  30. } -test {
  31. faultsim_test_result {0 {}} {1 {vtable constructor failed: t1}}
  32. }
  33. reset_db
  34. do_execsql_test 2.0 {
  35. CREATE VIRTUAL TABLE t1 USING fts5(doc, content=, contentless_delete=1);
  36. BEGIN;
  37. INSERT INTO t1(rowid, doc) VALUES(1, 'a b c d');
  38. INSERT INTO t1(rowid, doc) VALUES(2, 'a b c d');
  39. INSERT INTO t1(rowid, doc) VALUES(3, 'a b c d');
  40. INSERT INTO t1(rowid, doc) VALUES(4, 'a b c d');
  41. COMMIT;
  42. DELETE FROM t1 WHERE rowid IN (2, 4);
  43. }
  44. do_faultsim_test 2 -prep {
  45. sqlite3 db test.db
  46. execsql { SELECT rowid FROM t1 }
  47. } -body {
  48. execsql {
  49. SELECT rowid FROM t1('b c');
  50. }
  51. } -test {
  52. faultsim_test_result {0 {1 3}}
  53. }
  54. #-------------------------------------------------------------------------
  55. reset_db
  56. do_execsql_test 3.0 {
  57. CREATE VIRTUAL TABLE t1 USING fts5(doc, content=, contentless_delete=1);
  58. BEGIN;
  59. INSERT INTO t1(rowid, doc) VALUES(1, 'a b c d');
  60. INSERT INTO t1(rowid, doc) VALUES(2, 'a b c d');
  61. INSERT INTO t1(rowid, doc) VALUES(3, 'a b c d');
  62. INSERT INTO t1(rowid, doc) VALUES(4, 'a b c d');
  63. COMMIT;
  64. }
  65. faultsim_save_and_close
  66. do_faultsim_test 3 -prep {
  67. faultsim_restore_and_reopen
  68. execsql { SELECT rowid FROM t1 }
  69. } -body {
  70. execsql {
  71. INSERT INTO t1(rowid, doc) VALUES(5, 'a b c d');
  72. }
  73. } -test {
  74. faultsim_test_result {0 {}}
  75. }
  76. #-------------------------------------------------------------------------
  77. reset_db
  78. do_execsql_test 4.0 {
  79. CREATE VIRTUAL TABLE t1 USING fts5(doc, content=, contentless_delete=1);
  80. INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
  81. WITH s(i) AS (
  82. SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000
  83. )
  84. INSERT INTO t1(rowid, doc) SELECT i, 'a b c d' FROM s;
  85. }
  86. do_execsql_test 4.1 { DELETE FROM t1 WHERE rowid <= 25 }
  87. faultsim_save_and_close
  88. do_faultsim_test 4 -faults oom-t* -prep {
  89. faultsim_restore_and_reopen
  90. execsql { SELECT rowid FROM t1 }
  91. } -body {
  92. execsql {
  93. DELETE FROM t1 WHERE rowid < 100
  94. }
  95. } -test {
  96. faultsim_test_result {0 {}}
  97. }
  98. finish_test