Skip to content

Commit

Permalink
fix: Fix test for filter client receiving messages after restart (#2360)
Browse files Browse the repository at this point in the history
  • Loading branch information
jm-clius committed Jan 19, 2024
1 parent f841454 commit 7de91d9
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions tests/node/test_wakunode_filter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import
suite "Waku Filter - End to End":
var client {.threadvar.}: WakuNode
var clientPeerId {.threadvar.}: PeerId
var clientClone {.threadvar.}: WakuNode
var server {.threadvar.}: WakuNode
var serverRemotePeerInfo {.threadvar.}: RemotePeerInfo
var pubsubTopic {.threadvar.}: PubsubTopic
Expand All @@ -60,20 +61,25 @@ suite "Waku Filter - End to End":
serverKey = generateSecp256k1Key()
clientKey = generateSecp256k1Key()

server = newTestWakuNode(serverKey, parseIpAddress("0.0.0.0"), Port(0))
client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0))
server = newTestWakuNode(serverKey, parseIpAddress("0.0.0.0"), Port(23450))
client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(23451))
clientClone = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(23451)) # Used for testing client restarts

waitFor allFutures(server.start(), client.start())
await allFutures(server.start(), client.start())

waitFor server.mountFilter()
waitFor client.mountFilterClient()
await server.mountFilter()
await client.mountFilterClient()

client.wakuFilterClient.registerPushHandler(messagePushHandler)
serverRemotePeerInfo = server.peerInfo.toRemotePeerInfo()
clientPeerId = client.peerInfo.toRemotePeerInfo().peerId

# Prepare the clone but do not start it
await clientClone.mountFilterClient()
clientClone.wakuFilterClient.registerPushHandler(messagePushHandler)

asyncTeardown:
waitFor allFutures(client.stop(), server.stop())
await allFutures(client.stop(), clientClone.stop(), server.stop())

asyncTest "Client Node receives Push from Server Node, via Filter":
# When a client node subscribes to a filter node
Expand Down Expand Up @@ -142,8 +148,8 @@ suite "Waku Filter - End to End":
serverKey = generateSecp256k1Key()
server = newTestWakuNode(serverKey, parseIpAddress("0.0.0.0"), Port(0))

waitFor server.start()
waitFor server.mountRelay()
await server.start()
await server.mountRelay()

let serverRemotePeerInfo = server.peerInfo.toRemotePeerInfo()

Expand All @@ -155,7 +161,7 @@ suite "Waku Filter - End to End":
# Then the subscription is successful
check (not subscribeResponse.isOk())

xasyncTest "Filter Client Node can receive messages after subscribing and restarting, via Filter":
asyncTest "Filter Client Node can receive messages after subscribing and restarting, via Filter":
# Given a valid filter subscription
let subscribeResponse = await client.filterSubscribe(
some(pubsubTopic), contentTopicSeq, serverRemotePeerInfo
Expand All @@ -165,9 +171,8 @@ suite "Waku Filter - End to End":
server.wakuFilter.subscriptions.subscribedPeerCount() == 1

# And the client node reboots
waitFor client.stop()
waitFor client.start()
client.mountFilterClient()
await client.stop()
await clientClone.start() # Mimic restart by starting the clone

# When a message is sent to the subscribed content topic, via Filter; without refreshing the subscription
let msg = fakeWakuMessage(contentTopic=contentTopic)
Expand All @@ -192,9 +197,8 @@ suite "Waku Filter - End to End":
server.wakuFilter.subscriptions.subscribedPeerCount() == 1

# And the client node reboots
waitFor client.stop()
waitFor client.start()
discard client.mountFilterClient()
await client.stop()
await clientClone.start() # Mimic restart by starting the clone

# When a message is sent to the subscribed content topic, via Relay
let msg = fakeWakuMessage(contentTopic=contentTopic)
Expand All @@ -204,7 +208,7 @@ suite "Waku Filter - End to End":
check (not await pushHandlerFuture.withTimeout(FUTURE_TIMEOUT))

# Given the client refreshes the subscription
let subscribeResponse2 = await client.filterSubscribe(
let subscribeResponse2 = await clientClone.filterSubscribe(
some(pubsubTopic), contentTopicSeq, serverRemotePeerInfo
)
check:
Expand Down

0 comments on commit 7de91d9

Please sign in to comment.