3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this script is multithreading behavior
14 # $Id: thread1.test,v 1.8 2008/10/07 15:25:49 drh Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 # Skip this whole file if the thread testing code is not enabled
22 if {[run_thread_tests]==0} { finish_test ; return }
23 if {[llength [info command thread_step]]==0 || [sqlite3 -has-codec]} {
28 # Create some data to work with
33 INSERT INTO t1 VALUES(1,'abcdefgh');
34 INSERT INTO t1 SELECT a+1, b||b FROM t1;
35 INSERT INTO t1 SELECT a+2, b||b FROM t1;
36 INSERT INTO t1 SELECT a+4, b||b FROM t1;
37 SELECT count(*), max(length(b)) FROM t1;
41 # Interleave two threads on read access. Then make sure a third
42 # thread can write the database. In other words:
50 # At one point, the write-lock of C would fail on Linux.
53 thread_create A test.db
54 thread_create B test.db
55 thread_create C test.db
56 thread_compile A {SELECT a FROM t1}
67 thread_compile B {SELECT b FROM t1}
85 do_test thread1-1.10 {
86 thread_compile C {CREATE TABLE t2(x,y)}
90 do_test thread1-1.11 {
94 do_test thread1-1.12 {
95 catchsql {SELECT name FROM sqlite_master}
96 execsql {SELECT name FROM sqlite_master}
101 # The following tests - thread1-2.* - test the following scenario:
103 # 1: Read-lock thread A
104 # 2: Read-lock thread B
105 # 3: Attempt to write in thread C -> SQLITE_BUSY
106 # 4: Check db write failed from main thread.
107 # 5: Unlock from thread A.
108 # 6: Attempt to write in thread C -> SQLITE_BUSY
109 # 7: Check db write failed from main thread.
110 # 8: Unlock from thread B.
111 # 9: Attempt to write in thread C -> SQLITE_DONE
112 # 10: Finalize the write from thread C
113 # 11: Check db write succeeded from main thread.
115 do_test thread1-2.1 {
117 thread_create A test.db
118 thread_compile A {SELECT a FROM t1}
122 do_test thread1-2.2 {
123 thread_create B test.db
124 thread_compile B {SELECT b FROM t1}
128 do_test thread1-2.3 {
129 thread_create C test.db
130 thread_compile C {INSERT INTO t2 VALUES(98,99)}
137 do_test thread1-2.4 {
138 execsql {SELECT * FROM t2}
141 do_test thread1-2.5 {
145 do_test thread1-2.6 {
146 thread_compile C {INSERT INTO t2 VALUES(98,99)}
152 do_test thread1-2.7 {
153 execsql {SELECT * FROM t2}
155 do_test thread1-2.8 {
159 do_test thread1-2.9 {
160 thread_compile C {INSERT INTO t2 VALUES(98,99)}
164 do_test thread1-2.10 {
168 do_test thread1-2.11 {
169 execsql {SELECT * FROM t2}