def test_max_clients_and_healthcheck_timeout(self): with mock.patch.dict(config.config, { 'healthcheck_timeout': 1, 'max_clients': 3 }), mock.patch('hacheck.checker.tornado.httpclient.AsyncHTTPClient', ) as mock_async_http_client, mock.patch( 'hacheck.checker.tornado.httpclient.HTTPRequest', ) as mock_http_request: mock_io_loop = mock.Mock() yield checker.check_http( service_name='service_name', port=1234, query='status/', host='127.0.0.1', io_loop=mock_io_loop, query_params={}, headers=[], ) mock_http_request.assert_called_once_with( 'http://127.0.0.1:1234/status/', method=mock.ANY, headers=mock.ANY, request_timeout=1, follow_redirects=mock.ANY, validate_cert=mock.ANY, ) mock_async_http_client.assert_called_once_with( io_loop=mock_io_loop, max_clients=3, ) mock_async_http_client.return_value.fetch.assert_called_once_with( mock_http_request.return_value, )
def test_query_params_not_passed(self): response = yield checker.check_http("foo", self.get_http_port(), "/echo_foo", io_loop=self.io_loop, query_params="", headers={}) self.assertEqual(400, response[0])
def test_query_params_passed(self): response = yield checker.check_http("foo", self.get_http_port(), "/echo_foo", io_loop=self.io_loop, query_params="foo=bar", headers={}) self.assertEqual((200, b'bar'), response)
def test_check_wrong_port(self): code, response = yield checker.check_http("foo", self.get_http_port() + 1, "/", io_loop=self.io_loop, query_params="", headers={}) self.assertEqual(599, code)
def test_check_failure_with_code(self): code, response = yield checker.check_http("foo", self.get_http_port(), "/bip", io_loop=self.io_loop, query_params="", headers={}) self.assertEqual(501, code)
def test_check_success(self): response = yield checker.check_http("foo", self.get_http_port(), "/", io_loop=self.io_loop, query_params="", headers={}) self.assertEqual((200, b'TEST OK'), response)
def test_service_name_header(self): with mock.patch.dict(config.config, {'service_name_header': 'SName'}): code, response = yield checker.check_http('service_name', self.get_http_port(), "/sname", io_loop=self.io_loop, query_params="", headers={}) self.assertEqual(b'service_name', response)
def check_http_https(self, *args, **kwargs): return checker.check_http(*args, **kwargs)