2 #pragma ident "%Z%%M% %I% %E% SMI"
6 # The author disclaims copyright to this source code. In place of
7 # a legal notice, here is a blessing:
9 # May you do good and not evil.
10 # May you find forgiveness for yourself and forgive others.
11 # May you share freely, never taking more than you give.
13 #***********************************************************************
14 # This file implements regression tests for SQLite library. The
15 # focus of this script is multithreading behavior
17 # $Id: thread1.test,v 1.3 2004/02/11 02:18:07 drh Exp $
20 set testdir [file dirname $argv0]
21 source $testdir/tester.tcl
23 # Skip this whole file if the thread testing code is not enabled
25 if {[llength [info command thread_step]]==0 || [sqlite -has-codec]} {
30 # Create some data to work with
35 INSERT INTO t1 VALUES(1,'abcdefgh');
36 INSERT INTO t1 SELECT a+1, b||b FROM t1;
37 INSERT INTO t1 SELECT a+2, b||b FROM t1;
38 INSERT INTO t1 SELECT a+4, b||b FROM t1;
39 SELECT count(*), max(length(b)) FROM t1;
43 # Interleave two threads on read access. Then make sure a third
44 # thread can write the database. In other words:
52 # At one point, the write-lock of C would fail on Linux.
55 thread_create A test.db
56 thread_create B test.db
57 thread_create C test.db
58 thread_compile A {SELECT a FROM t1}
69 thread_compile B {SELECT b FROM t1}
87 do_test thread1-1.10 {
88 thread_compile C {CREATE TABLE t2(x,y)}
92 do_test thread1-1.11 {
96 do_test thread1-1.12 {
97 catchsql {SELECT name FROM sqlite_master}
98 execsql {SELECT name FROM sqlite_master}
102 # Under this scenario:
109 # Make sure the write-lock fails with SQLITE_BUSY
111 do_test thread1-2.1 {
113 thread_create A test.db
114 thread_compile A {SELECT a FROM t1}
118 do_test thread1-2.2 {
119 thread_create B test.db
120 thread_compile B {SELECT b FROM t1}
124 do_test thread1-2.3 {
125 thread_create C test.db
126 thread_compile C {INSERT INTO t2 VALUES(98,99)}
130 do_test thread1-2.4 {
131 execsql {SELECT * FROM t2}
133 do_test thread1-2.5 {
137 do_test thread1-2.6 {
141 do_test thread1-2.7 {
142 execsql {SELECT * FROM t2}
144 do_test thread1-2.8 {
148 do_test thread1-2.9 {
152 do_test thread1-2.10 {
153 execsql {SELECT * FROM t2}
155 do_test thread1-2.11 {