Skip to content

Commit 84eb26d

Browse files
committed
chore: test for the 'strict_status_code' param
1 parent 6ecd7db commit 84eb26d

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

hathor/healthcheck/resources/healthcheck.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ def render_GET(self, request):
4747
checks={c.component_name: [c] for c in components_health_checks},
4848
)
4949

50-
if not strict_status_code:
50+
if strict_status_code:
51+
request.setResponseCode(200)
52+
else:
5153
status_code = health_check.get_http_status_code()
5254
request.setResponseCode(status_code)
5355

tests/resources/healthcheck/test_healthcheck.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@ def test_get_no_recent_activity(self):
2525
response = yield self.web.get("/health")
2626
data = response.json_value()
2727

28+
self.assertEqual(response.responseCode, 503)
29+
self.assertEqual(data, {
30+
'status': 'fail',
31+
'description': ANY,
32+
'checks': {
33+
'sync': [{
34+
'componentType': 'internal',
35+
'status': 'fail',
36+
'output': HathorManager.UnhealthinessReason.NO_RECENT_ACTIVITY,
37+
'time': ANY
38+
}]
39+
}
40+
})
41+
42+
@inlineCallbacks
43+
def test_strict_status_code(self):
44+
"""Make sure the 'strict_status_code' parameter is working.
45+
The node should return 200 even if it's not ready.
46+
"""
47+
response = yield self.web.get("/health", {b'strict_status_code': b'1'})
48+
data = response.json_value()
49+
50+
self.assertEqual(response.responseCode, 200)
2851
self.assertEqual(data, {
2952
'status': 'fail',
3053
'description': ANY,
@@ -50,6 +73,7 @@ def test_get_no_connected_peer(self):
5073
response = yield self.web.get("/health")
5174
data = response.json_value()
5275

76+
self.assertEqual(response.responseCode, 503)
5377
self.assertEqual(data, {
5478
'status': 'fail',
5579
'description': ANY,
@@ -78,9 +102,10 @@ def test_get_peer_out_of_sync(self):
78102

79103
self.assertEqual(self.manager2.state, self.manager2.NodeState.READY)
80104

81-
response = yield self.web.get("p2p/readiness")
105+
response = yield self.web.get("/health")
82106
data = response.json_value()
83107

108+
self.assertEqual(response.responseCode, 503)
84109
self.assertEqual(data, {
85110
'status': 'fail',
86111
'description': ANY,
@@ -109,9 +134,10 @@ def test_get_ready(self):
109134
self.conn1.run_one_step(debug=True)
110135
self.clock.advance(0.1)
111136

112-
response = yield self.web.get("p2p/readiness")
137+
response = yield self.web.get("/health")
113138
data = response.json_value()
114139

140+
self.assertEqual(response.responseCode, 200)
115141
self.assertEqual(data, {
116142
'status': 'pass',
117143
'description': ANY,

0 commit comments

Comments
 (0)