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 / vec1 / test / vec1fault1.test
| 1 | # 2026-04-01 |
| 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 | # |
| 13 | |
| 14 | source [file join [file dirname [info script]] vec1_common.tcl] |
| 15 | set testprefix vec1fault1 |
| 16 | vec1_load db |
| 17 | |
| 18 | do_execsql_test 1.0 { |
| 19 | CREATE VIRTUAL TABLE mytbl USING vec1(a, b); |
| 20 | INSERT INTO mytbl(cmd, arg) VALUES('rebuild', '{index:"flat"}'); |
| 21 | } |
| 22 | faultsim_save_and_close |
| 23 | |
| 24 | do_faultsim_test 1 -faults oom* -prep { |
| 25 | faultsim_restore_and_reopen |
| 26 | vec1_load db |
| 27 | execsql { PRAGMA table_info = mytbl } |
| 28 | } -body { |
| 29 | execsql { |
| 30 | INSERT INTO mytbl VALUES(random_vector(128), 555); |
| 31 | } |
| 32 | } -test { |
| 33 | faultsim_test_result {0 {}} \ |
| 34 | {1 {unable to open a temporary database file for storing temporary tables}} |
| 35 | } |
| 36 | |
| 37 | #------------------------------------------------------------------------- |
| 38 | reset_db |
| 39 | vec1_load db |
| 40 | |
| 41 | do_execsql_test 2.0 { |
| 42 | CREATE VIRTUAL TABLE mytbl USING vec1(a, b); |
| 43 | WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<600 ) |
| 44 | INSERT INTO mytbl SELECT random_vector(8), i FROM s; |
| 45 | INSERT INTO mytbl(cmd, arg) VALUES('rebuild', ( |
| 46 | SELECT vec1_train(a, '{codesize:8, nbucket:2}') FROM mytbl |
| 47 | )); |
| 48 | } |
| 49 | |
| 50 | do_faultsim_test 2 -faults oom* -body { |
| 51 | execsql { |
| 52 | PRAGMA integrity_check |
| 53 | } |
| 54 | } -test { |
| 55 | faultsim_test_result {0 ok} \ |
| 56 | {1 {unable to open a temporary database file for storing temporary tables}} |
| 57 | } |
| 58 | |
| 59 | #------------------------------------------------------------------------- |
| 60 | # OOM error while loading the extension. |
| 61 | # |
| 62 | reset_db |
| 63 | |
| 64 | breakpoint |
| 65 | if {[catch {db one {SELECT vec1_info()}}]} { |
| 66 | do_faultsim_test 3 -faults oom* -prep { |
| 67 | reset_db |
| 68 | } -body { |
| 69 | vec1_load_only db |
| 70 | } -test { |
| 71 | faultsim_test_result {0 {}} {1 {}} {1 {error during initialization: }} |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | #------------------------------------------------------------------------- |
| 76 | # OOM error while deleting lots of rows |
| 77 | # |
| 78 | reset_db |
| 79 | vec1_load db |
| 80 | |
| 81 | do_execsql_test 4.0 { |
| 82 | CREATE VIRTUAL TABLE mytbl USING vec1(a); |
| 83 | WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100 ) |
| 84 | INSERT INTO mytbl SELECT random_vector(8) FROM s; |
| 85 | INSERT INTO mytbl(cmd, arg) VALUES('rebuild', '{index:"flat"}'); |
| 86 | } |
| 87 | faultsim_save_and_close |
| 88 | |
| 89 | do_faultsim_test 4 -faults oom* -prep { |
| 90 | faultsim_restore_and_reopen |
| 91 | vec1_load db |
| 92 | db eval { PRAGMA table_info = mytbl } |
| 93 | } -body { |
| 94 | execsql { |
| 95 | DELETE FROM mytbl WHERE rowid BETWEEN 30 AND 60 |
| 96 | } |
| 97 | } -test { |
| 98 | faultsim_test_result {0 {}} |
| 99 | } |
| 100 | |
| 101 | #------------------------------------------------------------------------- |
| 102 | # OOM error in vec1cat query |
| 103 | # |
| 104 | reset_db |
| 105 | vec1_load db |
| 106 | |
| 107 | do_execsql_test 5.0 { |
| 108 | CREATE VIRTUAL TABLE mytbl USING vec1(a, b); |
| 109 | CREATE VIRTUAL TABLE x1 USING vec1(a, b); |
| 110 | } |
| 111 | |
| 112 | set P {{{ |
| 113 | "total": {"cnt": 0, "cycle": 0}, |
| 114 | "init": {"cnt": 0, "cycle": 0}, |
| 115 | "coarse": {"cnt": 0, "cycle": 0}, |
| 116 | "idxread": {"cnt": 0, "cycle": 0}, |
| 117 | "metaread": {"cnt": 0, "cycle": 0}, |
| 118 | "metascan": {"cnt": 0, "cycle": 0}, |
| 119 | "lut": {"cnt": 0, "cycle": 0}, |
| 120 | "pqscan": {"cnt": 0, "cycle": 0}, |
| 121 | "finalsort": {"cnt": 0, "cycle": 0} |
| 122 | }}} |
| 123 | |
| 124 | do_faultsim_test 5 -faults oom-* -prep { |
| 125 | execsql { PRAGMA table_info = mytbl } |
| 126 | } -body { |
| 127 | execsql { |
| 128 | SELECT rowid, model, qprofile FROM vec1cat |
| 129 | } |
| 130 | } -test { |
| 131 | faultsim_test_result [subst {0 {1 {{"index": "none", "distance": "l2"}} $::P 2 {{"index": "none", "distance": "l2"}} $::P}}] |
| 132 | } |
| 133 | |
| 134 | #------------------------------------------------------------------------- |
| 135 | # OOM error in vec1FlatToNone() |
| 136 | # |
| 137 | reset_db |
| 138 | vec1_load db |
| 139 | |
| 140 | do_execsql_test 6.0 { |
| 141 | CREATE VIRTUAL TABLE hello USING vec1(a, b); |
| 142 | WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100 ) |
| 143 | INSERT INTO hello SELECT random_vector(8), i*100 FROM s; |
| 144 | |
| 145 | INSERT INTO hello(cmd, arg) VALUES('rebuild', '{index:"flat"}'); |
| 146 | } |
| 147 | |
| 148 | do_faultsim_test 6 -faults oom-* -prep { |
| 149 | sqlite3 db test.db |
| 150 | vec1_load db |
| 151 | execsql { PRAGMA table_info = mytbl } |
| 152 | } -body { |
| 153 | execsql { |
| 154 | INSERT INTO hello(cmd, arg) VALUES('rebuild', '{index:"flat"}'); |
| 155 | } |
| 156 | } -test { |
| 157 | faultsim_test_result {0 {}} |
| 158 | } |
| 159 | |
| 160 | #------------------------------------------------------------------------- |
| 161 | # OOM error in vec1FlatToNone() |
| 162 | # |
| 163 | reset_db |
| 164 | vec1_load db |
| 165 | |
| 166 | do_execsql_test 7.0 { |
| 167 | CREATE VIRTUAL TABLE hello USING vec1(a, b); |
| 168 | WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1100 ) |
| 169 | INSERT INTO hello SELECT random_vector(8), i*100 FROM s; |
| 170 | } |
| 171 | |
| 172 | |
| 173 | set mod [db one { |
| 174 | WITH s(i) AS ( |
| 175 | SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<600 |
| 176 | ) |
| 177 | SELECT vec1_train(random_vector(8), '{codesize:8}') FROM s |
| 178 | }] |
| 179 | |
| 180 | do_faultsim_test 7 -faults oom* -prep { |
| 181 | sqlite3 db test.db |
| 182 | vec1_load db |
| 183 | execsql { PRAGMA table_info = mytbl } |
| 184 | } -body { |
| 185 | execsql { |
| 186 | INSERT INTO hello(cmd, arg) VALUES('rebuild', $::mod); |
| 187 | } |
| 188 | } -test { |
| 189 | faultsim_test_result {0 {}} |
| 190 | } |
| 191 | |
| 192 | set mod [db one { |
| 193 | WITH s(i) AS ( |
| 194 | SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<600 |
| 195 | ) |
| 196 | SELECT vec1_train(random_vector(8), '{nbucket:8}') FROM s |
| 197 | }] |
| 198 | |
| 199 | do_faultsim_test 8 -faults oom* -prep { |
| 200 | sqlite3 db test.db |
| 201 | vec1_load db |
| 202 | execsql { PRAGMA table_info = mytbl } |
| 203 | } -body { |
| 204 | execsql { |
| 205 | INSERT INTO hello(cmd, arg) VALUES('rebuild', $::mod); |
| 206 | } |
| 207 | } -test { |
| 208 | faultsim_test_result {0 {}} |
| 209 | } |
| 210 | |
| 211 | |
| 212 | finish_test |
| 213 |