mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-05-12 06:19:33 +00:00
fix: rewrite Network - Test Limits for chronos AsyncSemaphore
Signed-off-by: Chrysostomos Nanakos <chris@include.gr>
This commit is contained in:
parent
7a6b4993b7
commit
80ea4c71cc
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user