diff options
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/thread002.test')
-rw-r--r-- | libraries/sqlite/unix/sqlite-3.5.1/test/thread002.test | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/thread002.test b/libraries/sqlite/unix/sqlite-3.5.1/test/thread002.test new file mode 100644 index 0000000..94141be --- /dev/null +++ b/libraries/sqlite/unix/sqlite-3.5.1/test/thread002.test | |||
@@ -0,0 +1,105 @@ | |||
1 | # 2007 September 10 | ||
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 | # | ||
12 | # This test attempts to deadlock SQLite in shared-cache mode. | ||
13 | # | ||
14 | # | ||
15 | # $Id: thread002.test,v 1.1 2007/09/10 10:53:02 danielk1977 Exp $ | ||
16 | |||
17 | set testdir [file dirname $argv0] | ||
18 | |||
19 | source $testdir/tester.tcl | ||
20 | source $testdir/thread_common.tcl | ||
21 | if {[info commands sqlthread] eq ""} { | ||
22 | return | ||
23 | } | ||
24 | |||
25 | db close | ||
26 | sqlite3_enable_shared_cache 1 | ||
27 | |||
28 | set ::NTHREAD 10 | ||
29 | |||
30 | do_test thread002.1 { | ||
31 | # Create 3 databases with identical schemas: | ||
32 | for {set ii 0} {$ii < 3} {incr ii} { | ||
33 | file delete -force test${ii}.db | ||
34 | sqlite3 db test${ii}.db | ||
35 | execsql { | ||
36 | CREATE TABLE t1(k, v); | ||
37 | CREATE INDEX t1_i ON t1(v); | ||
38 | INSERT INTO t1(v) VALUES(1.0); | ||
39 | } | ||
40 | db close | ||
41 | } | ||
42 | } {} | ||
43 | |||
44 | set thread_program { | ||
45 | set ::DB [sqlite3_open test.db] | ||
46 | for {set ii 1} {$ii <= 3} {incr ii} { | ||
47 | set T [lindex $order [expr $ii-1]] | ||
48 | execsql "ATTACH 'test${T}.db' AS aux${ii}" | ||
49 | } | ||
50 | |||
51 | for {set ii 0} {$ii < 100} {incr ii} { | ||
52 | execsql { SELECT * FROM aux1.t1 } | ||
53 | execsql { INSERT INTO aux1.t1(v) SELECT sum(v) FROM aux2.t1 } | ||
54 | |||
55 | execsql { SELECT * FROM aux2.t1 } | ||
56 | execsql { INSERT INTO aux2.t1(v) SELECT sum(v) FROM aux3.t1 } | ||
57 | |||
58 | execsql { SELECT * FROM aux3.t1 } | ||
59 | execsql { INSERT INTO aux3.t1(v) SELECT sum(v) FROM aux1.t1 } | ||
60 | |||
61 | execsql { CREATE TABLE aux1.t2(a,b) } | ||
62 | execsql { DROP TABLE aux1.t2 } | ||
63 | |||
64 | # if {($ii%10)==0} {puts -nonewline . ; flush stdout} | ||
65 | puts -nonewline . ; flush stdout | ||
66 | } | ||
67 | |||
68 | sqlite3_close $::DB | ||
69 | list OK | ||
70 | } | ||
71 | |||
72 | set order_list [list {0 1 2} {0 2 1} {1 0 2} {1 2 0} {2 0 1} {2 1 0}] | ||
73 | |||
74 | array unset finished | ||
75 | for {set ii 0} {$ii < $::NTHREAD} {incr ii} { | ||
76 | set order [lindex $order_list [expr $ii%6]] | ||
77 | thread_spawn finished($ii) $thread_procs "set order {$order}" $thread_program | ||
78 | } | ||
79 | |||
80 | # Wait for all threads to finish, then check they all returned "OK". | ||
81 | # | ||
82 | for {set i 0} {$i < $::NTHREAD} {incr i} { | ||
83 | if {![info exists finished($i)]} { | ||
84 | vwait finished($i) | ||
85 | } | ||
86 | do_test thread001.2.$i { | ||
87 | set ::finished($i) | ||
88 | } OK | ||
89 | } | ||
90 | |||
91 | # Check all three databases are Ok. | ||
92 | for {set ii 0} {$ii < 3} {incr ii} { | ||
93 | do_test thread002.3.$ii { | ||
94 | sqlite3 db test${ii}.db | ||
95 | set res [list \ | ||
96 | [execsql {SELECT count(*) FROM t1}] \ | ||
97 | [execsql {PRAGMA integrity_check}] \ | ||
98 | ] | ||
99 | db close | ||
100 | set res | ||
101 | } [list [expr 1 + $::NTHREAD*100] ok] | ||
102 | } | ||
103 | |||
104 | finish_test | ||
105 | |||