2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A# The author disclaims copyright to this source code. In place of
2N/A# a legal notice, here is a blessing:
2N/A# May you do good and not evil.
2N/A# May you find forgiveness for yourself and forgive others.
2N/A# May you share freely, never taking more than you give.
2N/A#***********************************************************************
2N/A# This file implements regression tests for SQLite library. The
2N/A# focus of this script is multithreading behavior
2N/Aset testdir [file dirname $argv0]
2N/A# Skip this whole file if the thread testing code is not enabled
2N/Aif {[llength [info command thread_step]]==0 || [sqlite -has-codec]} {
2N/A# Create some data to work with
2N/Ado_test thread1-1.1 {
2N/A CREATE TABLE t1(a,b);
2N/A INSERT INTO t1 VALUES(1,'abcdefgh');
2N/A INSERT INTO t1 SELECT a+1, b||b FROM t1;
2N/A INSERT INTO t1 SELECT a+2, b||b FROM t1;
2N/A INSERT INTO t1 SELECT a+4, b||b FROM t1;
2N/A SELECT count(*), max(length(b)) FROM t1;
2N/A# Interleave two threads on read access. Then make sure a third
2N/A# thread can write the database. In other words:
2N/A# At one point, the write-lock of C would fail on Linux.
2N/Ado_test thread1-1.2 {
2N/A thread_compile A {SELECT a FROM t1}
2N/Ado_test thread1-1.3 {
2N/Ado_test thread1-1.4 {
2N/Ado_test thread1-1.5 {
2N/A thread_compile B {SELECT b FROM t1}
2N/Ado_test thread1-1.6 {
2N/Ado_test thread1-1.7 {
2N/Ado_test thread1-1.8 {
2N/Ado_test thread1-1.9 {
2N/Ado_test thread1-1.10 {
2N/A thread_compile C {CREATE TABLE t2(x,y)}
2N/Ado_test thread1-1.11 {
2N/Ado_test thread1-1.12 {
2N/A catchsql {SELECT name FROM sqlite_master}
2N/A execsql {SELECT name FROM sqlite_master}
2N/A# Under this scenario:
2N/A# Make sure the write-lock fails with SQLITE_BUSY
2N/Ado_test thread1-2.1 {
2N/A thread_compile A {SELECT a FROM t1}
2N/Ado_test thread1-2.2 {
2N/A thread_compile B {SELECT b FROM t1}
2N/Ado_test thread1-2.3 {
2N/A thread_compile C {INSERT INTO t2 VALUES(98,99)}
2N/Ado_test thread1-2.4 {
2N/A execsql {SELECT * FROM t2}
2N/Ado_test thread1-2.5 {
2N/Ado_test thread1-2.6 {
2N/Ado_test thread1-2.7 {
2N/A execsql {SELECT * FROM t2}
2N/Ado_test thread1-2.8 {
2N/Ado_test thread1-2.9 {
2N/Ado_test thread1-2.10 {
2N/A execsql {SELECT * FROM t2}
2N/Ado_test thread1-2.11 {