mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Enhance thread001.test again, this time to also test in shared-cache mode. (CVS 4418)
FossilOrigin-Name: 54f87899033ddd892bfd3a16310f64fb42d807ae
This commit is contained in:
@ -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
70
test/thread_common.tcl
Normal 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
|
Reference in New Issue
Block a user