fts5fault5.test 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 fts5fault5
  17. # If SQLITE_ENABLE_FTS3 is defined, omit this file.
  18. ifcapable !fts5 {
  19. finish_test
  20. return
  21. }
  22. #-------------------------------------------------------------------------
  23. # OOM while creating an FTS5 table.
  24. #
  25. do_faultsim_test 1.1 -faults oom-t* -prep {
  26. db eval { DROP TABLE IF EXISTS abc }
  27. } -body {
  28. db eval { CREATE VIRTUAL TABLE abc USING fts5(x,y) }
  29. } -test {
  30. faultsim_test_result {0 {}}
  31. }
  32. #-------------------------------------------------------------------------
  33. # OOM while writing a multi-tier doclist-index. And while running
  34. # integrity-check on the same.
  35. #
  36. reset_db
  37. do_execsql_test 2.0 {
  38. CREATE VIRTUAL TABLE tt USING fts5(x);
  39. INSERT INTO tt(tt, rank) VALUES('pgsz', 32);
  40. }
  41. faultsim_save_and_close
  42. do_faultsim_test 2.1 -faults oom-t* -prep {
  43. faultsim_restore_and_reopen
  44. db eval { SELECT * FROM tt }
  45. } -body {
  46. set str [string repeat "abc " 50]
  47. db eval {
  48. WITH ii(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM ii WHERE i<100)
  49. INSERT INTO tt(rowid, x) SELECT i, $str FROM ii;
  50. }
  51. } -test {
  52. faultsim_test_result {0 {}}
  53. }
  54. do_faultsim_test 2.2 -faults oom-t* -body {
  55. db eval { INSERT INTO tt(tt) VALUES('integrity-check') }
  56. } -test {
  57. faultsim_test_result {0 {}}
  58. }
  59. #-------------------------------------------------------------------------
  60. # OOM while scanning fts5vocab tables.
  61. #
  62. reset_db
  63. do_test 3.0 {
  64. execsql {
  65. CREATE VIRTUAL TABLE tt USING fts5(x);
  66. CREATE VIRTUAL TABLE tv USING fts5vocab(tt, 'row');
  67. CREATE VIRTUAL TABLE tt2 USING fts5(x, detail=col);
  68. CREATE VIRTUAL TABLE tv2 USING fts5vocab(tt2, 'col');
  69. INSERT INTO tt(tt, rank) VALUES('pgsz', 32);
  70. INSERT INTO tt2(tt2, rank) VALUES('pgsz', 32);
  71. BEGIN;
  72. }
  73. for {set i 0} {$i < 20} {incr i} {
  74. set str [string repeat "$i " 50]
  75. execsql { INSERT INTO tt VALUES($str) }
  76. execsql { INSERT INTO tt2 VALUES($str) }
  77. }
  78. execsql COMMIT
  79. } {}
  80. do_faultsim_test 3.1 -faults oom-t* -body {
  81. db eval {
  82. SELECT term FROM tv;
  83. }
  84. } -test {
  85. faultsim_test_result {0 {0 1 10 11 12 13 14 15 16 17 18 19 2 3 4 5 6 7 8 9}}
  86. }
  87. do_faultsim_test 3.2 -faults oom-t* -body {
  88. db eval {
  89. SELECT term FROM tv WHERE term BETWEEN '1' AND '2';
  90. }
  91. } -test {
  92. faultsim_test_result {0 {1 10 11 12 13 14 15 16 17 18 19 2}}
  93. }
  94. do_execsql_test 3.3.0 {
  95. SELECT * FROM tv2;
  96. } {
  97. 0 x 1 {} 1 x 1 {} 10 x 1 {} 11 x 1 {} 12 x 1 {} 13 x 1 {}
  98. 14 x 1 {} 15 x 1 {} 16 x 1 {} 17 x 1 {} 18 x 1 {} 19 x 1 {}
  99. 2 x 1 {} 3 x 1 {} 4 x 1 {} 5 x 1 {} 6 x 1 {} 7 x 1 {} 8 x 1 {}
  100. 9 x 1 {}
  101. }
  102. do_faultsim_test 3.3 -faults oom-t* -body {
  103. db eval {
  104. SELECT * FROM tv2;
  105. }
  106. } -test {
  107. faultsim_test_result [list 0 [list \
  108. 0 x 1 {} 1 x 1 {} 10 x 1 {} 11 x 1 {} 12 x 1 {} 13 x 1 {} \
  109. 14 x 1 {} 15 x 1 {} 16 x 1 {} 17 x 1 {} 18 x 1 {} 19 x 1 {} \
  110. 2 x 1 {} 3 x 1 {} 4 x 1 {} 5 x 1 {} 6 x 1 {} 7 x 1 {} 8 x 1 {} \
  111. 9 x 1 {}
  112. ]]
  113. }
  114. finish_test