Skip to content

Commit

Permalink
Update Github Actions and Avoid GIL Issues and Races with MockHTTPSer…
Browse files Browse the repository at this point in the history
…ver (#235)
  • Loading branch information
smarr committed Feb 18, 2024
2 parents fd8fa6b + 698cdcd commit 21bd647
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -10,17 +10,17 @@ jobs:
matrix:
# Don't test pypy3.10, it currently is broken on GitHub Actions.
# re-enable once PyYAML can be installed again. See #225
python-version: [ '3.7', '3.11' ] # 'pypy3.10'
python-version: ["3.7", "3.12", "pypy3.10"]
include:
- python-version: 3.7
coverage: "--cov=rebench"
name: "Ubuntu-latest: Python ${{ matrix.python-version }}"
steps:
- name: Checkout ReBench
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: x64
Expand Down
10 changes: 9 additions & 1 deletion rebench/tests/mock_http_server.py
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
@@ -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
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 21bd647

Please sign in to comment.