diff --git a/rebench/rebenchdb.py b/rebench/rebenchdb.py index 516ba613..914be1ea 100644 --- a/rebench/rebenchdb.py +++ b/rebench/rebenchdb.py @@ -83,9 +83,13 @@ def _send_payload(payload, url): def _get_api_version(self): url = self._server_base_url + '/results' req = HttpRequest(url, method='OPTIONS') - with urlopen(req) as socket: - response = socket.read() - return socket.getheader('X-ReBenchDB-Result-API-Version') + try: + with urlopen(req) as socket: + response = socket.read() + return socket.getheader('X-ReBenchDB-Result-API-Version') + except: + # some error, so no API version available + return None def convert_data_to_json(self, data): return json.dumps(data, separators=(',', ':'), ensure_ascii=True) @@ -116,7 +120,7 @@ def _send_with_retries(self, payload_bytes, url): + "{ind}{ind}" + str(te) + "\n") return False, None except (IOError, HTTPException) as error: - if attempts > 0: + if error.status != 400 and attempts > 0: # let's retry, the benchmark server might just time out, as usual # but let it breath a little self.ui.warning( diff --git a/rebench/tests/mock_http_server.py b/rebench/tests/mock_http_server.py index 1b65dc3b..06546de2 100644 --- a/rebench/tests/mock_http_server.py +++ b/rebench/tests/mock_http_server.py @@ -7,19 +7,19 @@ class _RequestHandler(BaseHTTPRequestHandler): def do_GET(self): - self.send_response(200) + self.send_response(self.server.status_code) self.end_headers() self.send_header("Content-Length", 0) self.server.get_requests += 1 def do_PUT(self): - self.send_response(200) + self.send_response(self.server.status_code) self.send_header("Content-Length", 0) self.end_headers() self.server.put_requests += 1 def do_OPTIONS(self): - self.send_response(200) + self.send_response(self.server.status_code) if self.server.api_v2: self.send_header("X-ReBenchDB-Result-API-Version", "2.0.0") self.send_header("Allow", "PUT") @@ -38,19 +38,18 @@ def __init__(self, *args, **kwargs): self.get_requests = 0 self.options_requests = 0 self.api_v2 = None - - def set_api_v2(self, value): - self.api_v2 = value + self.status_code = 200 class MockHTTPServer(object): - def __init__(self, api_v2 = True): + def __init__(self, api_v2 = True, test_error_handling = False): self._port = -1 self._server = None self._thread = None self._is_shutdown = False self.api_v2 = api_v2 + self._test_error_handling = test_error_handling def get_free_port(self): s = socket.socket(socket.AF_INET, type=socket.SOCK_STREAM) @@ -63,7 +62,9 @@ def get_free_port(self): def start(self): self._server = HTTPServerWithCounter(('localhost', self._port), _RequestHandler) - self._server.set_api_v2(self.api_v2) + self._server.api_v2 = self.api_v2 + if self._test_error_handling: + self._server.status_code = 400 self._thread = Thread(target=self._server.serve_forever) self._thread.daemon = True diff --git a/rebench/tests/persistency_test.py b/rebench/tests/persistency_test.py index 453d64ad..6ad6425b 100644 --- a/rebench/tests/persistency_test.py +++ b/rebench/tests/persistency_test.py @@ -123,7 +123,7 @@ def test_data_discarding(self): @skipIf(git_not_available() or git_repo_not_initialized(), "git source info not available, but needed for reporting to ReBenchDB") - def test_rebench_db(self): + def test_rebenchdb(self): option_parser = ReBench().shell_options() cmd_config = option_parser.parse_args(['--experiment=Test', 'persistency.conf']) @@ -137,6 +137,22 @@ def test_rebench_db(self): finally: server.process_and_shutdown() + @skipIf(git_not_available() or git_repo_not_initialized(), + "git source info not available, but needed for reporting to ReBenchDB") + def test_rebenchdb_400_error(self): + option_parser = ReBench().shell_options() + cmd_config = option_parser.parse_args(['--experiment=Test', 'persistency.conf']) + + server = MockHTTPServer(test_error_handling=True) + + try: + self._exec_rebench_db(cmd_config, server) + server.process_and_shutdown() + + self.assertEqual(1, server.get_number_of_put_requests()) + finally: + server.process_and_shutdown() + def test_disabled_rebench_db(self): option_parser = ReBench().shell_options() cmd_config = option_parser.parse_args(['--experiment=Test', '-R', 'persistency.conf'])