xref: /sqlite-3.40.0/test/thread1.test (revision a6064dcf)
1# 2003 December 18
2#
3# The author disclaims copyright to this source code.  In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11# This file implements regression tests for SQLite library.  The
12# focus of this script is multithreading behavior
13#
14# $Id: thread1.test,v 1.1 2003/12/19 02:52:09 drh Exp $
15
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20# Skip this whole file if the thread testing code is not enabled
21#
22if {[llength [info command thread_step]]==0} {
23  finish_test
24  return
25}
26
27# Create some data to work with
28#
29do_test thread1-1.1 {
30  execsql {
31    CREATE TABLE t1(a,b);
32    INSERT INTO t1 VALUES(1,'abcdefgh');
33    INSERT INTO t1 SELECT a+1, b||b FROM t1;
34    INSERT INTO t1 SELECT a+2, b||b FROM t1;
35    INSERT INTO t1 SELECT a+4, b||b FROM t1;
36    SELECT count(*), max(length(b)) FROM t1;
37  }
38} {8 64}
39
40# Interleave two threads on read access.  Then make sure a third
41# thread can write the database.
42#
43do_test thread1-1.2 {
44  thread_create A test.db
45  thread_create B test.db
46  thread_create C test.db
47  thread_compile A {SELECT a FROM t1}
48  thread_step A
49  thread_result A
50} SQLITE_ROW
51do_test thread1-1.3 {
52  thread_argc A
53} 1
54do_test thread1-1.4 {
55  thread_argv A 0
56} 1
57do_test thread1-1.5 {
58  thread_compile B {SELECT b FROM t1}
59  thread_step B
60  thread_result B
61} SQLITE_ROW
62do_test thread1-1.6 {
63  thread_argc B
64} 1
65do_test thread1-1.7 {
66  thread_argv B 0
67} abcdefgh
68do_test thread1-1.8 {
69  thread_finalize A
70  thread_result A
71} SQLITE_OK
72do_test thread1-1.9 {
73  thread_finalize B
74  thread_result B
75} SQLITE_OK
76do_test thread1-1.10 {
77  thread_compile C {CREATE TABLE t2(x,y)}
78  thread_step C
79  thread_result C
80} SQLITE_DONE
81do_test thread1-1.11 {
82  thread_finalize C
83  thread_result C
84} SQLITE_OK
85
86
87thread_halt *
88finish_test
89