thread2.test 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # 2006 January 14
  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. # This file implements regression tests for SQLite library. The
  12. # focus of this script is multithreading behavior
  13. #
  14. # $Id: thread2.test,v 1.3 2008/10/07 15:25:49 drh Exp $
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. if {[run_thread_tests]==0} { finish_test ; return }
  18. # Skip this whole file if the thread testing code is not enabled
  19. #
  20. if {[llength [info command thread_step]]==0 || [sqlite3 -has-codec]} {
  21. finish_test
  22. return
  23. }
  24. # Create some data to work with
  25. #
  26. do_test thread1-1.1 {
  27. execsql {
  28. CREATE TABLE t1(a,b);
  29. INSERT INTO t1 VALUES(1,'abcdefgh');
  30. INSERT INTO t1 SELECT a+1, b||b FROM t1;
  31. INSERT INTO t1 SELECT a+2, b||b FROM t1;
  32. INSERT INTO t1 SELECT a+4, b||b FROM t1;
  33. SELECT count(*), max(length(b)) FROM t1;
  34. }
  35. } {8 64}
  36. # Use the thread_swap command to move the database connections between
  37. # threads, then verify that they still work.
  38. #
  39. do_test thread2-1.2 {
  40. db close
  41. thread_create A test.db
  42. thread_create B test.db
  43. thread_swap A B
  44. thread_compile A {SELECT a FROM t1 LIMIT 1}
  45. thread_result A
  46. } {SQLITE_OK}
  47. do_test thread2-1.3 {
  48. thread_step A
  49. thread_result A
  50. } {SQLITE_ROW}
  51. do_test thread2-1.4 {
  52. thread_argv A 0
  53. } {1}
  54. do_test thread2-1.5 {
  55. thread_finalize A
  56. thread_result A
  57. } {SQLITE_OK}
  58. do_test thread2-1.6 {
  59. thread_compile B {SELECT a FROM t1 LIMIT 1}
  60. thread_result B
  61. } {SQLITE_OK}
  62. do_test thread2-1.7 {
  63. thread_step B
  64. thread_result B
  65. } {SQLITE_ROW}
  66. do_test thread2-1.8 {
  67. thread_argv B 0
  68. } {1}
  69. do_test thread2-1.9 {
  70. thread_finalize B
  71. thread_result B
  72. } {SQLITE_OK}
  73. # Swap them again.
  74. #
  75. do_test thread2-2.2 {
  76. thread_swap A B
  77. thread_compile A {SELECT a FROM t1 LIMIT 1}
  78. thread_result A
  79. } {SQLITE_OK}
  80. do_test thread2-2.3 {
  81. thread_step A
  82. thread_result A
  83. } {SQLITE_ROW}
  84. do_test thread2-2.4 {
  85. thread_argv A 0
  86. } {1}
  87. do_test thread2-2.5 {
  88. thread_finalize A
  89. thread_result A
  90. } {SQLITE_OK}
  91. do_test thread2-2.6 {
  92. thread_compile B {SELECT a FROM t1 LIMIT 1}
  93. thread_result B
  94. } {SQLITE_OK}
  95. do_test thread2-2.7 {
  96. thread_step B
  97. thread_result B
  98. } {SQLITE_ROW}
  99. do_test thread2-2.8 {
  100. thread_argv B 0
  101. } {1}
  102. do_test thread2-2.9 {
  103. thread_finalize B
  104. thread_result B
  105. } {SQLITE_OK}
  106. thread_halt A
  107. thread_halt B
  108. # Also important to halt the worker threads, which are using spin
  109. # locks and eating away CPU cycles.
  110. #
  111. thread_halt *
  112. finish_test