From 52fd7a89473c4b7e18862a5c1f9a2b6715cc41c4 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 8 Jul 2023 00:54:26 +0200 Subject: test: verify that added runs are in the database And that they're marked as finished. It immediately exposed some concurrency bugs, so some locking has been fixed. --- test/py/test_repo.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'test/py/test_repo.py') diff --git a/test/py/test_repo.py b/test/py/test_repo.py index 782240b..1cc1434 100644 --- a/test/py/test_repo.py +++ b/test/py/test_repo.py @@ -4,6 +4,7 @@ # Distributed under the MIT License. from multiprocessing import Process +import re import pytest @@ -14,10 +15,11 @@ class LoggingEventRunComplete(LoggingEvent): def __init__(self, target): self.counter = 0 self.target = target + self.re = re.compile(r'run \d+ as finished') super().__init__(timeout=60) def log_line_matches(self, line): - return 'Received a "run finished" message from worker' in line + return bool(self.re.search(line)) def set(self): self.counter += 1 @@ -25,7 +27,7 @@ class LoggingEventRunComplete(LoggingEvent): super().set() -def _test_repo_internal(server_and_workers, test_repo, client, numof_processes, runs_per_process): +def _test_repo_internal(server_and_workers, test_repo, client, numof_processes, runs_per_process, db): numof_runs = numof_processes * runs_per_process server, workers = server_and_workers @@ -47,24 +49,30 @@ def _test_repo_internal(server_and_workers, test_repo, client, numof_processes, event.wait() assert numof_runs == test_repo.count_ci_output_files() + runs = db.get_all_runs() + assert numof_runs == len(runs) -def test_repo_1_client_1_run(server_and_workers, test_repo, client): - _test_repo_internal(server_and_workers, test_repo, client, 1, 1) + for id, status, ec, output, url, rev in runs: + assert status == 'finished', f'Invalid status for run {id}: {status}' -def test_repo_1_client_2_runs(server_and_workers, test_repo, client): - _test_repo_internal(server_and_workers, test_repo, client, 1, 2) +def test_repo_1_client_1_run(server_and_workers, test_repo, client, sqlite_db): + _test_repo_internal(server_and_workers, test_repo, client, 1, 1, sqlite_db) -def test_repo_1_client_10_runs(server_and_workers, test_repo, client): - _test_repo_internal(server_and_workers, test_repo, client, 1, 10) +def test_repo_1_client_2_runs(server_and_workers, test_repo, client, sqlite_db): + _test_repo_internal(server_and_workers, test_repo, client, 1, 2, sqlite_db) + + +def test_repo_1_client_10_runs(server_and_workers, test_repo, client, sqlite_db): + _test_repo_internal(server_and_workers, test_repo, client, 1, 10, sqlite_db) @pytest.mark.stress -def test_repo_1_client_2000_runs(server_and_workers, test_repo, client): - _test_repo_internal(server_and_workers, test_repo, client, 1, 2000) +def test_repo_1_client_2000_runs(server_and_workers, test_repo, client, sqlite_db): + _test_repo_internal(server_and_workers, test_repo, client, 1, 2000, sqlite_db) @pytest.mark.stress -def test_repo_4_clients_500_runs(server_and_workers, test_repo, client): - _test_repo_internal(server_and_workers, test_repo, client, 4, 500) +def test_repo_4_clients_500_runs(server_and_workers, test_repo, client, sqlite_db): + _test_repo_internal(server_and_workers, test_repo, client, 4, 500, sqlite_db) -- cgit v1.2.3