Add further tests for rollback operations in the presence of ongoing selects.

FossilOrigin-Name: eaf3aae014f59c8d37aa20aa31d54cf13f9e86fc
This commit is contained in:
dan 2014-11-12 17:45:37 +00:00
parent 8023104252
commit d7b06909ad
4 changed files with 177 additions and 9 deletions

View File

@ -1,5 +1,5 @@
C When\sa\stransaction\sor\ssavepoint\srollback\soccurs,\ssave\sthe\spositions\sof\sall\sopen\sread-cursors\sso\sthat\sthey\scan\sbe\srestored\sfollowing\sthe\srollback\soperation.
D 2014-11-12T14:56:02.923
C Add\sfurther\stests\sfor\srollback\soperations\sin\sthe\spresence\sof\songoing\sselects.
D 2014-11-12T17:45:37.113
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in a226317fdf3f4c895fb3cfedc355b4d0868ce1fb
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -797,7 +797,8 @@ F test/releasetest.mk 2eced2f9ae701fd0a29e714a241760503ccba25a
F test/releasetest.tcl a4279c890698584feb2ffc86735857a4e4474180
F test/resolver01.test 33abf37ff8335e6bf98f2b45a0af3e06996ccd9a
F test/rollback.test 458fe73eb3ffdfdf9f6ba3e9b7350a6220414dea
F test/rollback2.test 552abaab8e721b6060a727d639896427059e51ec
F test/rollback2.test fc14cf6d1a2b250d2735ef16124b971bce152f14
F test/rollbackfault.test 6a004f71087cc399296cffbb5429ea6da655ae65
F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81
F test/rowid.test 742b5741584a8a44fd83e856cc2896688401d645
F test/rtree.test 0c8d9dd458d6824e59683c19ab2ffa9ef946f798
@ -1219,7 +1220,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 1412fcc480799ecbd68d44dd18d5bad40e20ccf1
R 668a86f911283b47b6c156fecf772681
P dd03a2802f3f276525f3cef9a93f825dd8606626
R c0a8c133338658022754212d7071964f
U dan
Z cf8e25329461439611751d7913ef3ef9
Z c8dc7391cf2e61af731936b53ad2fd87

View File

@ -1 +1 @@
dd03a2802f3f276525f3cef9a93f825dd8606626
eaf3aae014f59c8d37aa20aa31d54cf13f9e86fc

View File

