-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathsessionfault3.test
More file actions
138 lines (123 loc) · 3.24 KB
/
Copy pathsessionfault3.test
File metadata and controls
138 lines (123 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# 2016 October 6
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
# The focus of this file is testing the session module.
#
if {![info exists testdir]} {
set testdir [file join [file dirname [info script]] .. .. test]
}
source [file join [file dirname [info script]] session_common.tcl]
source $testdir/tester.tcl
ifcapable !session {finish_test; return}
set testprefix sessionfault3
do_execsql_test 1.0 {
CREATE TABLE t1(a, b, PRIMARY KEY(a));
INSERT INTO t1 VALUES(1, 2);
INSERT INTO t1 VALUES(3, 4);
INSERT INTO t1 VALUES('five', 'six');
}
set C1 [changeset_from_sql {
INSERT INTO t1 VALUES('seven', 'eight');
UPDATE t1 SET b=6 WHERE a='five';
DELETE FROM t1 WHERE a=1;
}]
do_execsql_test 1.1 {
ALTER TABLE t1 ADD COLUMN d DEFAULT 123;
ALTER TABLE t1 ADD COLUMN e DEFAULT 'string';
}
set C2 [changeset_from_sql {
UPDATE t1 SET e='new value' WHERE a='seven';
INSERT INTO t1 VALUES(0, 0, 0, 0);
}]
do_faultsim_test 1.2 -faults oom* -prep {
sqlite3changegroup G
} -body {
G schema db main
G add $::C1
G add $::C2
G output
set {} {}
} -test {
catch { G delete }
faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
}
do_faultsim_test 1.3 -faults oom* -prep {
sqlite3changegroup G
} -body {
G schema db main
G change_begin INSERT t1 0
G change_int64 new 0 12345
G change_int64 new 1 67890
G output
set {} {}
} -test {
catch { G delete }
faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
INSERT INTO t1 VALUES(1, 'one');
INSERT INTO t1 VALUES(2, 'two');
ALTER TABLE t1 ADD COLUMN c DEFAULT 'abcdefghijklmnopqrstuvwxyz';
}
faultsim_save_and_close
do_faultsim_test 2 -faults oom-t* -prep {
faultsim_restore_and_reopen
db eval {SELECT * FROM sqlite_schema}
} -body {
sqlite3session S db main
S attach *
execsql {
DELETE FROM t1 WHERE a = 1;
}
} -test {
faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
catch { S delete }
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 3.0 {
CREATE TABLE t1(a PRIMARY KEY, b UNIQUE);
INSERT INTO t1 VALUES(1, 'one');
INSERT INTO t1 VALUES(2, 'two');
INSERT INTO t1 VALUES(3, 'three');
INSERT INTO t1 VALUES(4, 'four');
INSERT INTO t1 VALUES(5, 'five');
}
faultsim_save_and_close
faultsim_restore_and_reopen
set C [changeset_from_sql {
UPDATE t1 SET b=NULL WHERE a IN (1, 3, 5);
UPDATE t1 SET b='three' WHERE a=1;
UPDATE t1 SET b='five' WHERE a=3;
UPDATE t1 SET b='one' WHERE a=5;
}]
do_execsql_test 3.1 {
SELECT * FROM t1
} {
1 three 2 two 3 five 4 four 5 one
}
proc xConflict {args} {
lappend ::conflict_list $args
return "OMIT"
}
do_faultsim_test 3 -faults oom* -prep {
faultsim_restore_and_reopen
db eval {SELECT * FROM sqlite_schema}
} -body {
sqlite3changeset_apply_v2 db $::C xConflict
set {} {}
} -test {
faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
}
finish_test