win32lock.test 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # 2011 July 11
  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 recovery from transient manditory locks
  13. # that sometimes appear on database files due to anti-virus software.
  14. #
  15. if {$tcl_platform(platform)!="windows"} return
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. set testprefix win32lock
  19. db close
  20. sqlite3_shutdown
  21. test_sqlite3_log xLog
  22. proc xLog {error_code msg} {
  23. lappend ::log $msg
  24. }
  25. sqlite3 db test.db
  26. db eval {PRAGMA mmap_size=0}
  27. do_test win32lock-1.1 {
  28. db eval {
  29. PRAGMA cache_size=10;
  30. CREATE TABLE t1(x,y);
  31. INSERT INTO t1 VALUES(1,randomblob(100000));
  32. INSERT INTO t1 VALUES(2,randomblob(50000));
  33. INSERT INTO t1 VALUES(3,randomblob(25000));
  34. INSERT INTO t1 VALUES(4,randomblob(12500));
  35. SELECT x, length(y) FROM t1 ORDER BY rowid;
  36. }
  37. } {1 100000 2 50000 3 25000 4 12500}
  38. unset -nocomplain delay1 rc msg
  39. set old_pending_byte [sqlite3_test_control_pending_byte 0x40000000]
  40. set win32_lock_ok [list]
  41. set win32_lock_error [list]
  42. set delay1 25
  43. while {1} {
  44. lock_win32_file test.db 0 $::delay1
  45. set ::log {}
  46. set rc [catch {db eval {SELECT x, length(y) FROM t1 ORDER BY rowid}} msg]
  47. if {$rc} {
  48. lappend win32_lock_error $::delay1
  49. do_test win32lock-1.2-$delay1-error {
  50. set ::msg
  51. } {disk I/O error}
  52. } else {
  53. lappend win32_lock_ok $::delay1
  54. do_test win32lock-1.2-$delay1-ok {
  55. set ::msg
  56. } {1 100000 2 50000 3 25000 4 12500}
  57. if {[info exists ::log] && $::log!=""} {
  58. do_test win32lock-1.2-$delay1-log1 {
  59. regsub {\d+} $::log # x
  60. set x
  61. } {{delayed #ms for lock/sharing conflict}}
  62. }
  63. }
  64. if {[llength $win32_lock_ok] && [llength $win32_lock_error]} break
  65. incr delay1 25
  66. if {$delay1 > 12500} {
  67. puts "Timed out waiting for \"ok\" and \"error\" results."
  68. break
  69. }
  70. sqlite3_sleep 10
  71. }
  72. do_test win32lock-2.0 {
  73. file_control_win32_av_retry db -1 -1
  74. } {0 10 25}
  75. do_test win32lock-2.1 {
  76. file_control_win32_av_retry db 1 1
  77. } {0 1 1}
  78. #
  79. # NOTE: It is known that the win32lock-2.2-* tests may fail if the system is
  80. # experiencing heavy load (i.e. they are very timing sensitive). This is
  81. # primarily due to the AV retry delay being set to 1 millisecond in the
  82. # win32lock-2.1 test (above). While it is important to test this corner
  83. # case for the AV retry logic, a failure of this test should probably not
  84. # be interpreted as a bug in SQLite or these test cases.
  85. #
  86. set win32_lock_ok [list]
  87. set win32_lock_error [list]
  88. set delay1 1
  89. while {1} {
  90. lock_win32_file test.db 0 $::delay1
  91. set ::log {}
  92. set rc [catch {db eval {SELECT x, length(y) FROM t1 ORDER BY rowid}} msg]
  93. if {$rc} {
  94. lappend win32_lock_error $::delay1
  95. do_test win32lock-2.2-$delay1-error {
  96. set ::msg
  97. } {disk I/O error}
  98. } else {
  99. lappend win32_lock_ok $::delay1
  100. do_test win32lock-2.2-$delay1-ok {
  101. set ::msg
  102. } {1 100000 2 50000 3 25000 4 12500}
  103. if {[info exists ::log] && $::log!=""} {
  104. do_test win32lock-2.2-$delay1-log1 {
  105. regsub {\d+} $::log # x
  106. set x
  107. } {{delayed #ms for lock/sharing conflict}}
  108. }
  109. }
  110. if {[llength $win32_lock_ok] && [llength $win32_lock_error]} break
  111. incr delay1 1
  112. if {$delay1 > 500} {
  113. puts "Timed out waiting for \"ok\" and \"error\" results."
  114. break
  115. }
  116. sqlite3_sleep 10
  117. }
  118. file_control_win32_av_retry db 10 25
  119. sqlite3_test_control_pending_byte $old_pending_byte
  120. db close
  121. sqlite3_shutdown
  122. test_sqlite3_log
  123. sqlite3_initialize
  124. finish_test