Skip to content

Commit

Permalink
fix: node restart test issue (#2576)
Browse files Browse the repository at this point in the history
* test_protocol.nim: enhance test reboot and connect

- Is not necessary to start the node if the switch object has been
already started
- Enable an existing "Relay can receive messages after reboot and
reconnect" test
- Explicit reconnect to peer in "Relay can receive messages after reboot
and reconnect" test

* tests/waku_relay/utils: avoid starting the proto again in newTestSwitch proc
With that, we avoid double start of the protocol.

* bump nim-libp2p
  • Loading branch information
Ivansete-status authored Apr 18, 2024
1 parent 828583a commit 4a8e62a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
20 changes: 12 additions & 8 deletions tests/waku_relay/test_protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ suite "Waku Relay":
pubsubTopicSeq = @[pubsubTopic]
wakuMessage = fakeWakuMessage(testMessage, pubsubTopic)

await allFutures(switch.start(), node.start())
await allFutures(switch.start())

remotePeerInfo = switch.peerInfo.toRemotePeerInfo()
peerId = remotePeerInfo.peerId

asyncTeardown:
await allFutures(switch.stop(), node.stop())
await allFutures(switch.stop())

suite "Subscribe":
asyncTest "Publish without Subscription":
Expand Down Expand Up @@ -1210,14 +1210,14 @@ suite "Waku Relay":
await allFutures(otherSwitch.stop(), otherNode.stop())

suite "Security and Privacy":
xasyncTest "Relay can receive messages after reboot and reconnect":
asyncTest "Relay can receive messages after reboot and reconnect":
# Given a second node connected to the first one
let
otherSwitch = newTestSwitch()
otherPeerManager = PeerManager.new(otherSwitch)
otherNode = await newTestWakuRelay(otherSwitch)

await allFutures(otherSwitch.start(), otherNode.start())
await otherSwitch.start()
let
otherRemotePeerInfo = otherSwitch.peerInfo.toRemotePeerInfo()
otherPeerId = otherRemotePeerInfo.peerId
Expand All @@ -1239,8 +1239,11 @@ suite "Waku Relay":
await sleepAsync(500.millis)

# Given other node is stopped and restarted
await allFutures(otherSwitch.stop(), otherNode.stop())
await allFutures(otherSwitch.start(), otherNode.start())
await otherSwitch.stop()
await otherSwitch.start()

check await peerManager.connectRelay(otherRemotePeerInfo)

# FIXME: Once stopped and started, nodes are not considered connected, nor do they reconnect after running connectRelay, as below
# check await otherPeerManager.connectRelay(otherRemotePeerInfo)

Expand Down Expand Up @@ -1269,8 +1272,9 @@ suite "Waku Relay":
(pubsubTopic, msg2) == otherHandlerFuture.read()

# Given node is stopped and restarted
await allFutures(switch.stop(), node.stop())
await allFutures(switch.start(), node.start())
await switch.stop()
await switch.start()
check await peerManager.connectRelay(otherRemotePeerInfo)

# When sending a message from node
handlerFuture = newPushHandlerFuture()
Expand Down
1 change: 0 additions & 1 deletion tests/waku_relay/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ proc noopRawHandler*(): WakuRelayHandler =

proc newTestWakuRelay*(switch = newTestSwitch()): Future[WakuRelay] {.async.} =
let proto = WakuRelay.new(switch).tryGet()
await proto.start()

let protocolMatcher = proc(proto: string): bool {.gcsafe.} =
return proto.startsWith(WakuRelayCodec)
Expand Down
1 change: 0 additions & 1 deletion waku/waku_relay/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const TopicParameters = TopicParams(

# see: https://rfc.vac.dev/spec/29/#gossipsub-v10-parameters
const GossipsubParameters = GossipSubParams.init(
explicit = true,
pruneBackoff = chronos.minutes(1),
unsubscribeBackoff = chronos.seconds(5),
floodPublish = true,
Expand Down

0 comments on commit 4a8e62a

Please sign in to comment.