Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use await instead of waitFor in async tests #2690

Merged
merged 8 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 21 additions & 15 deletions tests/node/peer_manager/test_peer_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ suite "Peer Manager":
asyncTest "light client is not disconnected":
# Given two nodes with the same shardId
let
server =
newTestWakuNode(serverKey, listenAddress, listenPort, pubsubTopics = @[shardTopic0])
client =
newTestWakuNode(clientKey, listenAddress, listenPort, pubsubTopics = @[shardTopic1])
server = newTestWakuNode(
serverKey, listenAddress, listenPort, pubsubTopics = @[shardTopic0]
)
client = newTestWakuNode(
clientKey, listenAddress, listenPort, pubsubTopics = @[shardTopic1]
)

# And both mount metadata and filter
discard client.mountMetadata(0) # clusterId irrelevant, overridden by topic
Expand All @@ -46,7 +48,7 @@ suite "Peer Manager":
await server.mountFilter()

# And both nodes are started
waitFor allFutures(server.start(), client.start())
await allFutures(server.start(), client.start())
await sleepAsync(FUTURE_TIMEOUT)

# And the nodes are connected
Expand All @@ -67,10 +69,12 @@ suite "Peer Manager":
asyncTest "relay with same shardId is not disconnected":
# Given two nodes with the same shardId
let
server =
newTestWakuNode(serverKey, listenAddress, listenPort, pubsubTopics = @[shardTopic0])
client =
newTestWakuNode(clientKey, listenAddress, listenPort, pubsubTopics = @[shardTopic0])
server = newTestWakuNode(
serverKey, listenAddress, listenPort, pubsubTopics = @[shardTopic0]
)
client = newTestWakuNode(
clientKey, listenAddress, listenPort, pubsubTopics = @[shardTopic0]
)

# And both mount metadata and relay
discard client.mountMetadata(0) # clusterId irrelevant, overridden by topic
Expand All @@ -79,7 +83,7 @@ suite "Peer Manager":
await server.mountRelay()

# And both nodes are started
waitFor allFutures(server.start(), client.start())
await allFutures(server.start(), client.start())
await sleepAsync(FUTURE_TIMEOUT)

# And the nodes are connected
Expand All @@ -98,10 +102,12 @@ suite "Peer Manager":
asyncTest "relay with different shardId is disconnected":
# Given two nodes with different shardIds
let
server =
newTestWakuNode(serverKey, listenAddress, listenPort, pubsubTopics = @[shardTopic0])
client =
newTestWakuNode(clientKey, listenAddress, listenPort, pubsubTopics = @[shardTopic1])
server = newTestWakuNode(
serverKey, listenAddress, listenPort, pubsubTopics = @[shardTopic0]
)
client = newTestWakuNode(
clientKey, listenAddress, listenPort, pubsubTopics = @[shardTopic1]
)

# And both mount metadata and relay
discard client.mountMetadata(0) # clusterId irrelevant, overridden by topic
Expand All @@ -110,7 +116,7 @@ suite "Peer Manager":
await server.mountRelay()

# And both nodes are started
waitFor allFutures(server.start(), client.start())
await allFutures(server.start(), client.start())
await sleepAsync(FUTURE_TIMEOUT)

# And the nodes are connected
Expand Down
48 changes: 24 additions & 24 deletions tests/node/test_wakunode_legacy_store.nim
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ suite "Waku Store - End to End - Sorted Archive":
let mountArchiveResult = server.mountArchive(archiveDriver)
assert mountArchiveResult.isOk()

waitFor server.mountLegacyStore()
await server.mountLegacyStore()
client.mountLegacyStoreClient()

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

serverRemotePeerInfo = server.peerInfo.toRemotePeerInfo()
clientPeerId = client.peerInfo.toRemotePeerInfo().peerId

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

suite "Message Pagination":
asyncTest "Forward Pagination":
Expand Down Expand Up @@ -448,9 +448,9 @@ suite "Waku Store - End to End - Sorted Archive":
otherServer.mountArchive(otherArchiveDriverWithMessages)
assert mountOtherArchiveResult.isOk()

waitFor otherServer.mountLegacyStore()
await otherServer.mountLegacyStore()

waitFor otherServer.start()
await otherServer.start()
let otherServerRemotePeerInfo = otherServer.peerInfo.toRemotePeerInfo()

# When making a history query to the first server node
Expand Down Expand Up @@ -479,7 +479,7 @@ suite "Waku Store - End to End - Sorted Archive":
otherQueryResponse.get().messages == archiveMessages[5 ..< 10]

# Cleanup
waitFor otherServer.stop()
await otherServer.stop()

suite "Waku Store - End to End - Unsorted Archive":
var pubsubTopic {.threadvar.}: PubsubTopic
Expand Down Expand Up @@ -536,15 +536,15 @@ suite "Waku Store - End to End - Unsorted Archive":

