async2.test 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #
  2. # May you do good and not evil.
  3. # May you find forgiveness for yourself and forgive others.
  4. # May you share freely, never taking more than you give.
  5. #
  6. #***********************************************************************
  7. #
  8. # $Id: async2.test,v 1.12 2009/04/25 08:39:15 danielk1977 Exp $
  9. set testdir [file dirname $argv0]
  10. source $testdir/tester.tcl
  11. if {
  12. [info commands sqlite3async_initialize]=="" ||
  13. [info command sqlite3_memdebug_fail]==""
  14. } {
  15. # The async logic is not built into this system
  16. puts "Skipping async2 tests: not compiled with required features"
  17. finish_test
  18. return
  19. }
  20. # Enable asynchronous IO.
  21. set setup_script {
  22. CREATE TABLE counter(c);
  23. INSERT INTO counter(c) VALUES (1);
  24. }
  25. set sql_script {
  26. BEGIN;
  27. UPDATE counter SET c = 2;
  28. CREATE TABLE t1(a PRIMARY KEY, b, c);
  29. CREATE TABLE t2(a PRIMARY KEY, b, c);
  30. COMMIT;
  31. BEGIN;
  32. UPDATE counter SET c = 3;
  33. INSERT INTO t1 VALUES('abcdefghij', 'four', 'score');
  34. INSERT INTO t2 VALUES('klmnopqrst', 'and', 'seven');
  35. COMMIT;
  36. UPDATE counter SET c = 'FIN';
  37. }
  38. db close
  39. foreach err [list ioerr malloc-transient malloc-persistent] {
  40. set ::go 10
  41. for {set n 1} {$::go} {incr n} {
  42. set ::sqlite_io_error_pending 0
  43. sqlite3_memdebug_fail -1
  44. forcedelete test.db test.db-journal
  45. sqlite3 db test.db
  46. execsql $::setup_script
  47. db close
  48. sqlite3async_initialize "" 1
  49. sqlite3 db test.db
  50. sqlite3_db_config_lookaside db 0 0 0
  51. switch -- $err {
  52. ioerr { set ::sqlite_io_error_pending $n }
  53. malloc-persistent { sqlite3_memdebug_fail $n -repeat 1 }
  54. malloc-transient { sqlite3_memdebug_fail $n -repeat 0 }
  55. }
  56. catchsql $::sql_script
  57. db close
  58. sqlite3async_control halt idle
  59. sqlite3async_start
  60. sqlite3async_wait
  61. sqlite3async_control halt never
  62. sqlite3async_shutdown
  63. set ::sqlite_io_error_pending 0
  64. sqlite3_memdebug_fail -1
  65. sqlite3 db test.db
  66. set c [db one {SELECT c FROM counter LIMIT 1}]
  67. switch -- $c {
  68. 1 {
  69. do_test async-$err-1.1.$n {
  70. execsql {
  71. SELECT name FROM sqlite_master;
  72. }
  73. } {counter}
  74. }
  75. 2 {
  76. do_test async-$err-1.2.$n.1 {
  77. execsql {
  78. SELECT * FROM t1;
  79. }
  80. } {}
  81. do_test async-$err-1.2.$n.2 {
  82. execsql {
  83. SELECT * FROM t2;
  84. }
  85. } {}
  86. }
  87. 3 {
  88. do_test async-$err-1.3.$n.1 {
  89. execsql {
  90. SELECT * FROM t1;
  91. }
  92. } {abcdefghij four score}
  93. do_test async-$err-1.3.$n.2 {
  94. execsql {
  95. SELECT * FROM t2;
  96. }
  97. } {klmnopqrst and seven}
  98. }
  99. FIN {
  100. incr ::go -1
  101. }
  102. }
  103. db close
  104. }
  105. }
  106. catch {db close}
  107. finish_test