From: danielk1977 Date: Fri, 20 Mar 2009 15:16:05 +0000 (+0000) Subject: Add a test to try to hit the race-condition fixed by (6363). (CVS 6366) X-Git-Tag: version-3.6.15~384 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b31b211c3839900f04e459cd423f940682d66ba;p=thirdparty%2Fsqlite.git Add a test to try to hit the race-condition fixed by (6363). (CVS 6366) FossilOrigin-Name: 4310411f5027dba18e017023e21cb09982e26752 --- diff --git a/manifest b/manifest index ecbe33ea32..c691926fa6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sassert\sfailure\sintroduced\sby\s(6355).\s(CVS\s6365) -D 2009-03-20T14:42:11 +C Add\sa\stest\sto\stry\sto\shit\sthe\srace-condition\sfixed\sby\s(6363).\s(CVS\s6366) +D 2009-03-20T15:16:06 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -561,7 +561,7 @@ F test/thread001.test 06c45ed9597d478e7bbdc2a8937e1ebea2a20a32 F test/thread002.test 4338c3d7c5f2f781adc3dba956dfd92722397408 F test/thread003.test a8bc91af1d9d524148dd84e4d6a196ba17521e08 F test/thread004.test 9d8ea6a9b0d62d35ad0b967e010d723ed99f614a -F test/thread005.test ffe656387fd77bfc674eff08c268efc2f789c4bd +F test/thread005.test 555f8a37bd552dbb01f2e3ecb20b2832afa5fa27 F test/thread1.test 862dd006d189e8b0946935db17399dcac2f8ef91 F test/thread2.test 91f105374f18a66e73a3254c28fe7c77af69bdea F test/thread_common.tcl bde5a0faa9fc57e24140483d512718d72bfc42e2 @@ -709,7 +709,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 093a0cf4adc8613f744c2ccdef61f0b30a46818c -R 8085b31e0c8618fcfa2324af9c4bb501 +P a08324d16d1e9a4e7c1b294bc71fc939d173f826 +R 87fff081bb6bfc825b1acb6eabea142e U danielk1977 -Z ead312bd28ad877405ab99a1bca5833f +Z 5f0bd3312fbc59ec4534315ac49a7c31 diff --git a/manifest.uuid b/manifest.uuid index 3526b6921c..259c523a02 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a08324d16d1e9a4e7c1b294bc71fc939d173f826 \ No newline at end of file +4310411f5027dba18e017023e21cb09982e26752 \ No newline at end of file diff --git a/test/thread005.test b/test/thread005.test index f40e182a24..644c1021f8 100644 --- a/test/thread005.test +++ b/test/thread005.test @@ -11,7 +11,7 @@ # # Test a race-condition that shows up in shared-cache mode. # -# $Id: thread005.test,v 1.3 2009/03/20 10:24:04 danielk1977 Exp $ +# $Id: thread005.test,v 1.4 2009/03/20 15:16:06 danielk1977 Exp $ set testdir [file dirname $argv0] @@ -23,6 +23,55 @@ source $testdir/thread_common.tcl if {[info commands sqlthread] eq ""} { return } +db close + +# Use shared-cache mode for these tests. +# +set ::enable_shared_cache [sqlite3_enable_shared_cache] +sqlite3_enable_shared_cache 1 + +#------------------------------------------------------------------------- +# This test attempts to hit the race condition fixed by commit [6363]. +# +proc runsql {zSql {db {}}} { + set rc SQLITE_OK + while {$rc=="SQLITE_OK" && $zSql ne ""} { + set STMT [sqlite3_prepare_v2 $db $zSql -1 zSql] + while {[set rc [sqlite3_step $STMT]] eq "SQLITE_ROW"} { } + set rc [sqlite3_finalize $STMT] + } + return $rc +} +do_test thread005-1.1 { + sqlite3 db test.db + db eval { CREATE TABLE t1(a, b) } + db close +} {} +for {set ii 2} {$ii < 500} {incr ii} { + unset -nocomplain finished + thread_spawn finished(0) {sqlite3_open test.db} + thread_spawn finished(1) {sqlite3_open test.db} + if {![info exists finished(0)]} { vwait finished(0) } + if {![info exists finished(1)]} { vwait finished(1) } + + do_test thread005-1.$ii { + runsql { BEGIN } $finished(0) + runsql { INSERT INTO t1 VALUES(1, 2) } $finished(0) + + # If the race-condition was hit, then $finished(0 and $finished(1) + # will not use the same pager cache. In this case the next statement + # can be executed succesfully. However, if the race-condition is not + # hit, then $finished(1) will be blocked by the write-lock held by + # $finished(0) on the shared-cache table t1 and the statement will + # return SQLITE_LOCKED. + # + runsql { SELECT * FROM t1 } $finished(1) + } {SQLITE_LOCKED} + + sqlite3_close $finished(0) + sqlite3_close $finished(1) +} + #------------------------------------------------------------------------- # This test tries to exercise a race-condition that existed in shared-cache @@ -73,16 +122,10 @@ if {[info commands sqlthread] eq ""} { # switch or something... # -# Use shared-cache mode for this test. -# -db close -set ::enable_shared_cache [sqlite3_enable_shared_cache] -sqlite3_enable_shared_cache 1 - file delete -force test.db test2.db unset -nocomplain finished -do_test thread005-1.1 { +do_test thread005-2.1 { sqlite3 db test.db execsql { ATTACH 'test2.db' AS aux } execsql { @@ -182,11 +225,11 @@ if {![info exists finished(1)]} { vwait finished(1) } catch { db close } catch { db2 close } -do_test thread005-1.2 { +do_test thread005-2.2 { list $finished(0) $finished(1) } {ok ok} -do_test thread005-1.3 { +do_test thread005-2.3 { sqlite3 db test.db execsql { ATTACH 'test2.db' AS aux } execsql { SELECT count(*) FROM t1 WHERE b IS NULL }