2011-07-12 03:45:44 +04:00
|
|
|
# 2011 July 11
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
# This file implements regression tests for SQLite library. The
|
|
|
|
# focus of this script is recovery from transient manditory locks
|
|
|
|
# that sometimes appear on database files due to anti-virus software.
|
|
|
|
#
|
|
|
|
|
|
|
|
if {$tcl_platform(platform)!="windows"} return
|
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
|
|
|
|
|
|
|
set testprefix win32lock
|
|
|
|
|
2011-07-12 17:51:05 +04:00
|
|
|
db close
|
|
|
|
sqlite3_shutdown
|
|
|
|
test_sqlite3_log xLog
|
|
|
|
proc xLog {error_code msg} {
|
|
|
|
lappend ::log $msg
|
|
|
|
}
|
|
|
|
sqlite3 db test.db
|
|
|
|
|
2011-07-12 03:45:44 +04:00
|
|
|
do_test win32lock-1.1 {
|
|
|
|
db eval {
|
|
|
|
PRAGMA cache_size=10;
|
|
|
|
CREATE TABLE t1(x,y);
|
|
|
|
INSERT INTO t1 VALUES(1,randomblob(100000));
|
|
|
|
INSERT INTO t1 VALUES(2,randomblob(50000));
|
|
|
|
INSERT INTO t1 VALUES(3,randomblob(25000));
|
|
|
|
INSERT INTO t1 VALUES(4,randomblob(12500));
|
|
|
|
SELECT x, length(y) FROM t1 ORDER BY rowid;
|
|
|
|
}
|
|
|
|
} {1 100000 2 50000 3 25000 4 12500}
|
|
|
|
|
|
|
|
unset -nocomplain delay1 rc msg
|
|
|
|
set old_pending_byte [sqlite3_test_control_pending_byte 0x40000000]
|
2011-08-03 03:34:00 +04:00
|
|
|
|
|
|
|
set win32_lock_ok [list]
|
|
|
|
set win32_lock_error [list]
|
|
|
|
set delay1 25
|
2011-07-12 03:45:44 +04:00
|
|
|
while {1} {
|
|
|
|
lock_win32_file test.db 0 $::delay1
|
2011-08-03 03:34:00 +04:00
|
|
|
set ::log {}
|
2011-07-12 03:45:44 +04:00
|
|
|
set rc [catch {db eval {SELECT x, length(y) FROM t1 ORDER BY rowid}} msg]
|
|
|
|
if {$rc} {
|
2011-08-03 03:34:00 +04:00
|
|
|
lappend win32_lock_error $::delay1
|
|
|
|
do_test win32lock-1.2-$delay1-error {
|
2011-07-12 03:45:44 +04:00
|
|
|
set ::msg
|
|
|
|
} {disk I/O error}
|
|
|
|
} else {
|
2011-08-03 03:34:00 +04:00
|
|
|
lappend win32_lock_ok $::delay1
|
|
|
|
do_test win32lock-1.2-$delay1-ok {
|
2011-07-12 03:45:44 +04:00
|
|
|
set ::msg
|
|
|
|
} {1 100000 2 50000 3 25000 4 12500}
|
2011-07-28 23:16:41 +04:00
|
|
|
if {[info exists ::log] && $::log!=""} {
|
2011-07-12 17:51:05 +04:00
|
|
|
do_test win32lock-1.2-$delay1-log1 {
|
|
|
|
regsub {\d+} $::log # x
|
|
|
|
set x
|
|
|
|
} {{delayed #ms for lock/sharing conflict}}
|
|
|
|
}
|
2011-07-12 03:45:44 +04:00
|
|
|
}
|
2011-08-03 03:34:00 +04:00
|
|
|
if {[llength $win32_lock_ok] && [llength $win32_lock_error]} break
|
|
|
|
incr delay1 25
|
2011-08-25 08:09:12 +04:00
|
|
|
if {$delay1 > 12500} {
|
|
|
|
puts "Timed out waiting for \"ok\" and \"error\" results."
|
|
|
|
break
|
|
|
|
}
|
2011-08-03 03:34:00 +04:00
|
|
|
sqlite3_sleep 10
|
2011-07-12 03:45:44 +04:00
|
|
|
}
|
2011-07-13 20:03:46 +04:00
|
|
|
|
|
|
|
do_test win32lock-2.0 {
|
|
|
|
file_control_win32_av_retry db -1 -1
|
|
|
|
} {0 10 25}
|
|
|
|
do_test win32lock-2.1 {
|
|
|
|
file_control_win32_av_retry db 1 1
|
|
|
|
} {0 1 1}
|
|
|
|
|
2011-08-03 03:45:53 +04:00
|
|
|
#
|
|
|
|
# NOTE: It is known that the win32lock-2.2-* tests may fail if the system is
|
|
|
|
# experiencing heavy load (i.e. they are very timing sensitive). This is
|
|
|
|
# primarily due to the AV retry delay being set to 1 millisecond in the
|
|
|
|
# win32lock-2.1 test (above). While it is important to test this corner
|
|
|
|
# case for the AV retry logic, a failure of this test should probably not
|
|
|
|
# be interpreted as a bug in SQLite or these test cases.
|
|
|
|
#
|
2011-08-03 03:34:00 +04:00
|
|
|
set win32_lock_ok [list]
|
|
|
|
set win32_lock_error [list]
|
|
|
|
set delay1 1
|
2011-07-13 20:03:46 +04:00
|
|
|
while {1} {
|
|
|
|
lock_win32_file test.db 0 $::delay1
|
2011-08-03 03:34:00 +04:00
|
|
|
set ::log {}
|
2011-07-13 20:03:46 +04:00
|
|
|
set rc [catch {db eval {SELECT x, length(y) FROM t1 ORDER BY rowid}} msg]
|
|
|
|
if {$rc} {
|
2011-08-03 03:34:00 +04:00
|
|
|
lappend win32_lock_error $::delay1
|
|
|
|
do_test win32lock-2.2-$delay1-error {
|
2011-07-13 20:03:46 +04:00
|
|
|
set ::msg
|
|
|
|
} {disk I/O error}
|
|
|
|
} else {
|
2011-08-03 03:34:00 +04:00
|
|
|
lappend win32_lock_ok $::delay1
|
|
|
|
do_test win32lock-2.2-$delay1-ok {
|
2011-07-13 20:03:46 +04:00
|
|
|
set ::msg
|
|
|
|
} {1 100000 2 50000 3 25000 4 12500}
|
2011-08-03 00:19:48 +04:00
|
|
|
if {[info exists ::log] && $::log!=""} {
|
2011-07-13 20:03:46 +04:00
|
|
|
do_test win32lock-2.2-$delay1-log1 {
|
|
|
|
regsub {\d+} $::log # x
|
|
|
|
set x
|
|
|
|
} {{delayed #ms for lock/sharing conflict}}
|
|
|
|
}
|
|
|
|
}
|
2011-08-03 03:34:00 +04:00
|
|
|
if {[llength $win32_lock_ok] && [llength $win32_lock_error]} break
|
|
|
|
incr delay1 1
|
2011-08-25 08:09:12 +04:00
|
|
|
if {$delay1 > 500} {
|
|
|
|
puts "Timed out waiting for \"ok\" and \"error\" results."
|
|
|
|
break
|
|
|
|
}
|
2011-08-03 03:34:00 +04:00
|
|
|
sqlite3_sleep 10
|
2011-07-13 20:03:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
file_control_win32_av_retry db 10 25
|
2011-07-12 03:45:44 +04:00
|
|
|
sqlite3_test_control_pending_byte $old_pending_byte
|
2011-08-26 09:40:31 +04:00
|
|
|
db close
|
2011-07-12 17:51:05 +04:00
|
|
|
sqlite3_shutdown
|
|
|
|
test_sqlite3_log
|
|
|
|
sqlite3_initialize
|
2011-07-12 03:45:44 +04:00
|
|
|
finish_test
|