When timeout tests fail, print duration

This commit is contained in:
Mark Spanbroek 2020-11-11 10:57:04 +01:00 committed by markspanbroek
parent 4cd2e7a8b9
commit 930f599c73
1 changed files with 6 additions and 5 deletions

View File

@ -10,14 +10,15 @@ suite "timeout":
body body
Moment.now() - start Moment.now() - start
proc `~=`(actual, expected: Duration, precision = 5.milliseconds): bool = template checkDuration(duration, minimum: Duration, overshoot = 5.milliseconds) =
expected <= actual and actual < expected + precision check duration > minimum
check duration < minimum + overshoot
asynctest "can expire": asynctest "can expire":
let duration = measure: let duration = measure:
let timeout = newTimeout(10.milliseconds) let timeout = newTimeout(10.milliseconds)
await timeout.expired() await timeout.expired()
check duration ~= 10.milliseconds checkDuration duration, 10.milliseconds
asynctest "can be reset before expiry": asynctest "can be reset before expiry":
let duration = measure: let duration = measure:
@ -25,7 +26,7 @@ suite "timeout":
await sleepAsync(5.milliseconds) await sleepAsync(5.milliseconds)
timeout.reset(10.milliseconds) timeout.reset(10.milliseconds)
await timeout.expired() await timeout.expired()
check duration ~= 15.milliseconds checkDuration duration, 15.milliseconds
asynctest "can be reset after expiry": asynctest "can be reset after expiry":
let duration = measure: let duration = measure:
@ -33,7 +34,7 @@ suite "timeout":
await timeout.expired() await timeout.expired()
timeout.reset(10.milliseconds) timeout.reset(10.milliseconds)
await timeout.expired() await timeout.expired()
check duration ~= 20.milliseconds checkDuration duration, 20.milliseconds
asynctest "can be stopped": asynctest "can be stopped":
let timeout = newTimeout(10.milliseconds) let timeout = newTimeout(10.milliseconds)