async4.test 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. # 2009 April 25
  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. # $Id: async4.test,v 1.4 2009/06/05 17:09:12 drh Exp $
  13. set testdir [file dirname $argv0]
  14. source $testdir/tester.tcl
  15. # Do not use a codec for tests in this file, as the database file is
  16. # manipulated directly using tcl scripts (using the [hexio_write] command).
  17. #
  18. do_not_use_codec
  19. # These tests only work for Tcl version 8.5 and later on Windows (for now)
  20. #
  21. if {$tcl_platform(platform)=="windows"} {
  22. scan $::tcl_version %f vx
  23. if {$vx<8.5} {
  24. finish_test
  25. return
  26. }
  27. }
  28. if {[info commands sqlite3async_initialize] eq ""} {
  29. # The async logic is not built into this system
  30. finish_test
  31. return
  32. }
  33. db close
  34. # Test layout:
  35. #
  36. # async4.1.*: Test the lockfiles parameter.
  37. # async4.2.*: Test the delay parameter.
  38. do_test async4.1.1 {
  39. sqlite3async_initialize {} 0
  40. sqlite3async_control lockfiles
  41. } {1}
  42. do_test async4.1.2 {
  43. sqlite3async_control lockfiles false
  44. } {0}
  45. do_test async4.1.3 {
  46. sqlite3async_control lockfiles
  47. } {0}
  48. do_test async4.1.4 {
  49. sqlite3async_control lockfiles true
  50. } {1}
  51. do_test async4.1.5 {
  52. sqlite3 db test.db -vfs sqlite3async
  53. execsql { CREATE TABLE t1(a, b, c) }
  54. } {}
  55. do_test async4.1.6 {
  56. list [file exists test.db] [file size test.db]
  57. } {1 0}
  58. do_test async4.1.7 {
  59. sqlite3 db2 test.db
  60. catchsql { CREATE TABLE t2(a, b, c) } db2
  61. } {1 {database is locked}}
  62. do_test async4.1.8 {
  63. sqlite3async_control halt idle
  64. sqlite3async_start
  65. sqlite3async_wait
  66. } {}
  67. do_test async4.1.9 {
  68. catchsql { CREATE TABLE t2(a, b, c) } db2
  69. } {0 {}}
  70. do_test async4.1.10 {
  71. list [catch {sqlite3async_control lockfiles false} msg] $msg
  72. } {1 SQLITE_MISUSE}
  73. do_test async4.1.11 {
  74. db close
  75. list [catch {sqlite3async_control lockfiles false} msg] $msg
  76. } {1 SQLITE_MISUSE}
  77. do_test async4.1.12 {
  78. sqlite3async_start
  79. sqlite3async_wait
  80. sqlite3async_control lockfiles false
  81. } {0}
  82. do_test async4.1.13 {
  83. sqlite3 db test.db -vfs sqlite3async
  84. execsql { CREATE TABLE t3(a, b, c) } db
  85. } {}
  86. do_test async4.1.14 {
  87. execsql {
  88. CREATE INDEX i1 ON t2(a);
  89. CREATE INDEX i2 ON t1(a);
  90. } db2
  91. } {}
  92. do_test async4.1.15 {
  93. sqlite3async_start
  94. sqlite3async_wait
  95. hexio_write test.db 28 00000000
  96. execsql { pragma integrity_check } db2
  97. } {{*** in database main ***
  98. Page 5 is never used}}
  99. do_test async4.1.16 {
  100. db close
  101. db2 close
  102. sqlite3async_start
  103. sqlite3async_wait
  104. } {}
  105. do_test async4.1.17 {
  106. sqlite3async_control lockfiles true
  107. } {1}
  108. do_test async4.2.1 {
  109. sqlite3async_control delay
  110. } {0}
  111. do_test async4.2.2 {
  112. sqlite3async_control delay 23
  113. } {23}
  114. do_test async4.2.3 {
  115. sqlite3async_control delay
  116. } {23}
  117. do_test async4.2.4 {
  118. sqlite3async_control delay 0
  119. } {0}
  120. do_test async4.2.5 {
  121. sqlite3 db test.db -vfs sqlite3async
  122. execsql { CREATE TABLE t4(a, b) }
  123. set T1 [lindex [time {
  124. sqlite3async_start
  125. sqlite3async_wait
  126. }] 0]
  127. sqlite3async_control delay 100
  128. execsql { CREATE TABLE t5(a, b) }
  129. set T2 [lindex [time {
  130. sqlite3async_start
  131. sqlite3async_wait
  132. }] 0]
  133. expr {($T1+1000000) < $T2}
  134. } {1}
  135. do_test async4.2.6 {
  136. sqlite3async_control delay 0
  137. execsql { CREATE TABLE t6(a, b) }
  138. set T1 [lindex [time {
  139. sqlite3async_start
  140. sqlite3async_wait
  141. }] 0]
  142. expr {($T1+1000000) < $T2}
  143. } {1}
  144. do_test async4.2.7 {
  145. list [catch { sqlite3async_control delay -1 } msg] $msg
  146. } {1 SQLITE_MISUSE}
  147. do_test async4.2.8 {
  148. db close
  149. sqlite3async_start
  150. sqlite3async_wait
  151. } {}
  152. finish_test