Debian Codegraph @

ext/session/sessionfault3.test

raw
1 # 2016 October 6
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 # The focus of this file is testing the session module.
13 #
14
15 if {![info exists testdir]} {
16 set testdir [file join [file dirname [info script]] .. .. test]
17 }
18 source [file join [file dirname [info script]] session_common.tcl]
19 source $testdir/tester.tcl
20 ifcapable !session {finish_test; return}
21 set testprefix sessionfault3
22
23 do_execsql_test 1.0 {
24 CREATE TABLE t1(a, b, PRIMARY KEY(a));
25 INSERT INTO t1 VALUES(1, 2);
26 INSERT INTO t1 VALUES(3, 4);
27 INSERT INTO t1 VALUES('five', 'six');
28 }
29
30 set C1 [changeset_from_sql {
31 INSERT INTO t1 VALUES('seven', 'eight');
32 UPDATE t1 SET b=6 WHERE a='five';
33 DELETE FROM t1 WHERE a=1;
34 }]
35
36 do_execsql_test 1.1 {
37 ALTER TABLE t1 ADD COLUMN d DEFAULT 123;
38 ALTER TABLE t1 ADD COLUMN e DEFAULT 'string';
39 }
40
41 set C2 [changeset_from_sql {
42 UPDATE t1 SET e='new value' WHERE a='seven';
43 INSERT INTO t1 VALUES(0, 0, 0, 0);
44 }]
45
46 do_faultsim_test 1.2 -faults oom* -prep {
47 sqlite3changegroup G
48 } -body {
49 G schema db main
50 G add $::C1
51 G add $::C2
52 G output
53 set {} {}
54 } -test {
55 catch { G delete }
56 faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
57 }
58
59 do_faultsim_test 1.3 -faults oom* -prep {
60 sqlite3changegroup G
61 } -body {
62 G schema db main
63 G change_begin INSERT t1 0
64 G change_int64 new 0 12345
65 G change_int64 new 1 67890
66 G output
67 set {} {}
68 } -test {
69 catch { G delete }
70 faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
71 }
72
73 #-------------------------------------------------------------------------
74 reset_db
75 do_execsql_test 2.0 {
76 CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
77 INSERT INTO t1 VALUES(1, 'one');
78 INSERT INTO t1 VALUES(2, 'two');
79 ALTER TABLE t1 ADD COLUMN c DEFAULT 'abcdefghijklmnopqrstuvwxyz';
80 }
81 faultsim_save_and_close
82
83 do_faultsim_test 2 -faults oom-t* -prep {
84 faultsim_restore_and_reopen
85 db eval {SELECT * FROM sqlite_schema}
86 } -body {
87 sqlite3session S db main
88 S attach *
89 execsql {
90 DELETE FROM t1 WHERE a = 1;
91 }
92 } -test {
93 faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
94 catch { S delete }
95 }
96
97 #-------------------------------------------------------------------------
98 reset_db
99 do_execsql_test 3.0 {
100 CREATE TABLE t1(a PRIMARY KEY, b UNIQUE);
101 INSERT INTO t1 VALUES(1, 'one');
102 INSERT INTO t1 VALUES(2, 'two');
103 INSERT INTO t1 VALUES(3, 'three');
104 INSERT INTO t1 VALUES(4, 'four');
105 INSERT INTO t1 VALUES(5, 'five');
106 }
107 faultsim_save_and_close
108 faultsim_restore_and_reopen
109
110 set C [changeset_from_sql {
111 UPDATE t1 SET b=NULL WHERE a IN (1, 3, 5);
112 UPDATE t1 SET b='three' WHERE a=1;
113 UPDATE t1 SET b='five' WHERE a=3;
114 UPDATE t1 SET b='one' WHERE a=5;
115 }]
116
117 do_execsql_test 3.1 {
118 SELECT * FROM t1
119 } {
120 1 three 2 two 3 five 4 four 5 one
121 }
122
123 proc xConflict {args} {
124 lappend ::conflict_list $args
125 return "OMIT"
126 }
127
128 do_faultsim_test 3 -faults oom* -prep {
129 faultsim_restore_and_reopen
130 db eval {SELECT * FROM sqlite_schema}
131 } -body {
132 sqlite3changeset_apply_v2 db $::C xConflict
133 set {} {}
134 } -test {
135 faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
136 }
137
138 finish_test