aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/quick.test3
-rw-r--r--test/thread004.test80
2 files changed, 82 insertions, 1 deletions
diff --git a/test/quick.test b/test/quick.test
index c27f1d23f..4d8dca6e8 100644
--- a/test/quick.test
+++ b/test/quick.test
@@ -6,7 +6,7 @@
#***********************************************************************
# This file runs all tests.
#
-# $Id: quick.test,v 1.92 2009/02/03 16:51:25 danielk1977 Exp $
+# $Id: quick.test,v 1.93 2009/02/26 07:15:59 danielk1977 Exp $
proc lshift {lvar} {
upvar $lvar l
@@ -85,6 +85,7 @@ set EXCLUDE {
thread001.test
thread002.test
thread003.test
+ thread004.test
trans2.test
vacuum3.test
diff --git a/test/thread004.test b/test/thread004.test
new file mode 100644
index 000000000..5931e4b8b
--- /dev/null
+++ b/test/thread004.test
@@ -0,0 +1,80 @@
+# 2009 February 26
+#
+# 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: thread004.test,v 1.1 2009/02/26 07:15:59 danielk1977 Exp $
+
+set testdir [file dirname $argv0]
+
+source $testdir/tester.tcl
+ifcapable !mutex||!shared_cache {
+ return
+}
+source $testdir/thread_common.tcl
+if {[info commands sqlthread] eq ""
+ || [info commands sqlite3_table_column_metadata] eq ""
+} {
+ return
+}
+
+# Use shared-cache mode for this test.
+#
+db close
+set ::enable_shared_cache [sqlite3_enable_shared_cache]
+sqlite3_enable_shared_cache 1
+
+# Create a table in database test.db
+#
+sqlite3 db test.db
+do_test thread004-1.1 {
+ execsql { CREATE TABLE t1(a, b, c) }
+} {}
+
+do_test thread004-1.2 {
+
+ set ThreadOne {
+ set iStart [clock_seconds]
+ while {[clock_seconds]<$iStart+20} {
+ set ::DB [sqlite3_open test.db]
+ sqlite3_close $::DB
+ }
+ }
+ set ThreadTwo {
+ set ::DB [sqlite3_open test.db]
+ set iStart [clock_seconds]
+ set nErr 0
+ while {[clock_seconds] <$iStart+20} {
+ incr nErr [catch {sqlite3_table_column_metadata $::DB main t1 a}]
+ }
+ sqlite3_close $::DB
+ set nErr
+ }
+
+ # Run two threads. The first thread opens and closes database test.db
+ # repeatedly. Each time this happens, the in-memory schema used by
+ # all connections to test.db is discarded.
+ #
+ # The second thread calls sqlite3_table_column_metadata() over and
+ # over again. Each time it is called, the database schema is loaded
+ # if it is not already in memory. At one point this was crashing.
+ #
+ unset -nocomplain finished
+ thread_spawn finished(1) $thread_procs $ThreadOne
+ thread_spawn finished(2) $thread_procs $ThreadTwo
+
+ foreach t {1 2} {
+ if {![info exists finished($t)]} { vwait finished($t) }
+ }
+
+ set finished(2)
+} {0}
+sqlite3_enable_shared_cache $::enable_shared_cache
+finish_test
+