chore(test): reduce sleepAsync (#1481)

This commit is contained in:
Miran
2025-07-09 09:47:31 +02:00
committed by GitHub
parent 9b33cea225
commit 7ae366d979
10 changed files with 27 additions and 27 deletions

View File

@@ -80,7 +80,7 @@ proc testPubSubDaemonPublish(
await nativeNode.connect(daemonPeer.peer, daemonPeer.addresses)
await sleepAsync(1.seconds)
await sleepAsync(500.millis)
await daemonNode.connect(nativePeer.peerId, nativePeer.addrs)
proc pubsubHandler(
@@ -90,12 +90,12 @@ proc testPubSubDaemonPublish(
asyncDiscard daemonNode.pubsubSubscribe(testTopic, pubsubHandler)
pubsub.subscribe(testTopic, nativeHandler)
await sleepAsync(5.seconds)
await sleepAsync(3.seconds)
proc publisher() {.async.} =
while not finished:
await daemonNode.pubsubPublish(testTopic, msgData)
await sleepAsync(500.millis)
await sleepAsync(250.millis)
await wait(publisher(), 5.minutes) # should be plenty of time
@@ -132,7 +132,7 @@ proc testPubSubNodePublish(
await nativeNode.connect(daemonPeer.peer, daemonPeer.addresses)
await sleepAsync(1.seconds)
await sleepAsync(500.millis)
await daemonNode.connect(nativePeer.peerId, nativePeer.addrs)
var times = 0
@@ -152,12 +152,12 @@ proc testPubSubNodePublish(
discard
pubsub.subscribe(testTopic, nativeHandler)
await sleepAsync(5.seconds)
await sleepAsync(3.seconds)
proc publisher() {.async.} =
while not finished:
discard await pubsub.publish(testTopic, msgData)
await sleepAsync(500.millis)
await sleepAsync(250.millis)
await wait(publisher(), 5.minutes) # should be plenty of time
@@ -210,7 +210,7 @@ proc commonInteropTests*(name: string, swCreator: SwitchCreator) =
await nativeNode.stop()
await daemonNode.close()
await sleepAsync(1.seconds)
await sleepAsync(500.millis)
asyncTest "native -> daemon connection":
var protos = @["/test-stream"]
@@ -292,7 +292,7 @@ proc commonInteropTests*(name: string, swCreator: SwitchCreator) =
await stream.close()
await nativeNode.stop()
await daemonNode.close()
await sleepAsync(1.seconds)
await sleepAsync(500.millis)
asyncTest "native -> daemon websocket connection":
var protos = @["/test-stream"]
@@ -343,7 +343,7 @@ proc commonInteropTests*(name: string, swCreator: SwitchCreator) =
await stream.close()
await nativeNode.stop()
await daemonNode.close()
await sleepAsync(1.seconds)
await sleepAsync(500.millis)
asyncTest "daemon -> native websocket connection":
var protos = @["/test-stream"]

View File

@@ -41,7 +41,7 @@ suite "GossipSub Scoring":
gossipSub.updateScores()
await sleepAsync(100.millis)
await sleepAsync(50.millis)
check:
# test our disconnect mechanics

View File

@@ -481,7 +481,7 @@ suite "Autonat Service":
awaiter = newFuture[void]()
await autonatService.run(switch1)
await sleepAsync(200.millis)
await sleepAsync(100.millis)
check autonatService.networkReachability == NetworkReachability.Reachable
check libp2p_autonat_reachability_confidence.value(["Reachable"]) == 1
@@ -510,6 +510,6 @@ suite "Autonat Service":
await switch2.connect(switch1.peerInfo.peerId, switch1.peerInfo.addrs)
await sleepAsync(500.milliseconds)
await sleepAsync(250.milliseconds)
await allFuturesThrowing(switch1.stop(), switch2.stop())

View File

@@ -86,7 +86,7 @@ suite "Autorelay":
let autorelay = AutoRelayService.new(3, relayClient, checkMA, newRng())
switchClient = createSwitch(relayClient, autorelay)
await allFutures(switchClient.start(), switchRelay.start())
await sleepAsync(500.millis)
await sleepAsync(250.millis)
await switchClient.connect(switchRelay.peerInfo.peerId, switchRelay.peerInfo.addrs)
await fut.wait(1.seconds)
let addresses = autorelay.getAddresses()

View File

@@ -88,7 +88,7 @@ proc pubsubTest(f: set[P2PDaemonFlags]): Future[bool] {.async.} =
var ticket1 = await api1.pubsubSubscribe("test-topic", pubsubHandler1)
var ticket2 = await api2.pubsubSubscribe("test-topic", pubsubHandler2)
await sleepAsync(2.seconds)
await sleepAsync(1.seconds)
var topics1 = await api1.pubsubGetTopics()
var topics2 = await api2.pubsubGetTopics()
@@ -98,10 +98,10 @@ proc pubsubTest(f: set[P2PDaemonFlags]): Future[bool] {.async.} =
var peers2 = await api2.pubsubListPeers("test-topic")
if len(peers1) == 1 and len(peers2) == 1:
# Publish test data via api1.
await sleepAsync(500.milliseconds)
await sleepAsync(250.milliseconds)
await api1.pubsubPublish("test-topic", msgData)
var res =
await one(allFutures(handlerFuture1, handlerFuture2), sleepAsync(10.seconds))
await one(allFutures(handlerFuture1, handlerFuture2), sleepAsync(5.seconds))
await api1.close()
await api2.close()

View File

@@ -115,7 +115,7 @@ suite "Dcutr":
reuseConnection = true,
dir = Direction.Out,
): Future[void] {.async: (raises: [DialFailedError, CancelledError]).} =
await sleepAsync(100.millis)
await sleepAsync(50.millis)
let behindNATSwitch = SwitchStub.new(newStandardSwitch(), connectTimeoutProc)
let publicSwitch = newStandardSwitch()
@@ -194,7 +194,7 @@ suite "Dcutr":
reuseConnection = true,
dir = Direction.Out,
): Future[void] {.async: (raises: [DialFailedError, CancelledError]).} =
await sleepAsync(100.millis)
await sleepAsync(50.millis)
await ductrServerTest(connectProc)

View File

@@ -17,10 +17,10 @@ import ./helpers
suite "Future":
asyncTest "anyCompleted must complete with first completed future":
proc fut1() {.async.} =
await sleepAsync(100.milliseconds)
await sleepAsync(50.milliseconds)
proc fut2() {.async.} =
await sleepAsync(200.milliseconds)
await sleepAsync(100.milliseconds)
proc fut3() {.async.} =
raise newException(CatchableError, "fut3")
@@ -55,10 +55,10 @@ suite "Future":
asyncTest "anyCompleted with timeout":
proc fut1() {.async.} =
await sleepAsync(100.milliseconds)
await sleepAsync(50.milliseconds)
proc fut2() {.async.} =
await sleepAsync(200.milliseconds)
await sleepAsync(100.milliseconds)
proc fut3() {.async: (raises: [ValueError]).} =
# fut3 intentionally specifies raised ValueError

View File

@@ -32,7 +32,7 @@ suite "checkUntilTimeout helpers":
var a = 1
let b = 2
proc makeConditionTrueLater() {.async.} =
await sleepAsync(100.milliseconds)
await sleepAsync(50.milliseconds)
a = 2
asyncSpawn makeConditionTrueLater()
@@ -57,7 +57,7 @@ suite "checkUntilTimeout helpers":
var a = 1
let b = 2
proc makeConditionTrueLater() {.async.} =
await sleepAsync(100.milliseconds)
await sleepAsync(50.milliseconds)
a = 2
asyncSpawn makeConditionTrueLater()

View File

@@ -241,7 +241,7 @@ suite "Hole Punching":
switchAux.peerInfo.peerId, switchAux.peerInfo.addrs
)
await sleepAsync(200.millis)
await sleepAsync(100.millis)
await privatePeerSwitch1.connect(
switchAux2.peerInfo.peerId, switchAux2.peerInfo.addrs
@@ -270,7 +270,7 @@ suite "Hole Punching":
privatePeerSwitch2.connectStub = rcvConnectStub
# wait for hole punching to finish in the background
await sleepAsync(600.millis)
await sleepAsync(300.millis)
await allFuturesThrowing(
privatePeerSwitch1.stop(),

View File

@@ -556,7 +556,7 @@ suite "Mplex":
listenJob.complete()
await mplexListen.handle()
await sleepAsync(1.seconds) # give chronos some slack to process things
await sleepAsync(500.millis) # give chronos some slack to process things
await mplexListen.close()
except CancelledError as exc:
raise exc