make switch tests less sensitive to time (#501)
* make switch tests less sensitive to time * missing new line
This commit is contained in:
parent
b902c030a0
commit
87be2c7f1f
|
@ -98,3 +98,17 @@ proc newBufferStream*(writeHandler: WriteHandler): TestBufferStream =
|
|||
new result
|
||||
result.writeHandler = writeHandler
|
||||
result.initStream()
|
||||
|
||||
proc checkExpiringInternal(cond: proc(): bool): Future[bool] {.async, gcsafe.} =
|
||||
{.gcsafe.}:
|
||||
let start = Moment.now()
|
||||
while true:
|
||||
if Moment.now() > (start + chronos.seconds(5)):
|
||||
return false
|
||||
elif cond():
|
||||
return true
|
||||
else:
|
||||
await sleepAsync(1.millis)
|
||||
|
||||
template checkExpiring*(code: untyped): untyped =
|
||||
checkExpiringInternal(proc(): bool = code)
|
||||
|
|
|
@ -228,8 +228,7 @@ suite "Switch":
|
|||
await switch2.disconnect(switch1.peerInfo)
|
||||
|
||||
check not switch2.isConnected(switch1.peerInfo)
|
||||
await sleepAsync(1.millis)
|
||||
check not switch1.isConnected(switch2.peerInfo)
|
||||
check await(checkExpiring((not switch1.isConnected(switch2.peerInfo))))
|
||||
|
||||
checkTracker(LPChannelTrackerName)
|
||||
checkTracker(SecureConnTrackerName)
|
||||
|
@ -278,8 +277,7 @@ suite "Switch":
|
|||
await switch2.disconnect(switch1.peerInfo)
|
||||
|
||||
check not switch2.isConnected(switch1.peerInfo)
|
||||
await sleepAsync(1.millis)
|
||||
check not switch1.isConnected(switch2.peerInfo)
|
||||
check await(checkExpiring((not switch1.isConnected(switch2.peerInfo))))
|
||||
|
||||
checkTracker(LPChannelTrackerName)
|
||||
checkTracker(SecureConnTrackerName)
|
||||
|
@ -334,8 +332,7 @@ suite "Switch":
|
|||
await switch2.disconnect(switch1.peerInfo)
|
||||
|
||||
check not switch2.isConnected(switch1.peerInfo)
|
||||
await sleepAsync(1.millis)
|
||||
check not switch1.isConnected(switch2.peerInfo)
|
||||
check await(checkExpiring((not switch1.isConnected(switch2.peerInfo))))
|
||||
|
||||
checkTracker(LPChannelTrackerName)
|
||||
checkTracker(SecureConnTrackerName)
|
||||
|
@ -389,8 +386,7 @@ suite "Switch":
|
|||
await switch2.disconnect(switch1.peerInfo)
|
||||
|
||||
check not switch2.isConnected(switch1.peerInfo)
|
||||
await sleepAsync(1.millis)
|
||||
check not switch1.isConnected(switch2.peerInfo)
|
||||
check await(checkExpiring((not switch1.isConnected(switch2.peerInfo))))
|
||||
|
||||
checkTracker(LPChannelTrackerName)
|
||||
checkTracker(SecureConnTrackerName)
|
||||
|
@ -444,8 +440,7 @@ suite "Switch":
|
|||
await switch2.disconnect(switch1.peerInfo)
|
||||
|
||||
check not switch2.isConnected(switch1.peerInfo)
|
||||
await sleepAsync(1.millis)
|
||||
check not switch1.isConnected(switch2.peerInfo)
|
||||
check await(checkExpiring((not switch1.isConnected(switch2.peerInfo))))
|
||||
|
||||
checkTracker(LPChannelTrackerName)
|
||||
checkTracker(SecureConnTrackerName)
|
||||
|
@ -514,8 +509,8 @@ suite "Switch":
|
|||
|
||||
check not switch2.isConnected(switch1.peerInfo)
|
||||
check not switch3.isConnected(switch1.peerInfo)
|
||||
await sleepAsync(1.millis)
|
||||
check not switch1.isConnected(switch2.peerInfo)
|
||||
check await(checkExpiring((not switch1.isConnected(switch2.peerInfo))))
|
||||
check await(checkExpiring((not switch1.isConnected(switch3.peerInfo))))
|
||||
|
||||
checkTracker(LPChannelTrackerName)
|
||||
checkTracker(SecureConnTrackerName)
|
||||
|
|
Loading…
Reference in New Issue