fix: Fix test for filter client receiving messages after restart (#2360)

This commit is contained in:
Hanno Cornelius 2024-01-19 13:05:06 +02:00 committed by GitHub
parent f841454edc
commit 7de91d92bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 16 deletions

View File

@ -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
@ -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
@ -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()
@ -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
@ -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)
@ -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)
@ -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: