2023-09-08 09:19:47 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
|
|
|
std/tempfiles,
|
|
|
|
stew/shims/net,
|
|
|
|
testutils/unittests,
|
|
|
|
presto,
|
|
|
|
presto/client as presto_client,
|
|
|
|
libp2p/peerinfo,
|
|
|
|
libp2p/multiaddress,
|
|
|
|
libp2p/crypto/crypto
|
|
|
|
import
|
2024-07-05 22:03:38 +00:00
|
|
|
waku/[
|
|
|
|
waku_node,
|
|
|
|
node/waku_node as waku_node2,
|
|
|
|
# TODO: Remove after moving `git_version` to the app code.
|
|
|
|
waku_api/rest/server,
|
|
|
|
waku_api/rest/client,
|
|
|
|
waku_api/rest/responses,
|
|
|
|
waku_api/rest/health/handlers as health_api,
|
|
|
|
waku_api/rest/health/client as health_api_client,
|
|
|
|
waku_rln_relay,
|
|
|
|
node/health_monitor,
|
|
|
|
],
|
2023-09-08 09:19:47 +00:00
|
|
|
../testlib/common,
|
2023-09-11 06:32:31 +00:00
|
|
|
../testlib/testutils,
|
2023-09-08 09:19:47 +00:00
|
|
|
../testlib/wakucore,
|
|
|
|
../testlib/wakunode
|
|
|
|
|
|
|
|
proc testWakuNode(): WakuNode =
|
|
|
|
let
|
|
|
|
privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet()
|
2023-12-14 06:16:39 +00:00
|
|
|
bindIp = parseIpAddress("0.0.0.0")
|
|
|
|
extIp = parseIpAddress("127.0.0.1")
|
2023-09-08 09:19:47 +00:00
|
|
|
port = Port(0)
|
|
|
|
|
|
|
|
newTestWakuNode(privkey, bindIp, port, some(extIp), some(port))
|
|
|
|
|
|
|
|
suite "Waku v2 REST API - health":
|
2023-09-11 06:32:31 +00:00
|
|
|
# TODO: better test for health
|
2024-04-23 16:53:18 +00:00
|
|
|
asyncTest "Get node health info - GET /health":
|
2023-09-08 09:19:47 +00:00
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
2024-04-23 16:53:18 +00:00
|
|
|
let healthMonitor = WakuNodeHealthMonitor()
|
2023-09-08 09:19:47 +00:00
|
|
|
await node.start()
|
|
|
|
await node.mountRelay()
|
|
|
|
|
2024-04-23 16:53:18 +00:00
|
|
|
healthMonitor.setOverallHealth(HealthStatus.INITIALIZING)
|
|
|
|
|
2024-06-12 13:07:33 +00:00
|
|
|
var restPort = Port(0)
|
2023-12-14 06:16:39 +00:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 08:48:14 +00:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2024-06-12 13:07:33 +00:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2023-09-08 09:19:47 +00:00
|
|
|
|
2024-04-23 16:53:18 +00:00
|
|
|
installHealthApiHandler(restServer.router, healthMonitor)
|
2023-09-08 09:19:47 +00:00
|
|
|
restServer.start()
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
|
|
# When
|
|
|
|
var response = await client.healthCheck()
|
|
|
|
|
|
|
|
# Then
|
|
|
|
check:
|
2024-04-23 16:53:18 +00:00
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data ==
|
|
|
|
HealthReport(nodeHealth: HealthStatus.INITIALIZING, protocolsHealth: @[])
|
2023-09-08 09:19:47 +00:00
|
|
|
|
|
|
|
# now kick in rln (currently the only check for health)
|
2024-03-15 23:08:47 +00:00
|
|
|
await node.mountRlnRelay(
|
|
|
|
WakuRlnConfig(
|
|
|
|
rlnRelayDynamic: false,
|
|
|
|
rlnRelayCredIndex: some(1.uint),
|
|
|
|
rlnEpochSizeSec: 1,
|
|
|
|
rlnRelayTreePath: genTempPath("rln_tree", "wakunode"),
|
|
|
|
)
|
|
|
|
)
|
2024-04-23 16:53:18 +00:00
|
|
|
healthMonitor.setNode(node)
|
|
|
|
healthMonitor.setOverallHealth(HealthStatus.READY)
|
2023-09-08 09:19:47 +00:00
|
|
|
# When
|
|
|
|
response = await client.healthCheck()
|
|
|
|
|
|
|
|
# Then
|
|
|
|
check:
|
|
|
|
response.status == 200
|
2024-04-23 16:53:18 +00:00
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.nodeHealth == HealthStatus.READY
|
|
|
|
response.data.protocolsHealth.len() == 1
|
|
|
|
response.data.protocolsHealth[0].protocol == "Rln Relay"
|
|
|
|
response.data.protocolsHealth[0].health == HealthStatus.READY
|
2023-09-08 09:19:47 +00:00
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|