Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions tests/libp2p/muxers/test_mplex.nim
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,15 @@ suite "Mplex":
await chann.readExactly(addr data[0], 1)
await chann.readExactly(addr data[0], 1)

let rw = @[writer(), reader()]
let readerFut = reader()
let writerFut = writer()

await chann.close()
check await chann.reset()
# this would hang
.withTimeout(100.millis)

check await allFuturesThrowing(allFinished(rw)).withTimeout(100.millis)
check await allFuturesDiscarding(readerFut, writerFut).withTimeout(100.millis)

await conn.close()

Expand Down Expand Up @@ -484,7 +485,7 @@ suite "Mplex":
await conn.close()
await acceptFut.wait(1.seconds)
await mplexDialFut.wait(1.seconds)
await allFuturesThrowing(transport1.stop(), transport2.stop())
await allFuturesDiscarding(transport1.stop(), transport2.stop())
await listenFut

asyncTest "read/write receiver lazy":
Expand Down Expand Up @@ -523,7 +524,7 @@ suite "Mplex":
await conn.close()
await acceptFut.wait(1.seconds)
await mplexDialFut
await allFuturesThrowing(transport1.stop(), transport2.stop())
await allFuturesDiscarding(transport1.stop(), transport2.stop())
await listenFut

asyncTest "write fragmented":
Expand Down Expand Up @@ -576,7 +577,7 @@ suite "Mplex":
await conn.close()
await acceptFut
await mplexDialFut
await allFuturesThrowing(transport1.stop(), transport2.stop())
await allFuturesDiscarding(transport1.stop(), transport2.stop())

await listenFut

Expand Down Expand Up @@ -614,7 +615,7 @@ suite "Mplex":
await conn.close()
await acceptFut.wait(1.seconds)
await mplexDialFut
await allFuturesThrowing(transport1.stop(), transport2.stop())
await allFuturesDiscarding(transport1.stop(), transport2.stop())
await listenFut

asyncTest "multiple streams":
Expand Down Expand Up @@ -662,7 +663,7 @@ suite "Mplex":
await conn.close()
await acceptFut.wait(1.seconds)
await mplexDialFut
await allFuturesThrowing(transport1.stop(), transport2.stop())
await allFuturesDiscarding(transport1.stop(), transport2.stop())
await listenFut

asyncTest "multiple read/write streams":
Expand Down Expand Up @@ -713,7 +714,7 @@ suite "Mplex":
await acceptFut.wait(1.seconds)
await mplexDialFut
await mplexDial.close()
await allFuturesThrowing(transport1.stop(), transport2.stop())
await allFuturesDiscarding(transport1.stop(), transport2.stop())
await listenFut

asyncTest "channel closes listener with EOF":
Expand Down Expand Up @@ -760,7 +761,7 @@ suite "Mplex":

await conn.close()
await mplexDialFut
await allFuturesThrowing(transport1.stop(), transport2.stop())
await allFuturesDiscarding(transport1.stop(), transport2.stop())
await acceptFut

asyncTest "channel closes dialer with EOF":
Expand Down Expand Up @@ -810,13 +811,13 @@ suite "Mplex":
check s.closed

await readLoop
await allFuturesThrowing((dialStreams & listenStreams).mapIt(it.join()))
await allFuturesDiscarding((dialStreams & listenStreams).mapIt(it.join()))

checkTracker(LPChannelTrackerName)

await conn.close()
await mplexDialFut
await allFuturesThrowing(transport1.stop(), transport2.stop())
await allFuturesDiscarding(transport1.stop(), transport2.stop())
await acceptFut

asyncTest "dialing mplex closes both ends":
Expand Down Expand Up @@ -848,13 +849,13 @@ suite "Mplex":
unorderedCompare(dialStreams, mplexDial.getStreams())

await mplexDial.close()
await allFuturesThrowing((dialStreams & listenStreams).mapIt(it.join()))
await allFuturesDiscarding((dialStreams & listenStreams).mapIt(it.join()))

checkTracker(LPChannelTrackerName)

await conn.close()
await mplexDialFut
await allFuturesThrowing(transport1.stop(), transport2.stop())
await allFuturesDiscarding(transport1.stop(), transport2.stop())
await acceptFut

