fix: rewrite Network - Test Limits for chronos AsyncSemaphore

Signed-off-by: Chrysostomos Nanakos <chris@include.gr>
This commit is contained in:
Chrysostomos Nanakos 2026-05-05 12:07:29 +03:00 committed by Arnaud
parent 7a6b4993b7
commit 80ea4c71cc
No known key found for this signature in database
GPG Key ID: A6C7C781817146FA

View File

@ -1,3 +1,4 @@
import std/importutils
import std/[sequtils, tables] import std/[sequtils, tables]
import pkg/chronos import pkg/chronos
@ -12,6 +13,8 @@ import ../../asynctest
import ../examples import ../examples
import ../helpers import ../helpers
privateAccess(BlockExcNetwork)
asyncchecksuite "Network - Handlers": asyncchecksuite "Network - Handlers":
let let
rng = Rng.instance() rng = Rng.instance()
@ -174,39 +177,40 @@ asyncchecksuite "Network - Senders":
await done.wait(500.millis) await done.wait(500.millis)
# TODO: AsyncSemaphore in chronos requires size > 0, maxInflight = 0 no longer valid asyncchecksuite "Network - Test Limits":
# asyncchecksuite "Network - Test Limits": var
# var switch1, switch2: Switch
# switch1, switch2: Switch network1, network2: BlockExcNetwork
# network1, network2: BlockExcNetwork done: Future[void]
# done: Future[void]
# setup:
# setup: done = newFuture[void]()
# done = newFuture[void]() switch1 = newStandardSwitch()
# switch1 = newStandardSwitch() switch2 = newStandardSwitch()
# switch2 = newStandardSwitch()
# network1 = BlockExcNetwork.new(switch = switch1, maxInflight = 1)
# network1 = BlockExcNetwork.new(switch = switch1, maxInflight = 0) switch1.mount(network1)
# switch1.mount(network1)
# network2 = BlockExcNetwork.new(switch = switch2)
# network2 = BlockExcNetwork.new(switch = switch2) switch2.mount(network2)
# switch2.mount(network2)
# await switch1.start()
# await switch1.start() await switch2.start()
# await switch2.start()
# await switch1.connect(switch2.peerInfo.peerId, switch2.peerInfo.addrs)
# await switch1.connect(switch2.peerInfo.peerId, switch2.peerInfo.addrs)
# teardown:
# teardown: await allFuturesThrowing(switch1.stop(), switch2.stop())
# await allFuturesThrowing(switch1.stop(), switch2.stop())
# test "Concurrent Sends":
# test "Concurrent Sends": network2.handlers.onPresence = proc(
# network2.handlers.onPresence = proc( peer: PeerId, presence: seq[BlockPresence]
# peer: PeerId, presence: seq[BlockPresence] ): Future[void] {.async: (raises: []).} =
# ): Future[void] {.async: (raises: []).} = check false
# check false
# await network1.inflightSema.acquire()
# let fut = network1.send(switch2.peerInfo.peerId, Message())
# let fut = network1.send(switch2.peerInfo.peerId, Message())
# await sleepAsync(100.millis)
# check not fut.finished await sleepAsync(100.millis)
check not fut.finished