assert mountUnsortedArchiveResult.isOk()

waitFor server.mountLegacyStore()
await server.mountLegacyStore()
client.mountLegacyStoreClient()

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

serverRemotePeerInfo = server.peerInfo.toRemotePeerInfo()

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

asyncTest "Basic (Timestamp and Digest) Sorting Validation":
# When making a history query
Expand Down Expand Up @@ -691,15 +691,15 @@ suite "Waku Store - End to End - Archive with Multiple Topics":

assert mountSortedArchiveResult.isOk()

waitFor server.mountLegacyStore()
await server.mountLegacyStore()
client.mountLegacyStoreClient()

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

serverRemotePeerInfo = server.peerInfo.toRemotePeerInfo()

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

suite "Validation of Content Filtering":
asyncTest "Basic Content Filtering":
Expand Down Expand Up @@ -935,8 +935,8 @@ suite "Waku Store - End to End - Archive with Multiple Topics":
ephemeralServer.mountArchive(ephemeralArchiveDriver)
assert mountEphemeralArchiveResult.isOk()

waitFor ephemeralServer.mountLegacyStore()
waitFor ephemeralServer.start()
await ephemeralServer.mountLegacyStore()
await ephemeralServer.start()
let ephemeralServerRemotePeerInfo = ephemeralServer.peerInfo.toRemotePeerInfo()

# When making a history query to the server with only ephemeral messages
Expand All @@ -948,7 +948,7 @@ suite "Waku Store - End to End - Archive with Multiple Topics":
queryResponse.get().messages.len == 0

# Cleanup
waitFor ephemeralServer.stop()
await ephemeralServer.stop()

xasyncTest "Mixed messages":
# Given an archive with both ephemeral and non-ephemeral messages
Expand Down Expand Up @@ -977,8 +977,8 @@ suite "Waku Store - End to End - Archive with Multiple Topics":
mountMixedArchiveResult = mixedServer.mountArchive(mixedArchiveDriver)
assert mountMixedArchiveResult.isOk()

waitFor mixedServer.mountLegacyStore()
waitFor mixedServer.start()
await mixedServer.mountLegacyStore()
await mixedServer.start()
let mixedServerRemotePeerInfo = mixedServer.peerInfo.toRemotePeerInfo()

# When making a history query to the server with mixed messages
Expand All @@ -989,7 +989,7 @@ suite "Waku Store - End to End - Archive with Multiple Topics":
queryResponse.get().messages == nonEphemeralMessages

# Cleanup
waitFor mixedServer.stop()
await mixedServer.stop()

suite "Edge Case Scenarios":
asyncTest "Empty Message Store":
Expand All @@ -1004,8 +1004,8 @@ suite "Waku Store - End to End - Archive with Multiple Topics":
mountEmptyArchiveResult = emptyServer.mountArchive(emptyArchiveDriver)
assert mountEmptyArchiveResult.isOk()

waitFor emptyServer.mountLegacyStore()
waitFor emptyServer.start()
await emptyServer.mountLegacyStore()
await emptyServer.start()
let emptyServerRemotePeerInfo = emptyServer.peerInfo.toRemotePeerInfo()

# When making a history query to the server with an empty archive
Expand All @@ -1016,7 +1016,7 @@ suite "Waku Store - End to End - Archive with Multiple Topics":
queryResponse.get().messages.len == 0

# Cleanup
waitFor emptyServer.stop()
await emptyServer.stop()

asyncTest "Voluminous Message Store":
# Given a voluminous archive (1M+ messages)
Expand All @@ -1036,8 +1036,8 @@ suite "Waku Store - End to End - Archive with Multiple Topics":
voluminousServer.mountArchive(voluminousArchiveDriverWithMessages)
assert mountVoluminousArchiveResult.isOk()

waitFor voluminousServer.mountLegacyStore()
waitFor voluminousServer.start()
await voluminousServer.mountLegacyStore()
await voluminousServer.start()
let voluminousServerRemotePeerInfo = voluminousServer.peerInfo.toRemotePeerInfo()

# Given the following history query
Expand All @@ -1060,7 +1060,7 @@ suite "Waku Store - End to End - Archive with Multiple Topics":
]

# Cleanup
waitFor voluminousServer.stop()
await voluminousServer.stop()

asyncTest "Large contentFilters Array":
# Given a history query with the max contentFilters len, 10
Expand Down
4 changes: 2 additions & 2 deletions tests/node/test_wakunode_lightpush.nim
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ suite "Waku Lightpush - End To End":
await allFutures(server.start(), client.start())
await server.start()

waitFor server.mountRelay()
waitFor server.mountLightpush()
await server.mountRelay()
await server.mountLightpush()
client.mountLightpushClient()

serverRemotePeerInfo = server.peerInfo.toRemotePeerInfo()
Expand Down
Loading
Loading