From 80ea4c71ccdc4e3ed85ef58cfdfa3198eb8e03bc Mon Sep 17 00:00:00 2001 From: Chrysostomos Nanakos Date: Tue, 5 May 2026 12:07:29 +0300 Subject: [PATCH] fix: rewrite Network - Test Limits for chronos AsyncSemaphore Signed-off-by: Chrysostomos Nanakos --- tests/storage/blockexchange/testnetwork.nim | 76 +++++++++++---------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/tests/storage/blockexchange/testnetwork.nim b/tests/storage/blockexchange/testnetwork.nim index c03cf7db..638f6735 100644 --- a/tests/storage/blockexchange/testnetwork.nim +++ b/tests/storage/blockexchange/testnetwork.nim @@ -1,3 +1,4 @@ +import std/importutils import std/[sequtils, tables] import pkg/chronos @@ -12,6 +13,8 @@ import ../../asynctest import ../examples import ../helpers +privateAccess(BlockExcNetwork) + asyncchecksuite "Network - Handlers": let rng = Rng.instance() @@ -174,39 +177,40 @@ asyncchecksuite "Network - Senders": await done.wait(500.millis) -# TODO: AsyncSemaphore in chronos requires size > 0, maxInflight = 0 no longer valid -# asyncchecksuite "Network - Test Limits": -# var -# switch1, switch2: Switch -# network1, network2: BlockExcNetwork -# done: Future[void] -# -# setup: -# done = newFuture[void]() -# switch1 = newStandardSwitch() -# switch2 = newStandardSwitch() -# -# network1 = BlockExcNetwork.new(switch = switch1, maxInflight = 0) -# switch1.mount(network1) -# -# network2 = BlockExcNetwork.new(switch = switch2) -# switch2.mount(network2) -# -# await switch1.start() -# await switch2.start() -# -# await switch1.connect(switch2.peerInfo.peerId, switch2.peerInfo.addrs) -# -# teardown: -# await allFuturesThrowing(switch1.stop(), switch2.stop()) -# -# test "Concurrent Sends": -# network2.handlers.onPresence = proc( -# peer: PeerId, presence: seq[BlockPresence] -# ): Future[void] {.async: (raises: []).} = -# check false -# -# let fut = network1.send(switch2.peerInfo.peerId, Message()) -# -# await sleepAsync(100.millis) -# check not fut.finished +asyncchecksuite "Network - Test Limits": + var + switch1, switch2: Switch + network1, network2: BlockExcNetwork + done: Future[void] + + setup: + done = newFuture[void]() + switch1 = newStandardSwitch() + switch2 = newStandardSwitch() + + network1 = BlockExcNetwork.new(switch = switch1, maxInflight = 1) + switch1.mount(network1) + + network2 = BlockExcNetwork.new(switch = switch2) + switch2.mount(network2) + + await switch1.start() + await switch2.start() + + await switch1.connect(switch2.peerInfo.peerId, switch2.peerInfo.addrs) + + teardown: + await allFuturesThrowing(switch1.stop(), switch2.stop()) + + test "Concurrent Sends": + network2.handlers.onPresence = proc( + peer: PeerId, presence: seq[BlockPresence] + ): Future[void] {.async: (raises: []).} = + check false + + await network1.inflightSema.acquire() + + let fut = network1.send(switch2.peerInfo.peerId, Message()) + + await sleepAsync(100.millis) + check not fut.finished