14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
17
+ from pathlib import Path
17
18
import pytest
18
19
from pytest import param
19
20
from queue import Queue
@@ -239,7 +240,7 @@ def test_task_sped_up(sim_time_check_setup, monkeytime):
239
240
240
241
241
242
async def test_simulation_mode_settings_restart (
242
- monkeytime , flow , scheduler , run , start
243
+ monkeytime , flow , scheduler , start
243
244
):
244
245
"""Check that simulation mode settings are correctly restored
245
246
upon restart.
@@ -258,8 +259,11 @@ async def test_simulation_mode_settings_restart(
258
259
'runtime' : {
259
260
'one' : {
260
261
'execution time limit' : 'PT1M' ,
262
+ 'execution retry delays' : 'P0Y' ,
261
263
'simulation' : {
262
- 'speedup factor' : 1
264
+ 'speedup factor' : 1 ,
265
+ 'fail cycle points' : 'all' ,
266
+ 'fail try 1 only' : True ,
263
267
}
264
268
},
265
269
}
@@ -292,8 +296,9 @@ async def test_simulation_mode_settings_restart(
292
296
monkeytime (12 )
293
297
itask .state .status = 'running'
294
298
295
- # Check that we haven't got started time back
299
+ # Check that we haven't got started time & mode settings back:
296
300
assert itask .summary ['started_time' ] is None
301
+ assert itask .mode_settings is None
297
302
298
303
# Set the start time in the database to 0 to make the
299
304
# test simpler:
@@ -308,9 +313,100 @@ async def test_simulation_mode_settings_restart(
308
313
schd .workflow_db_mgr
309
314
) is False
310
315
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
+
311
323
# Set the current time > timeout
312
324
monkeytime (61 )
313
325
assert sim_time_check (
314
326
msg_q , [itask ], schd .task_events_mgr .broadcast_mgr ,
315
327
schd .workflow_db_mgr
316
328
) 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