def _run_and_wait(self, key, data, content_type='application/json', headers=None, fields=None): headers = base._get_headers(headers, content_type) def wait(): return self.logs_search_client.count_search_messages(key, headers) > 0 self.assertEqual(0, self.logs_search_client.count_search_messages(key, headers), 'Find log message in elasticsearch: {0}'.format(key)) headers = base._get_headers(headers, content_type) data = base._get_data(data) client = self.logs_client response, _ = client.send_single_log(data, headers, fields) self.assertEqual(204, response.status) test_utils.call_until_true(wait, _RETRY_COUNT * _RETRY_WAIT, _RETRY_WAIT) response = self.logs_search_client.search_messages(key, headers) self.assertEqual(1, len(response)) return response
def test_should_reject_too_big_message(self): _, message = base.generate_rejectable_message() headers = base._get_headers(self.logs_client.get_headers()) # Add 'Connection: Keep-Alive' to send large message before # connection is closed by client. In class ClosingHttp is added # header 'connection:close' (which will cause closing socket before sending whole message). # Data are send in small TCP packages. # Without this header set to Keep-Alive Tempest lib will try to retry connection and finally # raise ProtocolError. headers.update({'Connection': 'Keep-Alive'}) data = base._get_data(message) try: self.logs_client.send_single_log(data, headers) except exceptions.OverLimit as urc: self.assertEqual(413, urc.resp.status) return except exceptions.UnexpectedContentType as uct: self.assertEqual(503, uct.resp.status) return self.assertTrue(False, 'API should respond with 413 or 503')