diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-08 01:40:10 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-08 01:40:10 +0200 |
commit | 7bf0ec6bc417da77a8d45ab91b5522c96a25e273 (patch) | |
tree | 0a4a230d3509e01183f7ca67aac07ed0567b0994 /test | |
parent | test: verify that added runs are in the database (diff) | |
download | cimple-7bf0ec6bc417da77a8d45ab91b5522c96a25e273.tar.gz cimple-7bf0ec6bc417da77a8d45ab91b5522c96a25e273.zip |
test: refactoring
Diffstat (limited to '')
-rw-r--r-- | test/py/conftest.py | 22 | ||||
-rw-r--r-- | test/py/test_basic.py | 2 | ||||
-rw-r--r-- | test/py/test_repo.py | 32 |
3 files changed, 31 insertions, 25 deletions
diff --git a/test/py/conftest.py b/test/py/conftest.py index ead09d1..a92699d 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -119,6 +119,11 @@ def sqlite_path(tmp_path): return os.path.join(tmp_path, 'cimple.sqlite') +@fixture +def sqlite_db(server, sqlite_path): + return Database(sqlite_path) + + class CmdLineServer(CmdLine): def log_line_means_process_ready(self, line): return line.endswith('Waiting for new connections') @@ -179,11 +184,6 @@ def workers(worker_cmd): @fixture -def server_and_workers(server, workers): - yield server, workers - - -@fixture def client(client_cmd): return client_cmd @@ -193,6 +193,14 @@ def test_repo(tmp_path): return TestRepo(tmp_path) +class Env: + def __init__(self, server, workers, client, db): + self.server = server + self.workers = workers + self.client = client + self.db = db + + @fixture -def sqlite_db(server, sqlite_path): - return Database(sqlite_path) +def env(server, workers, client, sqlite_db): + return Env(server, workers, client, sqlite_db) diff --git a/test/py/test_basic.py b/test/py/test_basic.py index 9737552..7ac038c 100644 --- a/test/py/test_basic.py +++ b/test/py/test_basic.py @@ -65,5 +65,5 @@ def test_run_noop_server(server): pass -def test_run_noop_server_and_workers(server_and_workers): +def test_run_noop_server_and_workers(server, workers): pass diff --git a/test/py/test_repo.py b/test/py/test_repo.py index 1cc1434..c6cd6a2 100644 --- a/test/py/test_repo.py +++ b/test/py/test_repo.py @@ -27,18 +27,16 @@ class LoggingEventRunComplete(LoggingEvent): super().set() -def _test_repo_internal(server_and_workers, test_repo, client, numof_processes, runs_per_process, db): +def _test_repo_internal(env, repo, numof_processes, runs_per_process): numof_runs = numof_processes * runs_per_process - server, workers = server_and_workers - event = LoggingEventRunComplete(numof_runs) # Count the number of times the server receives the "run complete" message. - server.logger.add_event(event) + env.server.logger.add_event(event) def client_runner(): for i in range(runs_per_process): - client.run('run', test_repo.path, 'HEAD') + env.client.run('run', repo.path, 'HEAD') processes = [Process(target=client_runner) for i in range(numof_processes)] for proc in processes: @@ -47,32 +45,32 @@ def _test_repo_internal(server_and_workers, test_repo, client, numof_processes, proc.join() event.wait() - assert numof_runs == test_repo.count_ci_output_files() + assert numof_runs == repo.count_ci_output_files() - runs = db.get_all_runs() + runs = env.db.get_all_runs() assert numof_runs == len(runs) for id, status, ec, output, url, rev in runs: assert status == 'finished', f'Invalid status for run {id}: {status}' -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_1_run(env, test_repo): + _test_repo_internal(env, test_repo, 1, 1) -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_2_runs(env, test_repo): + _test_repo_internal(env, test_repo, 1, 2) -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) +def test_repo_1_client_10_runs(env, test_repo): + _test_repo_internal(env, test_repo, 1, 10) @pytest.mark.stress -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) +def test_repo_1_client_2000_runs(env, test_repo): + _test_repo_internal(env, test_repo, 1, 2000) @pytest.mark.stress -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) +def test_repo_4_clients_500_runs(env, test_repo): + _test_repo_internal(env, test_repo, 4, 500) |