From 8f088af9d6457639ffd667db6509f48db36142fd Mon Sep 17 00:00:00 2001 From: burnout87 Date: Wed, 9 Oct 2024 18:26:55 +0200 Subject: [PATCH] extended test --- cdci_data_analysis/pytest_fixtures.py | 9 +++++++++ tests/test_job_management.py | 16 +++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cdci_data_analysis/pytest_fixtures.py b/cdci_data_analysis/pytest_fixtures.py index 74b91092..0695158f 100644 --- a/cdci_data_analysis/pytest_fixtures.py +++ b/cdci_data_analysis/pytest_fixtures.py @@ -1568,6 +1568,15 @@ def remove_scratch_folders(job_id=None): for d in dir_list: shutil.rmtree(d) + @staticmethod + def remove_lock_files(job_id=None): + if job_id is None: + lock_files = glob.glob('.lock_*') + else: + lock_files = glob.glob(f'.lock_{job_id}') + for f in lock_files: + os.remove(f) + @staticmethod def remove_download_folders(id=None): if id is None: diff --git a/tests/test_job_management.py b/tests/test_job_management.py index d23e391a..2d5441dd 100644 --- a/tests/test_job_management.py +++ b/tests/test_job_management.py @@ -2605,6 +2605,7 @@ def test_email_t1_t2(dispatcher_long_living_fixture, ("hard_minimum_folder_age_days", 60)], indirect=True) def test_free_up_space(dispatcher_live_fixture, number_folders_to_delete, soft_minimum_age_days): DispatcherJobState.remove_scratch_folders() + DispatcherJobState.remove_lock_files() server = dispatcher_live_fixture @@ -2635,11 +2636,11 @@ def test_free_up_space(dispatcher_live_fixture, number_folders_to_delete, soft_m number_analysis_to_run = 8 for i in range(number_analysis_to_run): - ask(server, - params, - expected_query_status=["done"], - max_time_s=150 - ) + jdata = ask(server, + params, + expected_query_status=["done"], + max_time_s=150 + ) list_scratch_dir = sorted(glob.glob("scratch_sid_*_jid_*"), key=os.path.getmtime) @@ -2662,7 +2663,6 @@ def test_free_up_space(dispatcher_live_fixture, number_folders_to_delete, soft_m my_json_str = json.dumps(dict_analysis_parameters, indent=4) dict_analysis_parameters_outfile.write(u'%s' % my_json_str) - params = { 'token': encoded_token, 'soft_minimum_age_days': soft_minimum_age_days @@ -2677,7 +2677,9 @@ def test_free_up_space(dispatcher_live_fixture, number_folders_to_delete, soft_m assert 'output_status' in jdata - assert jdata['output_status'] == f"Removed {number_folders_to_delete} scratch directories" + number_lock_files_deleted = 0 if number_folders_to_delete < number_analysis_to_run else 1 + assert jdata['output_status'] == (f"Removed {number_folders_to_delete} scratch directories, " + f"and {number_lock_files_deleted} lock files.") assert len(glob.glob("scratch_sid_*_jid_*")) == number_analysis_to_run - number_folders_to_delete