diff options
author | sebres <sebres@users.sourceforge.net> | 2018-12-29 10:03:33 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2018-12-29 10:03:33 (GMT) |
commit | b226057ffc9a08d8fe7d8c8a739db9fe15edb436 (patch) | |
tree | 1201068ba0dad77dd5ac2cf9218bd6ac191df600 /tests/clock.test | |
parent | 211afcace9bd190522df92a019f6000774b33cc6 (diff) | |
download | tcl-b226057ffc9a08d8fe7d8c8a739db9fe15edb436.zip tcl-b226057ffc9a08d8fe7d8c8a739db9fe15edb436.tar.gz tcl-b226057ffc9a08d8fe7d8c8a739db9fe15edb436.tar.bz2 |
clock.test: resolve sporadic timing issues - "after 10" could cause pause >120ms on some platforms (especially on heavily loaded systems), so used average value of 5 measured intervals and real retrieved time as reference point
Diffstat (limited to 'tests/clock.test')
-rw-r--r-- | tests/clock.test | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/tests/clock.test b/tests/clock.test index 3ad5c9f..b17c543 100644 --- a/tests/clock.test +++ b/tests/clock.test @@ -252,6 +252,8 @@ proc ::testClock::registry { cmd path key } { proc timeWithinDuration {duration start end} { regexp {([\d.]+)(s|ms|us)} $duration -> duration unit + if {[llength $start] > 1} { set start [expr "([join $start +])/[llength $start]"] } + if {[llength $end] > 1} { set end [expr "([join $end +])/[llength $end]"] } set delta [expr {$end - $start}] expr { ($delta > 0) && ($delta <= $duration) ? @@ -35449,22 +35451,22 @@ test clock-33.4a {clock milliseconds} { concat {} } {} test clock-33.5 {clock clicks tests, millisecond timing test} { - # This test can fail on a system that is so heavily loaded that - # the test takes >120 ms to run. - set start [clock clicks -milli] - after 10 - set end [clock clicks -milli] - # 60 msecs seems to be the max time slice under Windows 95/98; - timeWithinDuration 120ms $start $end + set start [set end {}] + lassign [time { + lappend start [clock clicks -milli] + after 1 {lappend end [clock clicks -milli]} + vwait end + } 5] tm + timeWithinDuration [expr {int($tm/1000 + 1)}]ms $start $end } {ok} test clock-33.5a {clock tests, millisecond timing test} { - # This test can fail on a system that is so heavily loaded that - # the test takes >120 ms to run. - set start [clock milliseconds] - after 10 - set end [clock milliseconds] - # 60 msecs seems to be the max time slice under Windows 95/98 - timeWithinDuration 120ms $start $end + set start [set end {}] + lassign [time { + lappend start [clock milliseconds] + after 1 {lappend end [clock milliseconds]} + vwait end + } 5] tm + timeWithinDuration [expr {int($tm/1000 + 1)}]ms $start $end } {ok} test clock-33.6 {clock clicks, milli with too much abbreviation} { list [catch { clock clicks ? } msg] $msg @@ -35474,20 +35476,22 @@ test clock-33.7 {clock clicks, milli with too much abbreviation} { } {1 {ambiguous option "-": must be -milliseconds or -microseconds}} test clock-33.8 {clock clicks test, microsecond timing test} { - # This test can fail on a system that is so heavily loaded that - # the test takes >120 ms to run. - set start [clock clicks -micro] - after 10 - set end [clock clicks -micro] - timeWithinDuration 120000us $start $end + set start [set end {}] + lassign [time { + lappend start [clock clicks -micro] + after 1 {lappend end [clock clicks -micro]} + vwait end + } 5] tm + timeWithinDuration [expr {int($tm + 10)}]us $start $end } {ok} test clock-33.8a {clock test, microsecond timing test} { - # This test can fail on a system that is so heavily loaded that - # the test takes >120 ms to run. - set start [clock microseconds] - after 10 - set end [clock microseconds] - timeWithinDuration 120000us $start $end + set start [set end {}] + lassign [time { + lappend start [clock microseconds] + after 1 {lappend end [clock microseconds]} + vwait end + } 5] tm + timeWithinDuration [expr {int($tm + 10)}]us $start $end } {ok} test clock-33.9 {clock clicks test, millis align with seconds} { |