From 47e6eb8b6a1aeb80e8f735ea2677093577d5f439 Mon Sep 17 00:00:00 2001 From: Erik Harding Date: Fri, 17 Apr 2020 13:04:23 +0200 Subject: [PATCH 1/3] fix rabbitmq health check --- .gitignore | 1 + junebug/api.py | 2 +- junebug/tests/test_api.py | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 07d59bc..bdf590d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ _trial_temp .cache/ .coverage ve/ +.vscode diff --git a/junebug/api.py b/junebug/api.py index a4c5933..015a5b7 100644 --- a/junebug/api.py +++ b/junebug/api.py @@ -699,7 +699,7 @@ def return_queue_results(results): 'name': queue['name'], 'stuck': False, 'messages': queue.get('messages'), - 'rate': queue['messages_details']['rate'] + 'rate': queue['messages_stats']['ack_details']['rate'] } if (details['messages'] > 0 and details['rate'] == 0): stuck = True diff --git a/junebug/tests/test_api.py b/junebug/tests/test_api.py index 0b29b44..d8a9100 100644 --- a/junebug/tests/test_api.py +++ b/junebug/tests/test_api.py @@ -1048,7 +1048,7 @@ def test_get_channels_health_check(self): request_list.append( ((b'get', url, mock.ANY, mock.ANY, mock.ANY), (http.OK, {b'Content-Type': b'application/json'}, - b'{"messages": 1256, "messages_details": {"rate": 1.25}, "name": "%s"}' % queue_name))) # noqa + b'{"messages": 1256, "messages_stats": {"ack_details": {"rate": 1.25}}, "name": "%s"}' % queue_name))) # noqa async_failures = [] sequence_stubs = RequestSequence(request_list, async_failures.append) @@ -1112,7 +1112,7 @@ def test_get_channels_and_destinations_health_check(self): request_list.append( ((b'get', url, mock.ANY, mock.ANY, mock.ANY), (http.OK, {b'Content-Type': b'application/json'}, - b'{"messages": 1256, "messages_details": {"rate": 1.25}, "name": "%s"}' % queue_name))) # noqa + b'{"messages": 1256, "messages_stats": {"ack_details": {"rate": 1.25}}, "name": "%s"}' % queue_name))) # noqa response.append({ 'messages': 1256, @@ -1154,7 +1154,7 @@ def test_get_channels_health_check_stuck(self): request_list.append( ((b'get', url, mock.ANY, mock.ANY, mock.ANY), (http.OK, {b'Content-Type': b'application/json'}, - b'{"messages": 1256, "messages_details": {"rate": 0}, "name": "%s"}' % queue_name))) # noqa + b'{"messages": 1256, "messages_stats": {"ack_details": {"rate": 0.0}}, "name": "%s"}' % queue_name))) # noqa async_failures = [] sequence_stubs = RequestSequence(request_list, async_failures.append) From e41ffc0e7192e2f4689d06fdfcea5ef4a9e6d9d7 Mon Sep 17 00:00:00 2001 From: Erik Harding Date: Fri, 17 Apr 2020 13:09:31 +0200 Subject: [PATCH 2/3] fix flake8 --- junebug/api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/junebug/api.py b/junebug/api.py index 015a5b7..0a44a75 100644 --- a/junebug/api.py +++ b/junebug/api.py @@ -699,7 +699,8 @@ def return_queue_results(results): 'name': queue['name'], 'stuck': False, 'messages': queue.get('messages'), - 'rate': queue['messages_stats']['ack_details']['rate'] + 'rate': + queue['messages_stats']['ack_details']['rate'] } if (details['messages'] > 0 and details['rate'] == 0): stuck = True From 7003e87fb4822e031d5081847ef73def24b498f2 Mon Sep 17 00:00:00 2001 From: Erik Harding Date: Fri, 17 Apr 2020 16:05:37 +0200 Subject: [PATCH 3/3] fix http error tests --- junebug/tests/test_api.py | 18 +++++++----------- junebug/utils.py | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/junebug/tests/test_api.py b/junebug/tests/test_api.py index d8a9100..c3da4d7 100644 --- a/junebug/tests/test_api.py +++ b/junebug/tests/test_api.py @@ -78,7 +78,7 @@ def assert_response(self, response, code, description, result, ignore=[]): self.assertEqual(data, { 'status': code, - 'code': http.RESPONSES[code], + 'code': http.RESPONSES.get(code, code), 'description': description, 'result': result, }) @@ -88,12 +88,12 @@ def test_http_error(self): resp = yield self.get('/foobar') yield self.assert_response( resp, http.NOT_FOUND, - 'The requested URL was not found on the server. If you entered ' + 'The requested URL was not found on the server. If you entered ' 'the URL manually please check your spelling and try again.', { 'errors': [{ 'code': 404, 'message': ('404 Not Found: The requested URL was not ' - 'found on the server. If you entered the URL' + 'found on the server. If you entered the URL' ' manually please check your spelling and try' ' again.'), 'type': 'Not Found', @@ -103,20 +103,16 @@ def test_http_error(self): @inlineCallbacks def test_redirect_http_error(self): resp = yield self.get('/channels') - [redirect] = resp.history() yield self.assert_response( - redirect, http.MOVED_PERMANENTLY, + resp, 308, None, { 'errors': [{ - 'code': 301, - 'message': '301 Moved Permanently: None', + 'code': 308, + 'message': '308 Permanent Redirect: None', 'new_url': '%s/channels/' % self.url, - 'type': 'Moved Permanently', + 'type': 'Permanent Redirect', }], }) - yield self.assert_response( - resp, http.OK, - 'channels listed', []) @inlineCallbacks def test_invalid_json_handling(self): diff --git a/junebug/utils.py b/junebug/utils.py index cf853a7..99dacc4 100644 --- a/junebug/utils.py +++ b/junebug/utils.py @@ -14,7 +14,7 @@ def response(req, description, data, code=http.OK): return json.dumps({ 'status': code, - 'code': http.RESPONSES[code], + 'code': http.RESPONSES.get(code, code), 'description': description, 'result': data, }, cls=JSONMessageEncoder)