Enhance thread001.test again, this time to also test in shared-cache mode. (CVS 4418)

FossilOrigin-Name: 54f87899033ddd892bfd3a16310f64fb42d807ae
This commit is contained in:
danielk1977 2007-09-10 07:35:47 +00:00
parent d9b5b1177d
commit 49e439d934
4 changed files with 103 additions and 56 deletions

View File

@ -1,5 +1,5 @@
C Upgrade\sthread001.test\sto\stest\swith\smultiple\sdatabase\shandles.\s(CVS\s4417)
D 2007-09-10T06:23:54
C Enhance\sthread001.test\sagain,\sthis\stime\sto\salso\stest\sin\sshared-cache\smode.\s(CVS\s4418)
D 2007-09-10T07:35:47
F Makefile.in cbfb898945536a8f9ea8b897e1586dd1fdbcc5db
F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -425,9 +425,10 @@ F test/tableapi.test 036575a98dcce7c92e9f39056839bbad8a715412
F test/tclsqlite.test a868898e3350246be7ea132621dc25f9835b3030
F test/temptable.test c36f3e5a94507abb64f7ba23deeb4e1a8a8c3821
F test/tester.tcl 913a808f05b0aed2fbb16481a423b1a5a118bdf0
F test/thread001.test 956b80909cbec7cf2f2540bf1c8bb573052f0868
F test/thread001.test 8fbd9559da0bbdc273e00318c7fd66c162020af7
F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
F test/thread2.test 6d7b30102d600f51b4055ee3a5a19228799049fb
F test/thread_common.tcl 95b11a3f42df7cba82e0c8feb8a70d339aaad4cb
F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
F test/threadtest2.c ace893054fa134af3fc8d6e7cfecddb8e3acefb9
F test/tkt1435.test f8c52c41de6e5ca02f1845f3a46e18e25cadac00
@ -573,7 +574,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P 48e59c747f2be08102f16290fa57dfffc2ae920d
R e7956c3743bdd54859507fb25353105c
P 6ee2b8ffc4310c8e329f634f3ade058b33c53a2a
R 59e1b6472478b1b0d4fb7b3646b47885
U danielk1977
Z 0ed31afa9b04e141d583b88b37a43f9c
Z f03978abade17ec790e2c8c978d82d62

View File

@ -1 +1 @@
6ee2b8ffc4310c8e329f634f3ade058b33c53a2a
54f87899033ddd892bfd3a16310f64fb42d807ae

View File

@ -9,69 +9,45 @@
#
#***********************************************************************
#
# $Id: thread001.test,v 1.3 2007/09/10 06:23:54 danielk1977 Exp $
# $Id: thread001.test,v 1.4 2007/09/10 07:35:47 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/tester.tcl
source $testdir/thread_common.tcl
if {[info commands sqlthread] eq ""} {
puts -nonewline "Skipping thread-safety tests - "
puts " not running a threadsafe sqlite/tcl build"
puts -nonewline "Both SQLITE_THREADSAFE and TCL_THREADS must be defined when"
puts " building testfixture"
finish_test
return
}
set ::NTHREAD 10
# The following script is sourced by every thread spawned using
# [sqlthread spawn]:
set thread_procs {
# Execute the supplied SQL using database handle $::DB.
#
proc execsql {sql} {
set res [list]
set ::STMT [sqlite3_prepare $::DB $sql -1 dummy_tail]
while {[sqlite3_step $::STMT] eq "SQLITE_ROW"} {
for {set i 0} {$i < [sqlite3_column_count $::STMT]} {incr i} {
lappend res [sqlite3_column_text $::STMT 0]
}
}
set rc [sqlite3_finalize $::STMT]
if {$rc ne "SQLITE_OK"} {
error [sqlite3_errmsg $::DB]
}
set res
}
proc do_test {name script result} {
set res [eval $script]
if {$res ne $result} {
error "$name failed: expected \"$result\" got \"$res\""
}
}
}
proc thread_spawn {varname args} {
sqlthread spawn $varname [join $args ;]
}
#########################################################################
# End of infrastruture. Start of test cases.
#########################################################################
# Run this test twice: Once with all threads using the same database
# connection, and once with each using it's own connection.
# Run this test three times:
#
# 1) All threads use the same database handle.
# 2) All threads use their own database handles.
# 3) All threads use their own database handles, shared-cache is enabled.
#
foreach {dbconfig tn} [list "set ::DB $::DB" 1 "" 2] {
foreach {tn same_db shared_cache} [list \
1 1 0 \
2 0 0 \
3 0 1 \
] {
# Empty the database.
#
catchsql { DROP TABLE ab; }
do_test thread001.$tn.0 {
db close
sqlite3_enable_shared_cache $shared_cache
sqlite3_enable_shared_cache $shared_cache
} $shared_cache
sqlite3 db test.db
set dbconfig ""
if {$same_db} {
set dbconfig [list set ::DB [sqlite3_connection_pointer db]]
}
# Set up a database and a schema. The database contains a single
# table with two columns. The first column ("a") is an INTEGER PRIMARY
# KEY. The second contains the md5sum of all rows in the table with

70
test/thread_common.tcl Normal file
View File

@ -0,0 +1,70 @@
# 2007 September 10
#
# 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.
#
#***********************************************************************
#
# $Id: thread_common.tcl,v 1.1 2007/09/10 07:35:47 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
if {[info commands sqlthread] eq ""} {
puts -nonewline "Skipping thread-safety tests - "
puts " not running a threadsafe sqlite/tcl build"
puts -nonewline "Both SQLITE_THREADSAFE and TCL_THREADS must be defined when"
puts " building testfixture"
finish_test
return
}
set ::NTHREAD 10
# The following script is sourced by every thread spawned using
# [sqlthread spawn]:
set thread_procs {
# Execute the supplied SQL using database handle $::DB.
#
proc execsql {sql} {
set rc SQLITE_LOCKED
while {$rc eq "SQLITE_LOCKED"} {
set res [list]
set ::STMT [sqlite3_prepare $::DB $sql -1 dummy_tail]
while {[set rc [sqlite3_step $::STMT]] eq "SQLITE_ROW"} {
for {set i 0} {$i < [sqlite3_column_count $::STMT]} {incr i} {
lappend res [sqlite3_column_text $::STMT 0]
}
}
set rc [sqlite3_finalize $::STMT]
if {$rc eq "SQLITE_LOCKED"} {
after 20
}
}
if {$rc ne "SQLITE_OK"} {
error "$rc - [sqlite3_errmsg $::DB]"
}
set res
}
proc do_test {name script result} {
set res [eval $script]
if {$res ne $result} {
error "$name failed: expected \"$result\" got \"$res\""
}
}
}
proc thread_spawn {varname args} {
sqlthread spawn $varname [join $args ;]
}
return 0