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