Snapshot of upstream SQLite 3.11.0
[sqlcipher.git] / ext / fts5 / test / fts5fault2.test
blob43c7c7a3dda1e1e0c5dc2ab872bd5f3c4388bd69
1 # 2014 June 17
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #*************************************************************************
12 # This file is focused on OOM errors.
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 source $testdir/malloc_common.tcl
17 set testprefix fts5fault2
19 # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
20 ifcapable !fts5 {
21   finish_test
22   return
25 set doc [string trim [string repeat "x y z " 200]]
26 do_execsql_test 1.0 {
27   CREATE TABLE t1(a INTEGER PRIMARY KEY, x);
28   CREATE VIRTUAL TABLE x1 USING fts5(x, content='t1', content_rowid='a');
29   INSERT INTO x1(x1, rank) VALUES('pgsz', 32);
30   WITH input(a,b) AS (
31     SELECT 1, $doc UNION ALL
32     SELECT a+1, ($doc || CASE WHEN (a+1)%100 THEN '' ELSE ' xyz' END) 
33     FROM input WHERE a < 1000
34   )
35   INSERT INTO t1 SELECT * FROM input;
37   INSERT INTO x1(x1) VALUES('rebuild');
40 do_faultsim_test 1.1 -faults oom-* -prep {
41 } -body {
42   execsql { SELECT rowid FROM x1 WHERE x1 MATCH 'z AND xyz' }
43 } -test {
44   faultsim_test_result {0 {100 200 300 400 500 600 700 800 900 1000}}
47 do_faultsim_test 1.2 -faults oom-* -prep {
48 } -body {
49   execsql { SELECT rowid FROM x1 WHERE x1 MATCH 'z + xyz' ORDER BY 1 DESC}
50 } -test {
51   faultsim_test_result {0 {1000 900 800 700 600 500 400 300 200 100}}
54 #-------------------------------------------------------------------------
55 # OOM within a query that accesses the in-memory hash table. 
57 reset_db 
58 do_execsql_test 2.0 {
59   CREATE VIRTUAL TABLE "a b c" USING fts5(a, b, c);
60   INSERT INTO "a b c" VALUES('one two', 'x x x', 'three four');
61   INSERT INTO "a b c" VALUES('nine ten', 'y y y', 'two two');
64 do_faultsim_test 2.1 -faults oom-trans* -prep {
65   execsql {
66     BEGIN;
67       INSERT INTO "a b c" VALUES('one one', 'z z z', 'nine ten');
68   }
69 } -body {
70   execsql { SELECT rowid FROM "a b c" WHERE "a b c" MATCH 'one' }
71 } -test {
72   faultsim_test_result {0 {1 3}}
73   catchsql { ROLLBACK }
76 #-------------------------------------------------------------------------
77 # OOM within an 'optimize' operation that writes multiple pages to disk.
79 reset_db 
80 do_execsql_test 3.0 {
81   CREATE VIRTUAL TABLE zzz USING fts5(z);
82   INSERT INTO zzz(zzz, rank) VALUES('pgsz', 32);
83   INSERT INTO zzz VALUES('a b c d');
84   INSERT INTO zzz SELECT 'c d e f' FROM zzz;
85   INSERT INTO zzz SELECT 'e f g h' FROM zzz;
86   INSERT INTO zzz SELECT 'i j k l' FROM zzz;
87   INSERT INTO zzz SELECT 'l k m n' FROM zzz;
88   INSERT INTO zzz SELECT 'o p q r' FROM zzz;
90 faultsim_save_and_close
92 do_faultsim_test 3.1 -faults oom-trans* -prep {
93   faultsim_restore_and_reopen
94   execsql { SELECT rowid FROM zzz }
95 } -body {
96   execsql { INSERT INTO zzz(zzz) VALUES('optimize') }
97 } -test {
98   faultsim_test_result {0 {}}
101 #-------------------------------------------------------------------------
102 # OOM within an 'integrity-check' operation.
104 reset_db 
105 db func rnddoc fts5_rnddoc
106 do_execsql_test 4.0 {
107   CREATE VIRTUAL TABLE zzz USING fts5(z);
108   INSERT INTO zzz(zzz, rank) VALUES('pgsz', 32);
109   WITH ii(i) AS (SELECT 1 UNION SELECT i+1 FROM ii WHERE i<10)
110   INSERT INTO zzz SELECT rnddoc(10) || ' xccc' FROM ii;
113 do_faultsim_test 4.1 -faults oom-trans* -prep {
114 } -body {
115   execsql { INSERT INTO zzz(zzz) VALUES('integrity-check') }
116 } -test {
117   faultsim_test_result {0 {}}
120 #-------------------------------------------------------------------------
121 # OOM while parsing a tokenize=option
123 reset_db
124 faultsim_save_and_close
125 do_faultsim_test 5.0 -faults oom-* -prep {
126   faultsim_restore_and_reopen
127 } -body {
128   execsql { 
129     CREATE VIRTUAL TABLE uio USING fts5(a, b, 
130       tokenize="porter 'ascii'",
131       content="another table",
132       content_rowid="somecolumn"
133     );
134   }
135 } -test {
136   faultsim_test_result {0 {}}
139 finish_test