From 930f599c73af91696e81fa68061f91f61e7fdb8a Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 11 Nov 2020 10:57:04 +0100 Subject: [PATCH] When timeout tests fail, print duration --- tests/quic/testTimeout.nim | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/quic/testTimeout.nim b/tests/quic/testTimeout.nim index 8d89a06..af6c123 100644 --- a/tests/quic/testTimeout.nim +++ b/tests/quic/testTimeout.nim @@ -10,14 +10,15 @@ suite "timeout": body Moment.now() - start - proc `~=`(actual, expected: Duration, precision = 5.milliseconds): bool = - expected <= actual and actual < expected + precision + template checkDuration(duration, minimum: Duration, overshoot = 5.milliseconds) = + check duration > minimum + check duration < minimum + overshoot asynctest "can expire": let duration = measure: let timeout = newTimeout(10.milliseconds) await timeout.expired() - check duration ~= 10.milliseconds + checkDuration duration, 10.milliseconds asynctest "can be reset before expiry": let duration = measure: @@ -25,7 +26,7 @@ suite "timeout": await sleepAsync(5.milliseconds) timeout.reset(10.milliseconds) await timeout.expired() - check duration ~= 15.milliseconds + checkDuration duration, 15.milliseconds asynctest "can be reset after expiry": let duration = measure: @@ -33,7 +34,7 @@ suite "timeout": await timeout.expired() timeout.reset(10.milliseconds) await timeout.expired() - check duration ~= 20.milliseconds + checkDuration duration, 20.milliseconds asynctest "can be stopped": let timeout = newTimeout(10.milliseconds)