1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-27 20:41:58 +03:00

A better fix for ticket #530 - one that is likely to work on unix

implementations in addition to linux.  Also more tests for multi-thread
locking added. (CVS 1138)

FossilOrigin-Name: 7dddbeb586504de30c64a1e61614da447f18c8ba
This commit is contained in:
drh
2003-12-19 08:40:22 +00:00
parent a6064dcf3b
commit acf01e7ddd
4 changed files with 90 additions and 21 deletions

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this script is multithreading behavior
#
# $Id: thread1.test,v 1.1 2003/12/19 02:52:09 drh Exp $
# $Id: thread1.test,v 1.2 2003/12/19 08:40:24 drh Exp $
set testdir [file dirname $argv0]
@ -38,7 +38,15 @@ do_test thread1-1.1 {
} {8 64}
# Interleave two threads on read access. Then make sure a third
# thread can write the database.
# thread can write the database. In other words:
#
# read-lock A
# read-lock B
# unlock A
# unlock B
# write-lock C
#
# At one point, the write-lock of C would fail on Linux.
#
do_test thread1-1.2 {
thread_create A test.db
@ -82,7 +90,69 @@ do_test thread1-1.11 {
thread_finalize C
thread_result C
} SQLITE_OK
do_test thread1-1.12 {
catchsql {SELECT name FROM sqlite_master}
execsql {SELECT name FROM sqlite_master}
} {t1 t2}
# Under this scenario:
#
# read-lock A
# read-lock B
# unlock A
# write-lock C
#
# Make sure the write-lock fails with SQLITE_BUSY
#
do_test thread1-2.1 {
thread_halt *
thread_create A test.db
thread_compile A {SELECT a FROM t1}
thread_step A
thread_result A
} SQLITE_ROW
do_test thread1-2.2 {
thread_create B test.db
thread_compile B {SELECT b FROM t1}
thread_step B
thread_result B
} SQLITE_ROW
do_test thread1-2.3 {
thread_create C test.db
thread_compile C {INSERT INTO t2 VALUES(98,99)}
thread_step C
thread_result C
} SQLITE_BUSY
do_test thread1-2.4 {
execsql {SELECT * FROM t2}
} {}
do_test thread1-2.5 {
thread_finalize A
thread_result A
} SQLITE_OK
do_test thread1-2.6 {
thread_step C
thread_result C
} SQLITE_BUSY
do_test thread1-2.7 {
execsql {SELECT * FROM t2}
} {}
do_test thread1-2.8 {
thread_finalize B
thread_result B
} SQLITE_OK
do_test thread1-2.9 {
thread_step C
thread_result C
} SQLITE_DONE
do_test thread1-2.10 {
execsql {SELECT * FROM t2}
} {98 99}
do_test thread1-2.11 {
thread_finalize C
thread_result C
} SQLITE_OK
thread_halt *
finish_test