interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / thread2.test

120 lines · 2708 bytes Raw Blame History
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
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20if {[run_thread_tests]==0} { finish_test ; return }
21
22# Skip this whole file if the thread testing code is not enabled
23#
24if {[llength [info command thread_step]]==0 || [sqlite3 -has-codec]} {
25 finish_test
26 return
27}
28
29# Create some data to work with
30#
31do_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#
45do_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}
53do_test thread2-1.3 {
54 thread_step A
55 thread_result A
56} {SQLITE_ROW}
57do_test thread2-1.4 {
58 thread_argv A 0
59} {1}
60do_test thread2-1.5 {
61 thread_finalize A
62 thread_result A
63} {SQLITE_OK}
64do_test thread2-1.6 {
65 thread_compile B {SELECT a FROM t1 LIMIT 1}
66 thread_result B
67} {SQLITE_OK}
68do_test thread2-1.7 {
69 thread_step B
70 thread_result B
71} {SQLITE_ROW}
72do_test thread2-1.8 {
73 thread_argv B 0
74} {1}
75do_test thread2-1.9 {
76 thread_finalize B
77 thread_result B
78} {SQLITE_OK}
79
80# Swap them again.
81#
82do_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}
87do_test thread2-2.3 {
88 thread_step A
89 thread_result A
90} {SQLITE_ROW}
91do_test thread2-2.4 {
92 thread_argv A 0
93} {1}
94do_test thread2-2.5 {
95 thread_finalize A
96 thread_result A
97} {SQLITE_OK}
98do_test thread2-2.6 {
99 thread_compile B {SELECT a FROM t1 LIMIT 1}
100 thread_result B
101} {SQLITE_OK}
102do_test thread2-2.7 {
103 thread_step B
104 thread_result B
105} {SQLITE_ROW}
106do_test thread2-2.8 {
107 thread_argv B 0
108} {1}
109do_test thread2-2.9 {
110 thread_finalize B
111 thread_result B
112} {SQLITE_OK}
113thread_halt A
114thread_halt B
115
116# Also important to halt the worker threads, which are using spin
117# locks and eating away CPU cycles.
118#
119thread_halt *
120finish_test