From a2f9982b34c4ab023be4fd5b5aac4bfdefdd20e6 Mon Sep 17 00:00:00 2001 From: WXTIM <26465611+wxtim@users.noreply.github.com> Date: Thu, 18 Jan 2024 10:12:04 +0000 Subject: [PATCH] return to get_simulation. Cache call to time() --- cylc/flow/simulation.py | 9 +++++---- tests/unit/test_simulation.py | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cylc/flow/simulation.py b/cylc/flow/simulation.py index 42541c431d1..f34e9d8b260 100644 --- a/cylc/flow/simulation.py +++ b/cylc/flow/simulation.py @@ -61,7 +61,7 @@ def __init__(self, itask: 'TaskProxy', broadcast_mgr: 'BroadcastMgr'): else: rtconfig = itask.tdef.rtconfig self.simulated_run_length = ( - set_simulated_run_len(rtconfig)) + get_simulated_run_len(rtconfig)) self.sim_task_fails = sim_task_failed( rtconfig['simulation'], itask.point, @@ -88,7 +88,7 @@ def configure_sim_modes(taskdefs, sim_mode): rtc['pre-script'] = "" rtc['post-script'] = "" rtc['script'] = build_dummy_script( - rtc, set_simulated_run_len(rtc)) + rtc, get_simulated_run_len(rtc)) disable_platforms(rtc) @@ -102,7 +102,7 @@ def configure_sim_modes(taskdefs, sim_mode): ) -def set_simulated_run_len(rtc: Dict[str, Any]) -> int: +def get_simulated_run_len(rtc: Dict[str, Any]) -> int: """Calculate simulation run time from a task's config. rtc = run time config @@ -196,6 +196,7 @@ def sim_time_check( Returns: True if _any_ simulated task state has changed. """ + now = time() sim_task_state_changed: bool = False for itask in itasks: if ( @@ -223,7 +224,7 @@ def sim_time_check( itask.mode_settings = ModeSettings(itask, broadcast_mgr) timeout = started_time + itask.mode_settings.simulated_run_length - if time() > timeout: + if now > timeout: job_d = itask.tokens.duplicate(job=str(itask.submit_num)) now_str = get_current_time_string() diff --git a/tests/unit/test_simulation.py b/tests/unit/test_simulation.py index 753661a8f0e..920a872503a 100644 --- a/tests/unit/test_simulation.py +++ b/tests/unit/test_simulation.py @@ -24,7 +24,7 @@ parse_fail_cycle_points, build_dummy_script, disable_platforms, - set_simulated_run_len, + get_simulated_run_len, sim_task_failed, ) @@ -38,7 +38,7 @@ param('P1D', 24, 'PT1M', id='speed-up-and-execution-tl'), ) ) -def test_set_simulated_run_len( +def test_get_simulated_run_len( execution_time_limit, speedup_factor, default_run_length ): """Test the logic of the presence or absence of config items. @@ -53,7 +53,7 @@ def test_set_simulated_run_len( 'time limit buffer': 'PT0S', } } - assert set_simulated_run_len(rtc) == 3600 + assert get_simulated_run_len(rtc) == 3600 @pytest.mark.parametrize(