asyncTest "listening mplex closes both ends":
Expand Down Expand Up @@ -890,13 +891,13 @@ suite "Mplex":
listenStreams.len == 10 and dialStreams.len == 10

await mplexListen.close()
await allFuturesThrowing((dialStreams & listenStreams).mapIt(it.join()))
await allFuturesDiscarding((dialStreams & listenStreams).mapIt(it.join()))

checkTracker(LPChannelTrackerName)

await conn.close()
await mplexDialFut
await allFuturesThrowing(transport1.stop(), transport2.stop())
await allFuturesDiscarding(transport1.stop(), transport2.stop())
await acceptFut

asyncTest "canceling mplex handler closes both ends":
Expand Down Expand Up @@ -933,13 +934,13 @@ suite "Mplex":
listenStreams.len == 10 and dialStreams.len == 10

mplexHandle.cancel()
await allFuturesThrowing((dialStreams & listenStreams).mapIt(it.join()))
await allFuturesDiscarding((dialStreams & listenStreams).mapIt(it.join()))

checkTracker(LPChannelTrackerName)

await conn.close()
await mplexDialFut
await allFuturesThrowing(transport1.stop(), transport2.stop())
await allFuturesDiscarding(transport1.stop(), transport2.stop())

asyncTest "closing dialing connection should close both ends":
let ma = @[MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet()]
Expand Down Expand Up @@ -973,13 +974,13 @@ suite "Mplex":
listenStreams.len == 10 and dialStreams.len == 10

await conn.close()
await allFuturesThrowing((dialStreams & listenStreams).mapIt(it.join()))
await allFuturesDiscarding((dialStreams & listenStreams).mapIt(it.join()))

checkTracker(LPChannelTrackerName)

await conn.closeWithEOF()
await mplexDialFut
await allFuturesThrowing(transport1.stop(), transport2.stop())
await allFuturesDiscarding(transport1.stop(), transport2.stop())
await acceptFut

asyncTest "canceling listening connection should close both ends":
Expand Down Expand Up @@ -1015,13 +1016,13 @@ suite "Mplex":
listenStreams.len == 10 and dialStreams.len == 10

await listenConn.closeWithEOF()
await allFuturesThrowing((dialStreams & listenStreams).mapIt(it.join()))
await allFuturesDiscarding((dialStreams & listenStreams).mapIt(it.join()))

checkTracker(LPChannelTrackerName)

await conn.close()
await mplexDialFut
await allFuturesThrowing(transport1.stop(), transport2.stop())
await allFuturesDiscarding(transport1.stop(), transport2.stop())
await acceptFut

suite "jitter":
Expand Down Expand Up @@ -1093,7 +1094,7 @@ suite "Mplex":
await acceptFut
await mplexDialFut

await allFuturesThrowing(transport1.stop(), transport2.stop())
await allFuturesDiscarding(transport1.stop(), transport2.stop())
await listenFut

asyncTest "channel should handle 1 byte read/write":
Expand Down Expand Up @@ -1153,5 +1154,5 @@ suite "Mplex":
await conn.close()
await acceptFut
await mplexDialFut
await allFuturesThrowing(transport1.stop(), transport2.stop())
await allFuturesDiscarding(transport1.stop(), transport2.stop())
await listenFut
22 changes: 11 additions & 11 deletions tests/libp2p/protocols/test_autonat_service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ suite "Autonat Service":
check autonatService.networkReachability == NetworkReachability.NotReachable
check libp2p_autonat_reachability_confidence.value(["NotReachable"]) == 0.3

