Skip to content

Commit

Permalink
Make sure the server had a chance to process requests
Browse files Browse the repository at this point in the history
- yield the GIL, and sleep a bit
- then shutdown proactively and this way synchronize execution
- keep fallback in case of error

Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Feb 18, 2024
1 parent 6aad883 commit 698cdcd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
10 changes: 9 additions & 1 deletion rebench/tests/mock_http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from http.server import BaseHTTPRequestHandler, HTTPServer
from threading import Thread
from time import sleep


class _RequestHandler(BaseHTTPRequestHandler):
Expand Down Expand Up @@ -32,6 +33,7 @@ def __init__(self):
self._port = -1
self._server = None
self._thread = None
self._is_shutdown = False

def get_free_port(self):
s = socket.socket(socket.AF_INET, type=socket.SOCK_STREAM)
Expand All @@ -49,7 +51,13 @@ def start(self):
self._thread.daemon = True
self._thread.start()

def shutdown(self):
def process_and_shutdown(self):
if self._is_shutdown:
return

sleep(1) # yield GIL and give server time to process request

self._is_shutdown = True
self._server.shutdown()

def get_number_of_put_requests(self):
Expand Down
5 changes: 4 additions & 1 deletion rebench/tests/perf/issue_166_profiling_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest import skipIf

from ..mock_http_server import MockHTTPServer
from ...configurator import Configurator, load_config
from ...environment import git_not_available, git_repo_not_initialized
Expand Down Expand Up @@ -184,9 +185,11 @@ def test_send_to_rebench_db(self):
self.assertEqual(1, run_id.completed_invocations)
self.assertEqual(1, run_id.get_number_of_data_points())

server.process_and_shutdown()

self.assertEqual(1, server.get_number_of_put_requests())
finally:
server.shutdown()
server.process_and_shutdown()

@staticmethod
def _make_profiler_return_small_report(run_id):
Expand Down
8 changes: 6 additions & 2 deletions rebench/tests/persistency_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ def test_rebench_db(self):

try:
self._exec_rebench_db(cmd_config, server)
server.process_and_shutdown()

self.assertEqual(1, server.get_number_of_put_requests())
finally:
server.shutdown()
server.process_and_shutdown()

def test_disabled_rebench_db(self):
option_parser = ReBench().shell_options()
Expand All @@ -141,9 +143,11 @@ def test_disabled_rebench_db(self):

try:
self._exec_rebench_db(cmd_config, server)
server.process_and_shutdown()

self.assertEqual(0, server.get_number_of_put_requests())
finally:
server.shutdown()
server.process_and_shutdown()

def _exec_rebench_db(self, cmd_config, server):
port = server.get_free_port()
Expand Down

0 comments on commit 698cdcd

Please sign in to comment.