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 # The focus of this file is testing the session module.
15 if {![info exists testdir]} {
16 set testdir [file join [file dirname [info script]] .. .. test]
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 sessionfault2
23 do_execsql_test 1.0.0 {
24 CREATE TABLE t1(a PRIMARY KEY, b UNIQUE);
25 INSERT INTO t1 VALUES(1, 1);
26 INSERT INTO t1 VALUES(2, 2);
27 INSERT INTO t1 VALUES(3, 3);
29 CREATE TABLE t2(a PRIMARY KEY, b UNIQUE);
30 INSERT INTO t2 VALUES(1, 1);
31 INSERT INTO t2 VALUES(2, 2);
32 INSERT INTO t2 VALUES(3, 3);
34 faultsim_save_and_close
36 faultsim_restore_and_reopen
38 set ::C [changeset_from_sql {
39 UPDATE t1 SET b=4 WHERE a=3;
40 UPDATE t1 SET b=3 WHERE a=2;
41 UPDATE t1 SET b=2 WHERE a=1;
42 UPDATE t2 SET b=0 WHERE a=1;
43 UPDATE t2 SET b=1 WHERE a=2;
44 UPDATE t2 SET b=2 WHERE a=3;
49 proc xConflict args { return "OMIT" }
51 do_faultsim_test 1 -faults oom-p* -prep {
52 faultsim_restore_and_reopen
54 sqlite3changeset_apply db $::C xConflict
56 faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
57 faultsim_integrity_check
59 catch { db eval ROLLBACK }
66 if {$res != "1 2 2 3 3 4 1 0 2 1 3 2"} { error "data error" }
69 $res != "1 2 2 3 3 4 1 0 2 1 3 2"
70 && $res != "1 1 2 2 3 3 1 1 2 2 3 3"
71 } { error "data error!! $res" }
75 #-------------------------------------------------------------------------
76 # OOM when applying a changeset for which one of the tables has a name
77 # 99 bytes in size. This happens to cause an extra malloc in within the
78 # sessions_strm permutation.
81 set nm [string repeat t 99]
82 do_execsql_test 2.0.0 [string map "%TBL% $nm" {
83 CREATE TABLE %TBL%(a PRIMARY KEY, b UNIQUE);
85 faultsim_save_and_close
87 faultsim_restore_and_reopen
89 set ::C [changeset_from_sql [string map "%TBL% $nm" {
90 INSERT INTO %TBL% VALUES(1, 2);
91 INSERT INTO %TBL% VALUES(3, 4);
96 proc xConflict args { return "OMIT" }
97 do_faultsim_test 2 -faults oom-p* -prep {
98 faultsim_restore_and_reopen
100 sqlite3changeset_apply db $::C xConflict
102 faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
103 faultsim_integrity_check