await allFuturesThrowing(
await allFuturesDiscarding(
switch1.stop(), switch2.stop(), switch3.stop(), switch4.stop()
)

Expand Down Expand Up @@ -125,7 +125,7 @@ suite "Autonat Service":
check switch1.peerInfo.addrs ==
switch1.peerInfo.addrs.mapIt(switch1.peerStore.guessDialableAddr(it))

await allFuturesThrowing(
await allFuturesDiscarding(
switch1.stop(), switch2.stop(), switch3.stop(), switch4.stop()
)

Expand Down Expand Up @@ -177,7 +177,7 @@ suite "Autonat Service":
check autonatService.networkReachability == NetworkReachability.Reachable
check libp2p_autonat_reachability_confidence.value(["Reachable"]) == 0.3

await allFuturesThrowing(
await allFuturesDiscarding(
switch1.stop(), switch2.stop(), switch3.stop(), switch4.stop()
)

Expand Down Expand Up @@ -219,7 +219,7 @@ suite "Autonat Service":
check autonatService.networkReachability == NetworkReachability.Reachable
check libp2p_autonat_reachability_confidence.value(["Reachable"]) == 1

await allFuturesThrowing(
await allFuturesDiscarding(
switch1.stop(), switch2.stop(), switch3.stop(), switch4.stop()
)

Expand Down Expand Up @@ -270,7 +270,7 @@ suite "Autonat Service":
check autonatService.networkReachability == NetworkReachability.NotReachable
check libp2p_autonat_reachability_confidence.value(["NotReachable"]) == 1 / 3

await allFuturesThrowing(
await allFuturesDiscarding(
switch1.stop(), switch2.stop(), switch3.stop(), switch4.stop()
)

Expand All @@ -286,7 +286,7 @@ suite "Autonat Service":
check (await autonatService.stop(switch)) == true
check (await autonatService.stop(switch)) == false

await allFuturesThrowing(switch.stop())
await allFuturesDiscarding(switch.stop())

asyncTest "Must bypass maxConnectionsPerPeer limit":
let autonatService = AutonatService.new(
Expand Down Expand Up @@ -329,7 +329,7 @@ suite "Autonat Service":
check autonatService.networkReachability == NetworkReachability.Reachable
check libp2p_autonat_reachability_confidence.value(["Reachable"]) == 1

await allFuturesThrowing(switch1.stop(), switch2.stop())
await allFuturesDiscarding(switch1.stop(), switch2.stop())

asyncTest "Must work when peers ask each other at the same time with max 1 conn per peer":
let autonatService1 = AutonatService.new(
Expand Down Expand Up @@ -387,7 +387,7 @@ suite "Autonat Service":
check autonatService2.networkReachability == NetworkReachability.Reachable
check libp2p_autonat_reachability_confidence.value(["Reachable"]) == 1

await allFuturesThrowing(switch1.stop(), switch2.stop(), switch3.stop())
await allFuturesDiscarding(switch1.stop(), switch2.stop(), switch3.stop())

asyncTest "Must work for one peer when two peers ask each other at the same time with max 1 conn per peer":
let autonatService1 = AutonatService.new(
Expand Down Expand Up @@ -436,7 +436,7 @@ suite "Autonat Service":
# Make sure remote peer can't create a connection to us
check switch1.connManager.connCount(switch2.peerInfo.peerId) == 1

await allFuturesThrowing(switch1.stop(), switch2.stop())
await allFuturesDiscarding(switch1.stop(), switch2.stop())

asyncTest "Must work with low maxConnections":
let autonatService = AutonatService.new(
Expand Down Expand Up @@ -485,7 +485,7 @@ suite "Autonat Service":
check autonatService.networkReachability == NetworkReachability.Reachable
check libp2p_autonat_reachability_confidence.value(["Reachable"]) == 1

await allFuturesThrowing(
await allFuturesDiscarding(
switch1.stop(), switch2.stop(), switch3.stop(), switch4.stop(), switch5.stop()
)

Expand All @@ -511,4 +511,4 @@ suite "Autonat Service":

await sleepAsync(250.milliseconds)

await allFuturesThrowing(switch1.stop(), switch2.stop())
await allFuturesDiscarding(switch1.stop(), switch2.stop())
12 changes: 6 additions & 6 deletions tests/libp2p/protocols/test_autonat_v2_service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ proc createSwitches(n: int): seq[Switch] =
switches

proc startAll(switches: seq[Switch]) {.async.} =
await allFuturesThrowing(switches.mapIt(it.start()))
await allFuturesDiscarding(switches.mapIt(it.start()))

proc stopAll(switches: seq[Switch]) {.async.} =
await allFuturesThrowing(switches.mapIt(it.stop()))
await allFuturesDiscarding(switches.mapIt(it.stop()))

proc startAndConnect(switch: Switch, switches: seq[Switch]) {.async.} =
await switch.start()
Expand Down Expand Up @@ -335,7 +335,7 @@ suite "AutonatV2 Service":
await awaiter
check service.networkReachability == NetworkReachability.Reachable
check libp2p_autonat_v2_reachability_confidence.value(["Reachable"]) == 1
await allFuturesThrowing(switch1.stop(), switch2.stop())
await allFuturesDiscarding(switch1.stop(), switch2.stop())

asyncTest "Must work when peers ask each other at the same time with max 1 conn per peer":
let
Expand Down Expand Up @@ -400,7 +400,7 @@ suite "AutonatV2 Service":
check service2.networkReachability == NetworkReachability.Reachable
check libp2p_autonat_v2_reachability_confidence.value(["Reachable"]) == 1

await allFuturesThrowing(switch1.stop(), switch2.stop(), switch3.stop())
await allFuturesDiscarding(switch1.stop(), switch2.stop(), switch3.stop())

asyncTest "Must work for one peer when two peers ask each other at the same time with max 1 conn per peer":
let
Expand Down Expand Up @@ -454,7 +454,7 @@ suite "AutonatV2 Service":
# Make sure remote peer can't create a connection to us
check switch1.connManager.connCount(switch2.peerInfo.peerId) == 1

await allFuturesThrowing(switch1.stop(), switch2.stop())
await allFuturesDiscarding(switch1.stop(), switch2.stop())

asyncTest "Must work with low maxConnections":
let (service, client) = newService(
Expand Down Expand Up @@ -524,4 +524,4 @@ suite "AutonatV2 Service":

await sleepAsync(250.milliseconds)

await allFuturesThrowing(switch1.stop(), switch2.stop())
await allFuturesDiscarding(switch1.stop(), switch2.stop())
4 changes: 2 additions & 2 deletions tests/libp2p/protocols/test_noise.nim
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ suite "Noise":
check "Hello!" == msg
await conn.close()

await allFuturesThrowing(switch1.stop(), switch2.stop())
await allFuturesDiscarding(switch1.stop(), switch2.stop())

asyncTest "e2e test wrong secure negotiation":
let ma1 = MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet()
Expand All @@ -296,4 +296,4 @@ suite "Noise":
let conn =
await switch2.dial(switch1.peerInfo.peerId, switch1.peerInfo.addrs, TestCodec)

await allFuturesThrowing(switch1.stop(), switch2.stop())
await allFuturesDiscarding(switch1.stop(), switch2.stop())
12 changes: 6 additions & 6 deletions tests/libp2p/pubsub/component/test_floodsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ suite "FloodSub Component":
for y in 0 ..< runs:
if y != i:
subs &= waitSub(nodes[i], nodes[y], "foobar")
await allFuturesThrowing(subs)
await allFuturesDiscarding(subs)

var pubs: seq[Future[int]]
for i in 0 ..< runs:
pubs &= nodes[i].publish("foobar", ("Hello!" & $i).toBytes())
await allFuturesThrowing(pubs)
await allFuturesDiscarding(pubs)

await allFuturesThrowing(futs.mapIt(it[0]))
await allFuturesDiscarding(futs.mapIt(it[0]))

asyncTest "FloodSub multiple peers, with self trigger":
var runs = 10
Expand Down Expand Up @@ -232,15 +232,15 @@ suite "FloodSub Component":
for y in 0 ..< runs:
if y != i:
subs &= waitSub(nodes[i], nodes[y], "foobar")
await allFuturesThrowing(subs)
await allFuturesDiscarding(subs)

var pubs: seq[Future[int]]
for i in 0 ..< runs:
pubs &= nodes[i].publish("foobar", ("Hello!" & $i).toBytes())
await allFuturesThrowing(pubs)
await allFuturesDiscarding(pubs)

# wait the test task
await allFuturesThrowing(futs.mapIt(it[0]))
await allFuturesDiscarding(futs.mapIt(it[0]))

# test calling unsubscribeAll for coverage
for node in nodes:
Expand Down
Loading
Loading