blob: d014be4d2c59bed75cf27a187efc592905ef2523 [file] [log] [blame]
drh80084ca2011-07-11 23:45:44 +00001# 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
16if {$tcl_platform(platform)!="windows"} return
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
21set testprefix win32lock
22
drha32ad842011-07-12 13:51:05 +000023db close
24sqlite3_shutdown
25test_sqlite3_log xLog
26proc xLog {error_code msg} {
27 lappend ::log $msg
28}
29sqlite3 db test.db
30
drh80084ca2011-07-11 23:45:44 +000031do_test win32lock-1.1 {
32 db eval {
33 PRAGMA cache_size=10;
34 CREATE TABLE t1(x,y);
35 INSERT INTO t1 VALUES(1,randomblob(100000));
36 INSERT INTO t1 VALUES(2,randomblob(50000));
37 INSERT INTO t1 VALUES(3,randomblob(25000));
38 INSERT INTO t1 VALUES(4,randomblob(12500));
39 SELECT x, length(y) FROM t1 ORDER BY rowid;
40 }
41} {1 100000 2 50000 3 25000 4 12500}
42
43unset -nocomplain delay1 rc msg
drh80084ca2011-07-11 23:45:44 +000044set old_pending_byte [sqlite3_test_control_pending_byte 0x40000000]
mistachkin176f1b42011-08-02 23:34:00 +000045
46set win32_lock_ok [list]
47set win32_lock_error [list]
48set delay1 25
drh80084ca2011-07-11 23:45:44 +000049while {1} {
drh80084ca2011-07-11 23:45:44 +000050 lock_win32_file test.db 0 $::delay1
mistachkin176f1b42011-08-02 23:34:00 +000051 set ::log {}
drh80084ca2011-07-11 23:45:44 +000052 set rc [catch {db eval {SELECT x, length(y) FROM t1 ORDER BY rowid}} msg]
53 if {$rc} {
mistachkin176f1b42011-08-02 23:34:00 +000054 lappend win32_lock_error $::delay1
55 do_test win32lock-1.2-$delay1-error {
drh80084ca2011-07-11 23:45:44 +000056 set ::msg
57 } {disk I/O error}
drh80084ca2011-07-11 23:45:44 +000058 } else {
mistachkin176f1b42011-08-02 23:34:00 +000059 lappend win32_lock_ok $::delay1
60 do_test win32lock-1.2-$delay1-ok {
drh80084ca2011-07-11 23:45:44 +000061 set ::msg
62 } {1 100000 2 50000 3 25000 4 12500}
mistachkin4e6b49b2011-07-28 19:16:41 +000063 if {[info exists ::log] && $::log!=""} {
drha32ad842011-07-12 13:51:05 +000064 do_test win32lock-1.2-$delay1-log1 {
65 regsub {\d+} $::log # x
66 set x
67 } {{delayed #ms for lock/sharing conflict}}
68 }
drh80084ca2011-07-11 23:45:44 +000069 }
mistachkin176f1b42011-08-02 23:34:00 +000070 if {[llength $win32_lock_ok] && [llength $win32_lock_error]} break
71 incr delay1 25
mistachkinf2d25f22011-08-25 04:09:12 +000072 if {$delay1 > 12500} {
73 puts "Timed out waiting for \"ok\" and \"error\" results."
74 break
75 }
mistachkin176f1b42011-08-02 23:34:00 +000076 sqlite3_sleep 10
drh80084ca2011-07-11 23:45:44 +000077}
drhd0cdf012011-07-13 16:03:46 +000078
79do_test win32lock-2.0 {
80 file_control_win32_av_retry db -1 -1
81} {0 10 25}
82do_test win32lock-2.1 {
83 file_control_win32_av_retry db 1 1
84} {0 1 1}
85
mistachkin85e444c2011-08-02 23:45:53 +000086#
87# NOTE: It is known that the win32lock-2.2-* tests may fail if the system is
88# experiencing heavy load (i.e. they are very timing sensitive). This is
89# primarily due to the AV retry delay being set to 1 millisecond in the
90# win32lock-2.1 test (above). While it is important to test this corner
91# case for the AV retry logic, a failure of this test should probably not
92# be interpreted as a bug in SQLite or these test cases.
93#
mistachkin176f1b42011-08-02 23:34:00 +000094set win32_lock_ok [list]
95set win32_lock_error [list]
96set delay1 1
drhd0cdf012011-07-13 16:03:46 +000097while {1} {
drhd0cdf012011-07-13 16:03:46 +000098 lock_win32_file test.db 0 $::delay1
mistachkin176f1b42011-08-02 23:34:00 +000099 set ::log {}
drhd0cdf012011-07-13 16:03:46 +0000100 set rc [catch {db eval {SELECT x, length(y) FROM t1 ORDER BY rowid}} msg]
101 if {$rc} {
mistachkin176f1b42011-08-02 23:34:00 +0000102 lappend win32_lock_error $::delay1
103 do_test win32lock-2.2-$delay1-error {
drhd0cdf012011-07-13 16:03:46 +0000104 set ::msg
105 } {disk I/O error}
drhd0cdf012011-07-13 16:03:46 +0000106 } else {
mistachkin176f1b42011-08-02 23:34:00 +0000107 lappend win32_lock_ok $::delay1
108 do_test win32lock-2.2-$delay1-ok {
drhd0cdf012011-07-13 16:03:46 +0000109 set ::msg
110 } {1 100000 2 50000 3 25000 4 12500}
mistachkin1b466a62011-08-02 20:19:48 +0000111 if {[info exists ::log] && $::log!=""} {
drhd0cdf012011-07-13 16:03:46 +0000112 do_test win32lock-2.2-$delay1-log1 {
113 regsub {\d+} $::log # x
114 set x
115 } {{delayed #ms for lock/sharing conflict}}
116 }
drhd0cdf012011-07-13 16:03:46 +0000117 }
mistachkin176f1b42011-08-02 23:34:00 +0000118 if {[llength $win32_lock_ok] && [llength $win32_lock_error]} break
119 incr delay1 1
mistachkinf2d25f22011-08-25 04:09:12 +0000120 if {$delay1 > 500} {
121 puts "Timed out waiting for \"ok\" and \"error\" results."
122 break
123 }
mistachkin176f1b42011-08-02 23:34:00 +0000124 sqlite3_sleep 10
drhd0cdf012011-07-13 16:03:46 +0000125}
126
127file_control_win32_av_retry db 10 25
drh80084ca2011-07-11 23:45:44 +0000128sqlite3_test_control_pending_byte $old_pending_byte
mistachkin4d60be52011-08-26 05:40:31 +0000129db close
drha32ad842011-07-12 13:51:05 +0000130sqlite3_shutdown
131test_sqlite3_log
132sqlite3_initialize
drh80084ca2011-07-11 23:45:44 +0000133finish_test