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
|
|
|
|
../../waku/waku_node,
|
|
|
|
../../waku/node/waku_node as waku_node2, # TODO: Remove after moving `git_version` to the app code.
|
2023-09-22 13:36:46 +00:00
|
|
|
../../waku/waku_api/rest/server,
|
|
|
|
../../waku/waku_api/rest/client,
|
|
|
|
../../waku/waku_api/rest/responses,
|
|
|
|
../../waku/waku_api/rest/health/handlers as health_api,
|
|
|
|
../../waku/waku_api/rest/health/client as health_api_client,
|
2023-09-08 09:19:47 +00:00
|
|
|
../../waku/waku_rln_relay,
|
|
|
|
../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
|
|
|
|
xasyncTest "Get node health info - GET /health":
|
2023-09-08 09:19:47 +00:00
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
await node.mountRelay()
|
|
|
|
|
|
|
|
let restPort = Port(58001)
|
2023-12-14 06:16:39 +00:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2023-09-08 09:19:47 +00:00
|
|
|
let restServer = RestServerRef.init(restAddress, restPort).tryGet()
|
|
|
|
|
|
|
|
installHealthApiHandler(restServer.router, node)
|
|
|
|
restServer.start()
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
|
|
# When
|
|
|
|
var response = await client.healthCheck()
|
|
|
|
|
|
|
|
# Then
|
|
|
|
check:
|
|
|
|
response.status == 503
|
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
|
|
|
response.data == "Node is not ready"
|
|
|
|
|
|
|
|
# now kick in rln (currently the only check for health)
|
|
|
|
await node.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
|
|
|
rlnRelayCredIndex: some(1.uint),
|
2024-02-28 16:19:20 +00:00
|
|
|
rlnEpochSizeSec: 1,
|
2023-09-08 09:19:47 +00:00
|
|
|
rlnRelayTreePath: genTempPath("rln_tree", "wakunode"),
|
|
|
|
))
|
|
|
|
|
|
|
|
# When
|
|
|
|
response = await client.healthCheck()
|
|
|
|
|
|
|
|
# Then
|
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
|
|
|
response.data == "Node is healthy"
|
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|