xref: /sqlite-3.40.0/test/async.test (revision fda06bef)
12366940dSdrh#
22366940dSdrh#    May you do good and not evil.
32366940dSdrh#    May you find forgiveness for yourself and forgive others.
42366940dSdrh#    May you share freely, never taking more than you give.
52366940dSdrh#
62366940dSdrh#***********************************************************************
72366940dSdrh# This file runs all tests.
82366940dSdrh#
9dda70fe3Sdrh# $Id: async.test,v 1.21 2009/06/05 17:09:12 drh Exp $
102366940dSdrh
112366940dSdrhset testdir [file dirname $argv0]
122366940dSdrhsource $testdir/tester.tcl
134ff62026Sdanielk1977
146f050aa2Sdanielk1977if {[info commands sqlite3async_initialize] eq ""} {
154ff62026Sdanielk1977  # The async logic is not built into this system
164ff62026Sdanielk1977  finish_test
174ff62026Sdanielk1977  return
184ff62026Sdanielk1977}
194ff62026Sdanielk1977
203e078c7aSdrhrename finish_test async_really_finish_test
21b6be675dSdanielk1977proc finish_test {} {
22b6be675dSdanielk1977  catch {db close}
23b6be675dSdanielk1977  catch {db2 close}
24b6be675dSdanielk1977  catch {db3 close}
25b6be675dSdanielk1977}
26430e74cdSdanif {[info exists G(isquick)]} { set ASYNC_SAVE_ISQUICK $G(isquick) }
27430e74cdSdanset G(isquick) 1
282366940dSdrh
291c501793Sdanielk1977set ASYNC_INCLUDE {
30ed10afb4Sdanielk1977  insert.test
31ed10afb4Sdanielk1977  insert2.test
32ed10afb4Sdanielk1977  insert3.test
33ed10afb4Sdanielk1977  lock.test
34ed10afb4Sdanielk1977  lock2.test
35ed10afb4Sdanielk1977  lock3.test
362366940dSdrh  select1.test
372366940dSdrh  select2.test
382366940dSdrh  select3.test
392366940dSdrh  select4.test
4097bbdc0aSdrh  trans.test
412366940dSdrh}
422366940dSdrh
432366940dSdrh# Enable asynchronous IO.
446f050aa2Sdanielk1977sqlite3async_initialize "" 1
452366940dSdrh
460cf408ffSdan# This proc flushes the contents of the async-IO queue through to the
470cf408ffSdan# underlying VFS. A couple of the test scripts identified in $ASYNC_INCLUDE
480cf408ffSdan# above contain lines like "catch flush_async_queue" in places where
490cf408ffSdan# this is required for the tests to work in async mode.
500cf408ffSdan#
510cf408ffSdanproc flush_async_queue {} {
520cf408ffSdan  sqlite3async_control halt idle
530cf408ffSdan  sqlite3async_start
540cf408ffSdan  sqlite3async_wait
550cf408ffSdan  sqlite3async_control halt never
560cf408ffSdan}
570cf408ffSdan
58fe53f2e3Sdrhrename do_test async_really_do_test
592366940dSdrhproc do_test {name args} {
60fe53f2e3Sdrh  uplevel async_really_do_test async_io-$name $args
610cf408ffSdan  flush_async_queue
622366940dSdrh}
632366940dSdrh
642366940dSdrhforeach testfile [lsort -dictionary [glob $testdir/*.test]] {
652366940dSdrh  set tail [file tail $testfile]
661c501793Sdanielk1977  if {[lsearch -exact $ASYNC_INCLUDE $tail]<0} continue
672366940dSdrh  source $testfile
68b6be675dSdanielk1977
69b6be675dSdanielk1977  # Make sure everything is flushed through. This is because [source]ing
70b6be675dSdanielk1977  # the next test file will delete the database file on disk (using
71*fda06befSmistachkin  # [delete_file]). If the asynchronous backend still has the file
72b6be675dSdanielk1977  # open, it will become confused.
73b6be675dSdanielk1977  #
740cf408ffSdan  flush_async_queue
752366940dSdrh}
762366940dSdrh
77750b03e5Sdanielk1977# Flush the write-queue and disable asynchronous IO. This should ensure
78750b03e5Sdanielk1977# all allocated memory is cleaned up.
7905a82983Sdrhset sqlite3async_trace 1
800cf408ffSdanflush_async_queue
816f050aa2Sdanielk1977sqlite3async_shutdown
8205a82983Sdrhset sqlite3async_trace 0
83750b03e5Sdanielk1977
84fe53f2e3Sdrhrename do_test {}
85fe53f2e3Sdrhrename async_really_do_test do_test
86fe53f2e3Sdrhrename finish_test {}
873e078c7aSdrhrename async_really_finish_test finish_test
881c501793Sdanielk1977
89430e74cdSdanif {[info exists ASYNC_SAVE_ISQUICK]} { set G(isquick) $ASYNC_SAVE_ISQUICK }
901c501793Sdanielk1977finish_test
91