def test_tcp_handler_send(fake_socket, dummy_log_record): handler = TCPHandler(host='127.0.0.1', port=4399, tcp_timeout=5, enabled_flag=True, message_type='splunk', lvl='INFO', enabled_loggers=['awx', 'activity_stream', 'job_events', 'system_tracking']) handler.setFormatter(LogstashFormatter()) with mock.patch('socket.socket', return_value=fake_socket) as sok_init_mock,\ mock.patch('select.select', return_value=([], [fake_socket], [])): handler.emit(dummy_log_record) sok_init_mock.assert_called_once_with(socket.AF_INET, socket.SOCK_STREAM) fake_socket.connect.assert_called_once_with(('127.0.0.1', 4399)) fake_socket.setblocking.assert_called_once_with(0) fake_socket.send.assert_called_once_with(handler.format(dummy_log_record)) fake_socket.close.assert_called_once()
def test_tcp_handler_send(fake_socket, dummy_log_record): handler = TCPHandler(host='127.0.0.1', port=4399, tcp_timeout=5) handler.setFormatter(LogstashFormatter()) with mock.patch('socket.socket', return_value=fake_socket) as sok_init_mock,\ mock.patch('select.select', return_value=([], [fake_socket], [])): handler.emit(dummy_log_record) sok_init_mock.assert_called_once_with(socket.AF_INET, socket.SOCK_STREAM) fake_socket.connect.assert_called_once_with(('127.0.0.1', 4399)) fake_socket.setblocking.assert_called_once_with(0) fake_socket.send.assert_called_once_with( handler.format(dummy_log_record)) fake_socket.close.assert_called_once()
def test_tcp_handler_log_exception(fake_socket, dummy_log_record): handler = TCPHandler(host='127.0.0.1', port=4399, tcp_timeout=5) handler.setFormatter(LogstashFormatter()) with mock.patch('socket.socket', return_value=fake_socket) as sok_init_mock,\ mock.patch('select.select', return_value=([], [], [])),\ mock.patch('awx.main.utils.handlers.logger') as logger_mock: fake_socket.connect.side_effect = Exception("foo") handler.emit(dummy_log_record) sok_init_mock.assert_called_once_with(socket.AF_INET, socket.SOCK_STREAM) logger_mock.exception.assert_called_once() fake_socket.close.assert_called_once() assert not fake_socket.send.called
def test_tcp_handler_log_exception(fake_socket, dummy_log_record): handler = TCPHandler(host='127.0.0.1', port=4399, tcp_timeout=5, enabled_flag=True, message_type='splunk', lvl='INFO', enabled_loggers=['awx', 'activity_stream', 'job_events', 'system_tracking']) handler.setFormatter(LogstashFormatter()) with mock.patch('socket.socket', return_value=fake_socket) as sok_init_mock,\ mock.patch('select.select', return_value=([], [], [])),\ mock.patch('awx.main.utils.handlers.logger') as logger_mock: fake_socket.connect.side_effect = Exception("foo") handler.emit(dummy_log_record) sok_init_mock.assert_called_once_with(socket.AF_INET, socket.SOCK_STREAM) logger_mock.exception.assert_called_once() fake_socket.close.assert_called_once() assert not fake_socket.send.called
def test_https_logging_handler_has_default_http_timeout(): handler = TCPHandler() assert handler.tcp_timeout == 5