Skip to content

Commit 2ded984

Browse files
committed
Ensure that mode_settings are deleted from the task proxy when
a psuedo-job finishes. Add test for workflow reload.
1 parent 6cd8f1f commit 2ded984

File tree

2 files changed

+105
-5
lines changed

2 files changed

+105
-5
lines changed

cylc/flow/simulation.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def __init__(
9090

9191
self.timeout = started_time + self.simulated_run_length
9292

93+
9394
def configure_sim_modes(taskdefs, sim_mode):
9495
"""Adjust task defs for simulation and dummy mode.
9596
@@ -219,6 +220,7 @@ def sim_time_check(
219220
"""
220221
now = time()
221222
sim_task_state_changed: bool = False
223+
222224
for itask in itasks:
223225
if (
224226
itask.state.status != TASK_STATUS_RUNNING
@@ -228,8 +230,6 @@ def sim_time_check(
228230
):
229231
continue
230232

231-
232-
233233
if itask.mode_settings is None:
234234
itask.mode_settings = ModeSettings(itask, broadcast_mgr, db_mgr)
235235

@@ -251,7 +251,11 @@ def sim_time_check(
251251
message_queue.put(
252252
TaskMsg(job_d, now_str, 'DEBUG', msg)
253253
)
254+
255+
# We've finished this psuedojob, so delete all the mode settings.
256+
itask.mode_settings = None
254257
sim_task_state_changed = True
258+
itask.mode_settings = None
255259
return sim_task_state_changed
256260

257261

tests/integration/test_simulation.py

+99-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
from pathlib import Path
1718
import pytest
1819
from pytest import param
1920
from queue import Queue
@@ -239,7 +240,7 @@ def test_task_sped_up(sim_time_check_setup, monkeytime):
239240

240241

241242
async def test_simulation_mode_settings_restart(
242-
monkeytime, flow, scheduler, run, start
243+
monkeytime, flow, scheduler, start
243244
):
244245
"""Check that simulation mode settings are correctly restored
245246
upon restart.
@@ -258,8 +259,11 @@ async def test_simulation_mode_settings_restart(
258259
'runtime': {
259260
'one': {
260261
'execution time limit': 'PT1M',
262+
'execution retry delays': 'P0Y',
261263
'simulation': {
262-
'speedup factor': 1
264+
'speedup factor': 1,
265+
'fail cycle points': 'all',
266+
'fail try 1 only': True,
263267
}
264268
},
265269
}
@@ -292,8 +296,9 @@ async def test_simulation_mode_settings_restart(
292296
monkeytime(12)
293297
itask.state.status = 'running'
294298

295-
# Check that we haven't got started time back
299+
# Check that we haven't got started time & mode settings back:
296300
assert itask.summary['started_time'] is None
301+
assert itask.mode_settings is None
297302

298303
# Set the start time in the database to 0 to make the
299304
# test simpler:
@@ -308,9 +313,100 @@ async def test_simulation_mode_settings_restart(
308313
schd.workflow_db_mgr
309314
) is False
310315

316+
# Check that the itask.mode_settings is now re-created
317+
assert itask.mode_settings.__dict__ == {
318+
'simulated_run_length': 60.0,
319+
'sim_task_fails': False,
320+
'timeout': 60.0
321+
}
322+
311323
# Set the current time > timeout
312324
monkeytime(61)
313325
assert sim_time_check(
314326
msg_q, [itask], schd.task_events_mgr.broadcast_mgr,
315327
schd.workflow_db_mgr
316328
) is True
329+
330+
assert itask.mode_settings is None
331+
332+
schd.task_events_mgr.broadcast_mgr.put_broadcast(
333+
['1066'], ['one'], [{
334+
'execution time limit': 'PT1S'}])
335+
336+
assert itask.mode_settings is None
337+
338+
schd.task_job_mgr._simulation_submit_task_jobs(
339+
[itask], schd.workflow)
340+
341+
assert itask.submit_num == 2
342+
assert itask.mode_settings.__dict__ == {
343+
'simulated_run_length': 1.0,
344+
'sim_task_fails': False,
345+
'timeout': 62.0
346+
}
347+
348+
349+
async def test_simulation_mode_settings_reload(
350+
monkeytime, flow, scheduler, start
351+
):
352+
"""Check that simulation mode settings are changed for future
353+
pseudo jobs on reload.
354+
355+
"""
356+
def sim_run(schd):
357+
"""Submit and run a psuedo-job.
358+
"""
359+
# Get the only task proxy, submit the psuedo job:
360+
itask = schd.pool.get_tasks()[0]
361+
itask.state.is_queued = False
362+
monkeytime(0)
363+
schd.task_job_mgr._simulation_submit_task_jobs(
364+
[itask], schd.workflow)
365+
monkeytime(61)
366+
367+
# Run Time Check
368+
assert sim_time_check(
369+
schd.message_queue, [itask], schd.task_events_mgr.broadcast_mgr,
370+
schd.workflow_db_mgr
371+
) is True
372+
373+
# Capture result process queue.
374+
out = schd.message_queue.queue[0].message
375+
schd.process_queued_task_messages()
376+
return out
377+
378+
id_ = flow({
379+
'scheduler': {'cycle point format': '%Y'},
380+
'scheduling': {
381+
'initial cycle point': '1066',
382+
'graph': {
383+
'R1': 'one'
384+
}
385+
},
386+
'runtime': {
387+
'one': {
388+
'execution time limit': 'PT1M',
389+
'execution retry delays': 'P0Y',
390+
'simulation': {
391+
'speedup factor': 1,
392+
'fail cycle points': 'all',
393+
'fail try 1 only': False,
394+
}
395+
},
396+
}
397+
})
398+
schd = scheduler(id_)
399+
async with start(schd):
400+
# Submit first psuedo-job and "run" to failure:
401+
assert sim_run(schd) == 'failed'
402+
403+
# Modify config as if reinstall had taken place:
404+
conf_file = Path(schd.workflow_run_dir) / 'flow.cylc'
405+
conf_file.write_text(
406+
conf_file.read_text().replace('False', 'True'))
407+
408+
# Reload Workflow:
409+
await schd.command_reload_workflow()
410+
411+
# Submit second psuedo-job and "run" to success:
412+
assert sim_run(schd) == 'succeeded'

0 commit comments

Comments
 (0)