adding debug logs to waku_store_legacy/test_client.nim

This commit is contained in:
Gabriel mermelstein 2024-05-09 19:06:28 +02:00
parent fa26d05f8e
commit 67e0306828
No known key found for this signature in database
GPG Key ID: 82B8134785FEAE0D
1 changed files with 41 additions and 0 deletions

View File

@ -32,11 +32,15 @@ suite "Store Client":
var clientPeerInfo {.threadvar.}: RemotePeerInfo var clientPeerInfo {.threadvar.}: RemotePeerInfo
asyncSetup: asyncSetup:
echo "-------------------- 1 --------------------"
message1 = fakeWakuMessage(contentTopic = DefaultContentTopic) message1 = fakeWakuMessage(contentTopic = DefaultContentTopic)
message2 = fakeWakuMessage(contentTopic = DefaultContentTopic) message2 = fakeWakuMessage(contentTopic = DefaultContentTopic)
message3 = fakeWakuMessage(contentTopic = DefaultContentTopic) message3 = fakeWakuMessage(contentTopic = DefaultContentTopic)
echo "-------------------- 2 --------------------"
messageSeq = @[message1, message2, message3] messageSeq = @[message1, message2, message3]
echo "-------------------- 3 --------------------"
handlerFuture = newLegacyHistoryFuture() handlerFuture = newLegacyHistoryFuture()
echo "-------------------- 4 --------------------"
handler = proc(req: HistoryQuery): Future[HistoryResult] {.async, gcsafe.} = handler = proc(req: HistoryQuery): Future[HistoryResult] {.async, gcsafe.} =
handlerFuture.complete(req) handlerFuture.complete(req)
return ok(HistoryResponse(messages: messageSeq)) return ok(HistoryResponse(messages: messageSeq))
@ -48,14 +52,20 @@ suite "Store Client":
serverSwitch = newTestSwitch() serverSwitch = newTestSwitch()
clientSwitch = newTestSwitch() clientSwitch = newTestSwitch()
echo "-------------------- 5 --------------------"
server = await newTestWakuStore(serverSwitch, handler = handler) server = await newTestWakuStore(serverSwitch, handler = handler)
echo "-------------------- 6 --------------------"
client = newTestWakuStoreClient(clientSwitch) client = newTestWakuStoreClient(clientSwitch)
echo "-------------------- 7 --------------------"
await allFutures(serverSwitch.start(), clientSwitch.start()) await allFutures(serverSwitch.start(), clientSwitch.start())
echo "-------------------- 8 --------------------"
serverPeerInfo = serverSwitch.peerInfo.toRemotePeerInfo() serverPeerInfo = serverSwitch.peerInfo.toRemotePeerInfo()
echo "-------------------- 9 --------------------"
clientPeerInfo = clientSwitch.peerInfo.toRemotePeerInfo() clientPeerInfo = clientSwitch.peerInfo.toRemotePeerInfo()
echo "-------------------- 10 --------------------"
asyncTeardown: asyncTeardown:
await allFutures(serverSwitch.stop(), clientSwitch.stop()) await allFutures(serverSwitch.stop(), clientSwitch.stop())
@ -63,15 +73,20 @@ suite "Store Client":
suite "HistoryQuery Creation and Execution": suite "HistoryQuery Creation and Execution":
asyncTest "Valid Queries": asyncTest "Valid Queries":
# When a valid query is sent to the server # When a valid query is sent to the server
echo "-------------------- 11 --------------------"
let queryResponse = await client.query(historyQuery, peer = serverPeerInfo) let queryResponse = await client.query(historyQuery, peer = serverPeerInfo)
echo "-------------------- 12 --------------------"
# Then the query is processed successfully # Then the query is processed successfully
assert await handlerFuture.withTimeout(FUTURE_TIMEOUT) assert await handlerFuture.withTimeout(FUTURE_TIMEOUT)
echo "-------------------- 13 --------------------"
check: check:
handlerFuture.read() == historyQuery handlerFuture.read() == historyQuery
queryResponse.get().messages == messageSeq queryResponse.get().messages == messageSeq
echo "-------------------- 14 --------------------"
asyncTest "Invalid Queries": asyncTest "Invalid Queries":
echo "-------------------- 15 --------------------"
# TODO: IMPROVE: We can't test "actual" invalid queries because # TODO: IMPROVE: We can't test "actual" invalid queries because
# it directly depends on the handler implementation, to achieve # it directly depends on the handler implementation, to achieve
# proper coverage we'd need an example implementation. # proper coverage we'd need an example implementation.
@ -111,86 +126,112 @@ suite "Store Client":
endTime: some(-1.Timestamp), endTime: some(-1.Timestamp),
) )
echo "-------------------- 16 --------------------"
# When the query is sent to the server # When the query is sent to the server
let queryResponse1 = await client.query(invalidQuery1, peer = serverPeerInfo) let queryResponse1 = await client.query(invalidQuery1, peer = serverPeerInfo)
echo "-------------------- 17 --------------------"
# Then the query is not processed # Then the query is not processed
assert await handlerFuture.withTimeout(FUTURE_TIMEOUT) assert await handlerFuture.withTimeout(FUTURE_TIMEOUT)
echo "-------------------- 18 --------------------"
check: check:
handlerFuture.read() == invalidQuery1 handlerFuture.read() == invalidQuery1
queryResponse1.get().messages == messageSeq queryResponse1.get().messages == messageSeq
echo "-------------------- 19 --------------------"
# When the query is sent to the server # When the query is sent to the server
handlerFuture = newLegacyHistoryFuture() handlerFuture = newLegacyHistoryFuture()
let queryResponse2 = await client.query(invalidQuery2, peer = serverPeerInfo) let queryResponse2 = await client.query(invalidQuery2, peer = serverPeerInfo)
echo "-------------------- 20 --------------------"
# Then the query is not processed # Then the query is not processed
assert await handlerFuture.withTimeout(FUTURE_TIMEOUT) assert await handlerFuture.withTimeout(FUTURE_TIMEOUT)
echo "-------------------- 21 --------------------"
check: check:
handlerFuture.read() == invalidQuery2 handlerFuture.read() == invalidQuery2
queryResponse2.get().messages == messageSeq queryResponse2.get().messages == messageSeq
echo "-------------------- 22 --------------------"
# When the query is sent to the server # When the query is sent to the server
handlerFuture = newLegacyHistoryFuture() handlerFuture = newLegacyHistoryFuture()
let queryResponse3 = await client.query(invalidQuery3, peer = serverPeerInfo) let queryResponse3 = await client.query(invalidQuery3, peer = serverPeerInfo)
echo "-------------------- 23 --------------------"
# Then the query is not processed # Then the query is not processed
assert await handlerFuture.withTimeout(FUTURE_TIMEOUT) assert await handlerFuture.withTimeout(FUTURE_TIMEOUT)
echo "-------------------- 24 --------------------"
check: check:
handlerFuture.read() == invalidQuery3 handlerFuture.read() == invalidQuery3
queryResponse3.get().messages == messageSeq queryResponse3.get().messages == messageSeq
echo "-------------------- 25 --------------------"
# When the query is sent to the server # When the query is sent to the server
handlerFuture = newLegacyHistoryFuture() handlerFuture = newLegacyHistoryFuture()
let queryResponse4 = await client.query(invalidQuery4, peer = serverPeerInfo) let queryResponse4 = await client.query(invalidQuery4, peer = serverPeerInfo)
echo "-------------------- 26 --------------------"
# Then the query is not processed # Then the query is not processed
assert await handlerFuture.withTimeout(FUTURE_TIMEOUT) assert await handlerFuture.withTimeout(FUTURE_TIMEOUT)
echo "-------------------- 27 --------------------"
check: check:
handlerFuture.read() == invalidQuery4 handlerFuture.read() == invalidQuery4
queryResponse4.get().messages == messageSeq queryResponse4.get().messages == messageSeq
echo "-------------------- 28 --------------------"
# When the query is sent to the server # When the query is sent to the server
handlerFuture = newLegacyHistoryFuture() handlerFuture = newLegacyHistoryFuture()
let queryResponse5 = await client.query(invalidQuery5, peer = serverPeerInfo) let queryResponse5 = await client.query(invalidQuery5, peer = serverPeerInfo)
echo "-------------------- 29 --------------------"
# Then the query is not processed # Then the query is not processed
assert await handlerFuture.withTimeout(FUTURE_TIMEOUT) assert await handlerFuture.withTimeout(FUTURE_TIMEOUT)
echo "-------------------- 30 --------------------"
check: check:
handlerFuture.read() == invalidQuery5 handlerFuture.read() == invalidQuery5
queryResponse5.get().messages == messageSeq queryResponse5.get().messages == messageSeq
echo "-------------------- 31 --------------------"
# When the query is sent to the server # When the query is sent to the server
handlerFuture = newLegacyHistoryFuture() handlerFuture = newLegacyHistoryFuture()
let queryResponse6 = await client.query(invalidQuery6, peer = serverPeerInfo) let queryResponse6 = await client.query(invalidQuery6, peer = serverPeerInfo)
echo "-------------------- 32 --------------------"
# Then the query is not processed # Then the query is not processed
assert await handlerFuture.withTimeout(FUTURE_TIMEOUT) assert await handlerFuture.withTimeout(FUTURE_TIMEOUT)
echo "-------------------- 33 --------------------"
check: check:
handlerFuture.read() == invalidQuery6 handlerFuture.read() == invalidQuery6
queryResponse6.get().messages == messageSeq queryResponse6.get().messages == messageSeq
echo "-------------------- 34 --------------------"
suite "Verification of HistoryResponse Payload": suite "Verification of HistoryResponse Payload":
asyncTest "Positive Responses": asyncTest "Positive Responses":
echo "-------------------- 35 --------------------"
# When a valid query is sent to the server # When a valid query is sent to the server
let queryResponse = await client.query(historyQuery, peer = serverPeerInfo) let queryResponse = await client.query(historyQuery, peer = serverPeerInfo)
echo "-------------------- 36 --------------------"
# Then the query is processed successfully, and is of the expected type # Then the query is processed successfully, and is of the expected type
check: check:
await handlerFuture.withTimeout(FUTURE_TIMEOUT) await handlerFuture.withTimeout(FUTURE_TIMEOUT)
type(queryResponse.get()) is HistoryResponse type(queryResponse.get()) is HistoryResponse
echo "-------------------- 37 --------------------"
asyncTest "Negative Responses - PeerDialFailure": asyncTest "Negative Responses - PeerDialFailure":
echo "-------------------- 38 --------------------"
# Given a stopped peer # Given a stopped peer
let let
otherServerSwitch = newTestSwitch() otherServerSwitch = newTestSwitch()
otherServerPeerInfo = otherServerSwitch.peerInfo.toRemotePeerInfo() otherServerPeerInfo = otherServerSwitch.peerInfo.toRemotePeerInfo()
echo "-------------------- 39 --------------------"
# When a query is sent to the stopped peer # When a query is sent to the stopped peer
let queryResponse = await client.query(historyQuery, peer = otherServerPeerInfo) let queryResponse = await client.query(historyQuery, peer = otherServerPeerInfo)
echo "-------------------- 40 --------------------"
# Then the query is not processed # Then the query is not processed
check: check:
not await handlerFuture.withTimeout(FUTURE_TIMEOUT) not await handlerFuture.withTimeout(FUTURE_TIMEOUT)
queryResponse.isErr() queryResponse.isErr()
queryResponse.error.kind == HistoryErrorKind.PEER_DIAL_FAILURE queryResponse.error.kind == HistoryErrorKind.PEER_DIAL_FAILURE
echo "-------------------- 41 --------------------"