Skip to content

Commit

Permalink
ensure that sim mode won't fail if an invalid date is broadcast to it
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Apr 22, 2024
1 parent ef656f3 commit d378e3a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
37 changes: 17 additions & 20 deletions cylc/flow/run_modes/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def submit_task_job(
Returns:
True - indicating that TaskJobManager need take no further action.
"""
configure_sim_mode(rtconfig)
configure_sim_mode(
rtconfig,
itask.tdef.rtconfig['simulation']['fail cycle points'])
itask.summary['started_time'] = now[0]
task_job_mgr._set_retry_timers(itask, rtconfig)
itask.mode_settings = ModeSettings(
Expand Down Expand Up @@ -156,21 +158,12 @@ def __init__(
if not rtconfig:
rtconfig = itask.tdef.rtconfig
if rtconfig and rtconfig != itask.tdef.rtconfig:
try:
rtconfig["simulation"][
"fail cycle points"
] = parse_fail_cycle_points(
rtconfig["simulation"]["fail cycle points"]
)
except PointParsingError as exc:
# Broadcast Fail CP didn't parse
LOG.warning(
'Broadcast fail cycle point was invalid:\n'
f' {exc.args[0]}'
)
rtconfig['simulation'][
'fail cycle points'
] = itask.tdef.rtconfig['simulation']['fail cycle points']
rtconfig["simulation"][
"fail cycle points"
] = parse_fail_cycle_points(
rtconfig["simulation"]["fail cycle points"],
itask.tdef.rtconfig['simulation']['fail cycle points']
)

# Calculate simulation info:
self.simulated_run_length = (
Expand All @@ -183,7 +176,7 @@ def __init__(
self.timeout = started_time + self.simulated_run_length


def configure_sim_mode(rtc):
def configure_sim_mode(rtc, fallback):
"""Adjust task defs for simulation and dummy mode.
"""
Expand All @@ -197,7 +190,8 @@ def configure_sim_mode(rtc):
rtc["simulation"][
"fail cycle points"
] = parse_fail_cycle_points(
rtc["simulation"]["fail cycle points"]
rtc["simulation"]["fail cycle points"],
fallback
)


Expand Down Expand Up @@ -240,7 +234,7 @@ def disable_platforms(


def parse_fail_cycle_points(
f_pts_orig: List[str]
f_pts_orig: List[str], fallback
) -> 'Union[None, List[PointBase]]':
"""Parse `[simulation][fail cycle points]`.
Expand Down Expand Up @@ -275,6 +269,7 @@ def parse_fail_cycle_points(
LOG.warning(
f'Invalid ISO 8601 date representation: {point_str}'
)
return fallback
return f_pts


Expand Down Expand Up @@ -303,7 +298,9 @@ def sim_time_check(
if itask.mode_settings is None:
rtconfig = task_events_manager.broadcast_mgr.get_updated_rtconfig(
itask)
rtconfig = configure_sim_mode(rtconfig)
rtconfig = configure_sim_mode(
rtconfig,
itask.tdef.rtconfig['simulation']['fail cycle points'])
itask.mode_settings = ModeSettings(
itask,
db_mgr,
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/run_modes/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ async def test_settings_broadcast(
'Invalid ISO 8601 date representation: higadfuhasgiurguj'
in log.messages[-1])

# Check that the invalid broadcast hasn't
# changed the itask sim mode settings:
assert itask.mode_settings.sim_task_fails is True

schd.broadcast_mgr.put_broadcast(
['1066'], ['one'], [{
'simulation': {'fail cycle points': '1'}
Expand Down

0 comments on commit d378e3a

Please sign in to comment.