@ -9,6 +9,9 @@
#
#***********************************************************************
#
# This file containst tests to verify that ROLLBACK or ROLLBACK TO
# operations interact correctly with ongoing SELECT statements.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -16,7 +19,6 @@ set ::testprefix rollback2
proc int2hex {i} { format %.2X $i }
db func int2hex int2hex
do_execsql_test 1.0 {
SELECT int2hex(0), int2hex(100), int2hex(255)
} {00 64 FF}
@ -32,6 +34,17 @@ do_execsql_test 1.1 {
} {}
# do_rollback_test ID SWITCHES
#
# where SWITCHES are:
#
# -setup SQL script to open transaction and begin writing.
# -select SELECT to execute after -setup script
# -result Expected result of -select statement
# -rollback Use this SQL command ("ROLLBACK" or "ROLLBACK TO ...") to
# rollback the transaction in the middle of the -select statment
# execution.
#
proc do_rollback_test {tn args} {
set A(-setup) ""
set A(-select) ""
@ -61,7 +74,7 @@ proc do_rollback_test {tn args} {
}
}
do_rollback_test 2 -setup {
do_rollback_test 2.1 -setup {
BEGIN;
DELETE FROM t1 WHERE (i%2)==1;
} -select {
@ -70,5 +83,75 @@ do_rollback_test 2 -setup {
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
}
do_rollback_test 2.2 -setup {
BEGIN;
DELETE FROM t1 WHERE (i%4)==1;
SAVEPOINT one;
DELETE FROM t1 WHERE (i%2)==1;
} -rollback {
ROLLBACK TO one;
} -select {
SELECT i FROM t1 WHERE (i%2)==0
} -result {
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
}
#--------------------------------------------------------------------
# Try with some index scans
#
do_eqp_test 3.1 {
SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h DESC;
} {0 0 0 {SCAN TABLE t1 USING INDEX i1}}
do_rollback_test 3.2 -setup {
BEGIN;
DELETE FROM t1 WHERE (i%2)==1;
} -select {
SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h DESC;
} -result {
40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2
}
do_rollback_test 3.3 -setup {
BEGIN;
DELETE FROM t1 WHERE (i%4)==1;
SAVEPOINT one;
DELETE FROM t1 WHERE (i%2)==1;
} -rollback {
ROLLBACK TO one;
} -select {
SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h DESC;
} -result {
40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2
}
#--------------------------------------------------------------------
# Now with some index scans that feature overflow keys.
#
set leader [string repeat "abcdefghij" 70]
do_execsql_test 4.1 { UPDATE t1 SET h = $leader || h; }
do_eqp_test 4.2 {
SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h ASC;
} {0 0 0 {SCAN TABLE t1 USING INDEX i1}}
do_rollback_test 4.3 -setup {
BEGIN;
DELETE FROM t1 WHERE (i%2)==1;
} -select {
SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h ASC;
} -result {
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
}
do_rollback_test 4.4 -setup {
BEGIN;
DELETE FROM t1 WHERE (i%4)==1;
SAVEPOINT one;
DELETE FROM t1 WHERE (i%2)==1;
} -rollback {
ROLLBACK TO one;
} -select {
SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h ASC;
} -result {
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
}
finish_test

84
test/rollbackfault.test Normal file
View File

@ -0,0 +1,84 @@
# 2014-11-12
#
# 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.
#
#***********************************************************************
#
# Test that errors encountered during a ROLLBACK operation correctly
# affect ongoing SQL statements.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/malloc_common.tcl
set testprefix rollbackfault
proc int2hex {i} { format %.2X $i }
db func int2hex int2hex
do_execsql_test 1.0 {
SELECT int2hex(0), int2hex(100), int2hex(255)
} {00 64 FF}
do_execsql_test 1.1 {
CREATE TABLE t1(i, h);
CREATE INDEX i1 ON t1(h);
WITH data(a, b) AS (
SELECT 1, int2hex(1)
UNION ALL
SELECT a+1, int2hex(a+1) FROM data WHERE a<40
)
INSERT INTO t1 SELECT * FROM data;
} {}
foreach f {oom ioerr} {
do_faultsim_test 1.2 -faults $f* -prep {
set sql1 { SELECT i FROM t1 WHERE (i%2)==0 }
set sql2 { SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h }
set ::s1 [sqlite3_prepare db $sql1 -1 dummy]
set ::s2 [sqlite3_prepare db $sql2 -1 dummy]
for {set i 0} {$i < 10} {incr i} { sqlite3_step $::s1 }
for {set i 0} {$i < 3} {incr i} { sqlite3_step $::s2 }
execsql {
BEGIN; DELETE FROM t1 WHERE (i%2)
}
} -body {
execsql { ROLLBACK }
} -test {
set res1 [list]
set res2 [list]
while {"SQLITE_ROW" == [sqlite3_step $::s1]} {
lappend res1 [sqlite3_column_text $::s1 0]
}
while {"SQLITE_ROW" == [sqlite3_step $::s2]} {
lappend res2 [sqlite3_column_text $::s2 0]
}
set rc1 [sqlite3_finalize $::s1]
set rc2 [sqlite3_finalize $::s2]
catchsql { ROLLBACK }
if {$rc1=="SQLITE_OK" && $rc2=="SQLITE_OK"
&& $res1=="22 24 26 28 30 32 34 36 38 40"
&& $res2=="8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40"
} {
# This is Ok.
} elseif {$rc1!="SQLITE_OK" && $rc2!="SQLITE_OK" && $res1=="" &&$res2==""} {
# Also Ok.
} else {
error "statements don't look right"
}
}
}
finish_test