Annotation of embedaddon/sqlite3/test/thread2.test, revision 1.1.1.1
1.1 misho 1: # 2006 January 14
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: thread2.test,v 1.3 2008/10/07 15:25:49 drh Exp $
15:
16:
17: set testdir [file dirname $argv0]
18: source $testdir/tester.tcl
19:
20: if {[run_thread_tests]==0} { finish_test ; return }
21:
22: # Skip this whole file if the thread testing code is not enabled
23: #
24: if {[llength [info command thread_step]]==0 || [sqlite3 -has-codec]} {
25: finish_test
26: return
27: }
28:
29: # Create some data to work with
30: #
31: do_test thread1-1.1 {
32: execsql {
33: CREATE TABLE t1(a,b);
34: INSERT INTO t1 VALUES(1,'abcdefgh');
35: INSERT INTO t1 SELECT a+1, b||b FROM t1;
36: INSERT INTO t1 SELECT a+2, b||b FROM t1;
37: INSERT INTO t1 SELECT a+4, b||b FROM t1;
38: SELECT count(*), max(length(b)) FROM t1;
39: }
40: } {8 64}
41:
42: # Use the thread_swap command to move the database connections between
43: # threads, then verify that they still work.
44: #
45: do_test thread2-1.2 {
46: db close
47: thread_create A test.db
48: thread_create B test.db
49: thread_swap A B
50: thread_compile A {SELECT a FROM t1 LIMIT 1}
51: thread_result A
52: } {SQLITE_OK}
53: do_test thread2-1.3 {
54: thread_step A
55: thread_result A
56: } {SQLITE_ROW}
57: do_test thread2-1.4 {
58: thread_argv A 0
59: } {1}
60: do_test thread2-1.5 {
61: thread_finalize A
62: thread_result A
63: } {SQLITE_OK}
64: do_test thread2-1.6 {
65: thread_compile B {SELECT a FROM t1 LIMIT 1}
66: thread_result B
67: } {SQLITE_OK}
68: do_test thread2-1.7 {
69: thread_step B
70: thread_result B
71: } {SQLITE_ROW}
72: do_test thread2-1.8 {
73: thread_argv B 0
74: } {1}
75: do_test thread2-1.9 {
76: thread_finalize B
77: thread_result B
78: } {SQLITE_OK}
79:
80: # Swap them again.
81: #
82: do_test thread2-2.2 {
83: thread_swap A B
84: thread_compile A {SELECT a FROM t1 LIMIT 1}
85: thread_result A
86: } {SQLITE_OK}
87: do_test thread2-2.3 {
88: thread_step A
89: thread_result A
90: } {SQLITE_ROW}
91: do_test thread2-2.4 {
92: thread_argv A 0
93: } {1}
94: do_test thread2-2.5 {
95: thread_finalize A
96: thread_result A
97: } {SQLITE_OK}
98: do_test thread2-2.6 {
99: thread_compile B {SELECT a FROM t1 LIMIT 1}
100: thread_result B
101: } {SQLITE_OK}
102: do_test thread2-2.7 {
103: thread_step B
104: thread_result B
105: } {SQLITE_ROW}
106: do_test thread2-2.8 {
107: thread_argv B 0
108: } {1}
109: do_test thread2-2.9 {
110: thread_finalize B
111: thread_result B
112: } {SQLITE_OK}
113: thread_halt A
114: thread_halt B
115:
116: # Also important to halt the worker threads, which are using spin
117: # locks and eating away CPU cycles.
118: #
119: thread_halt *
120: finish_test
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>