CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
thread2.test121 linesDownload Raw Back to test
1# 2006 January 142#3# The author disclaims copyright to this source code.  In place of4# 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.  The12# focus of this script is multithreading behavior13#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.tcl19 20if {[run_thread_tests]==0} { finish_test ; return }21 22# Skip this whole file if the thread testing code is not enabled23#24if {[llength [info command thread_step]]==0 || [sqlite3 -has-codec]} {25  finish_test26  return27}28 29# Create some data to work with30#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 between43# threads, then verify that they still work.44#45do_test thread2-1.2 {46  db close47  thread_create A test.db48  thread_create B test.db49  thread_swap A B50  thread_compile A {SELECT a FROM t1 LIMIT 1}51  thread_result A52} {SQLITE_OK}53do_test thread2-1.3 {54  thread_step A55  thread_result A56} {SQLITE_ROW}57do_test thread2-1.4 {58  thread_argv A 059} {1}60do_test thread2-1.5 {61  thread_finalize A62  thread_result A63} {SQLITE_OK}64do_test thread2-1.6 {65  thread_compile B {SELECT a FROM t1 LIMIT 1}66  thread_result B67} {SQLITE_OK}68do_test thread2-1.7 {69  thread_step B70  thread_result B71} {SQLITE_ROW}72do_test thread2-1.8 {73  thread_argv B 074} {1}75do_test thread2-1.9 {76  thread_finalize B77  thread_result B78} {SQLITE_OK}79 80# Swap them again.81#82do_test thread2-2.2 {83  thread_swap A B84  thread_compile A {SELECT a FROM t1 LIMIT 1}85  thread_result A86} {SQLITE_OK}87do_test thread2-2.3 {88  thread_step A89  thread_result A90} {SQLITE_ROW}91do_test thread2-2.4 {92  thread_argv A 093} {1}94do_test thread2-2.5 {95  thread_finalize A96  thread_result A97} {SQLITE_OK}98do_test thread2-2.6 {99  thread_compile B {SELECT a FROM t1 LIMIT 1}100  thread_result B101} {SQLITE_OK}102do_test thread2-2.7 {103  thread_step B104  thread_result B105} {SQLITE_ROW}106do_test thread2-2.8 {107  thread_argv B 0108} {1}109do_test thread2-2.9 {110  thread_finalize B111  thread_result B112} {SQLITE_OK}113thread_halt A114thread_halt B115 116# Also important to halt the worker threads, which are using spin117# locks and eating away CPU cycles.118#119thread_halt *   120finish_test121