Debian Codegraph @

tests/i/test_force_trigger.py

raw
1 # THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
2 # Copyright (C) NIWA & British Crown (Met Office) & Contributors.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 import asyncio
18 import logging
19 from typing import (
20 Any as Fixture,
21 Callable,
22 )
23
24 import pytest
25
26 from cylc.flow.commands import (
27 force_trigger_tasks,
28 hold,
29 reload_workflow,
30 remove_tasks,
31 resume,
32 run_cmd,
33 set_prereqs_and_outputs,
34 )
35 from cylc.flow.cycling.integer import IntegerPoint
36 from cylc.flow.flow_mgr import FLOW_NEW
37 from cylc.flow.scheduler import Scheduler
38 from cylc.flow.task_state import (
39 TASK_STATUS_FAILED,
40 TASK_STATUS_RUNNING,
41 TASK_STATUS_SUBMITTED,
42 TASK_STATUS_SUCCEEDED,
43 TASK_STATUS_WAITING,
44 )
45 from cylc.flow.workflow_status import AutoRestartMode
46
47
48 async def test_workflow_paused_simple(
49 one_conf, flow, scheduler, run, complete
50 ):
51 """It should run triggered tasks even if the workflow is paused."""
52 schd: Scheduler = scheduler(flow(one_conf), paused_start=True)
53 async with run(schd):
54 await run_cmd(force_trigger_tasks(schd, ['1/one'], ['1']))
55 await complete(schd, '1/one', allow_paused=True, timeout=1)
56
57
58 async def test_workflow_paused_queues(
59 flow: 'Fixture',
60 scheduler: 'Fixture',
61 start: 'Fixture',
62 capture_submission: 'Fixture',
63 log_filter: Callable
64 ):
65 """
66 Test manual triggering when the workflow is paused.
67
68 The usual queue limiting behaviour is expected.
69
70 https://github.com/cylc/cylc-flow/issues/6192
71
72 """
73 id_ = flow({
74 'scheduling': {
75 'queues': {
76 'default': {
77 'limit': 1,
78 },
79 },
80 'graph': {
81 'R1': '''
82 a => x & y & z
83 ''',
84 },
85 },
86 })
87 schd = scheduler(id_, paused_start=True)
88
89 # start the scheduler (but don't set the main loop running)
90 async with start(schd):
91
92 # capture task submissions (prevents real submissions)
93 submitted_tasks = capture_submission(schd)
94
95 # paused at start-up so no tasks should be submitted
96 assert len(submitted_tasks) == 0
97
98 # manually trigger 1/x - it should be submitted
99 await run_cmd(force_trigger_tasks(schd, ['1/x'], ["1"]))
100 schd.release_tasks_to_run()
101 assert len(submitted_tasks) == 1
102
103 # manually trigger 1/y - it should be queued but not submitted
104 # (queue limit reached)
105 await run_cmd(force_trigger_tasks(schd, ['1/y'], ["1"]))
106 schd.release_tasks_to_run()
107 assert len(submitted_tasks) == 1
108
109 # manually trigger 1/y again - it should be submitted
110 # (triggering a queued task runs it)
111 await run_cmd(force_trigger_tasks(schd, ['1/y'], ["1"]))
112 schd.release_tasks_to_run()
113 assert len(submitted_tasks) == 2
114
115 # manually trigger 1/y yet again - the trigger should be ignored
116 # (task already active)
117 await run_cmd(force_trigger_tasks(schd, ['1/y'], ["1"]))
118 schd.release_tasks_to_run()
119 assert len(submitted_tasks) == 2
120 assert log_filter(
121 level=logging.WARNING,
122 contains="Job already in process - ignoring"
123 )
124
125
126 async def test_trigger_group_whilst_paused(flow, scheduler, run, complete):
127 """Only group start tasks should run if the group is triggered whilst
128 the scheduler is paused.
129
130 Group start tasks have only off-group dependencies.
131
132 Others (with in-group dependencies) should run as normal when their
133 prerequisites are satisfied once the workflow is resumed.
134
135 """
136 id_ = flow('a => b => c => d')
137 schd = scheduler(id_, paused_start=True)
138 async with run(schd):
139 # trigger the chain
140 await run_cmd(force_trigger_tasks(schd, ['1/a'], []))
141
142 # 1/a should run whilst the workflow is paused (group start-task)
143 await complete(schd, '1/a', allow_paused=True, timeout=1)
144
145 # 1/b should *not* run whilst the workflow is paused
146 with pytest.raises(AssertionError):
147 await complete(schd, '1/b', allow_paused=True, timeout=2)
148
149 b = schd.pool._get_task_by_id('1/b')
150 assert b.state.status == TASK_STATUS_WAITING
151
152 # 1/b and 1/c should run once the workflow is resumed
153 await run_cmd(resume(schd))
154 await complete(schd, '1/c')
155
156
157 async def test_trigger_group(
158 flow, scheduler, run, complete, log_filter
159 ):
160 """Test trigger of a sub-graph of future, then past, tasks.
161
162 It should satisfy off-group task and xtrigger prerequisites automatically.
163
164 """
165 cfg = {
166 'scheduling': {
167 'xtriggers': {
168 'xr': 'xrandom(0)' # never satisfied
169 },
170 'special tasks': {
171 'external-trigger': 'xt(cheese)'
172 },
173 'graph': {
174 'R1': """
175 # upstream:
176 x => a
177
178 # sub-graph for group trigger:
179 a => b & c & xt => d
180
181 # downstream:
182 d => e => y
183
184 # off-group prerequisites:
185 @xr => x # stop the flow starting
186 @xr => c # off-group xtrigger prerequisite
187 @xr => off => b # off-group task prerequisite
188 # (plus task xt has a push external trigger)
189
190 # stop the flow from ending without intervention:
191 @xr => y
192 """
193 },
194 },
195 }
196 id_ = flow(cfg)
197 schd = scheduler(id_, paused_start=False)
198 async with run(schd, level=logging.INFO) as log:
199 # Trigger the group ahead of the flow.
200 # It should run the group and flow on to downstream task e.
201 await run_cmd(
202 force_trigger_tasks(schd, ['1/a', '1/b', '1/c', '1/d', '1/xt'], [])
203 )
204 await complete(schd, '1/e')
205
206 # It should satisfy off-group prerequisites.
207 assert log_filter(
208 regex="1/c:waiting.*prerequisite force-satisfied: xr = xrandom")
209 assert log_filter(
210 regex="1/b:waiting.*prerequisite force-satisfied: 1/off:succeeded")
211 assert log_filter(
212 regex="1/a:waiting.*prerequisite force-satisfied: 1/x:succeeded")
213 assert log_filter(
214 regex='1/xt:waiting.*external trigger force-satisfied: "cheese"')
215
216 log.clear()
217
218 # Trigger the group again, now as past tasks, in the same flow.
219 # It should erase flow 1 history to allow the rerun.
220 # It should not flow on to e, which already ran in flow 1.
221
222 # Create an active task that needs removing, to test that.
223 await run_cmd(
224 set_prereqs_and_outputs(schd, ['1/c'], [], [], ['all'])
225 )
226 await run_cmd(
227 force_trigger_tasks(schd, ['1/a', '1/b', '1/c', '1/d', '1/xt'], [])
228 )
229 await complete(schd, '1/d')
230
231 assert log_filter(
232 contains=(
233 "Removed tasks: 1/a (flows=1), 1/b (flows=1),"
234 " 1/c (flows=1), 1/d (flows=1), 1/xt (flows=1)"
235 )
236 )
237 assert log_filter(
238 regex="1/c:waiting.*prerequisite force-satisfied: xr = xrandom")
239 assert log_filter(
240 regex="1/b:waiting.*prerequisite force-satisfied: 1/off:succeeded")
241 assert log_filter(
242 regex="1/a:waiting.*prerequisite force-satisfied: 1/x:succeeded")
243 assert log_filter(
244 regex='1/xt:waiting.*external trigger force-satisfied: "cheese"')
245
246 log.clear()
247
248 # Trigger the group again, as past tasks, in a new flow.
249 # It should flow on to task e again, in flow 2.
250 await run_cmd(
251 force_trigger_tasks(
252 schd, ['1/a', '1/b', '1/c', '1/d', '1/xt'], ['new'])
253 )
254 await complete(schd, '1/e')
255
256 assert log_filter(
257 regex=(
258 r"1/c\(flows=2\):waiting.*prerequisite"
259 r" force-satisfied: xr = xrandom"
260 )
261 )
262 assert log_filter(
263 regex=(
264 r"1/b\(flows=2\):waiting.*prerequisite"
265 r" force-satisfied: 1/off:succeeded"
266 )
267 )
268 assert log_filter(
269 regex=(
270 r"1/a\(flows=2\):waiting.*prerequisite"
271 r" force-satisfied: 1/x:succeeded"
272 )
273 )
274 assert log_filter(
275 regex=(
276 r"1/xt\(flows=2\):waiting.*external trigger"
277 r' force-satisfied: "cheese"'
278 )
279 )
280
281 # Task d (in the group) should have run 3 times.
282 assert log_filter(
283 contains="[1/d/03(flows=2):running] => succeeded"
284 )
285 # Task e (downstream of the group) only twice (once in each flow).
286 assert log_filter(
287 contains="[1/e/02(flows=2):running] => succeeded"
288 )
289
290
291 async def test_trigger_active_task_in_group(
292 flow,
293 scheduler,
294 run,
295 complete,
296 log_filter,
297 reflog,
298 ):
299 """It should remove (and kill) active tasks that are not group start tasks.
300
301 The workflow `a => b => c` starts out like this:
302
303 * a (succeeded, n=1)
304 * b (running, n=0)
305 * c (waiting, n=1)
306
307 Then we reload to add the dependency `d => b` and trigger a, b & c.
308
309 * a - should be removed and re-spawned.
310 * b - should be removed and re-spawned with `a => b` unsatisfied but
311 `d => b` force-satisfied.
312 * c - should be left alone.
313
314 See point (4):
315 https://github.com/cylc/cylc-admin/blob/master/docs/proposal-group-trigger.md#details
316 """
317 conf = {
318 'scheduling': {
319 'graph': {'R1': 'a => b => c'},
320 },
321 }
322 id_ = flow(conf)
323 schd = scheduler(id_, paused_start=False)
324
325 async with run(schd):
326 # capture triggering information
327 triggers = reflog(schd)
328
329 # run until 1/a:succeeded
330 await complete(schd, '1/a')
331
332 # check 1/b prereqs
333 b_1 = schd.pool.get_task(IntegerPoint('1'), 'b')
334 assert [
335 (prereq.task, is_satisfied)
336 for condition in b_1.state.prerequisites
337 for prereq, is_satisfied in condition.items()
338 ] == [
339 # 1/b has a single prereq, it has been satisfied normally
340 ('a', 'satisfied naturally'),
341 ]
342
343 # submit 1/b
344 schd.submit_task_jobs([b_1])
345
346 # reload the workflow adding the dependency "d => b"
347 conf['scheduling']['graph']['R1'] += '\nd => b'
348 flow(conf, workflow_id=id_)
349 await run_cmd(reload_workflow(schd))
350
351 # trigger the chain a => b => c
352 await run_cmd(force_trigger_tasks(schd, ['1/a', '1/b', '1/c'], []))
353
354 # active task 1/b should be killed
355 assert log_filter(
356 contains=(
357 '[1/b/01:running] removed from the n=0 window: request'
358 ' - active job orphaned'
359 )
360 )
361
362 # check 1/b prereqs
363 b_1 = schd.pool.get_task(IntegerPoint('1'), 'b') # ret reloaded task
364 assert [
365 (prereq.task, is_satisfied)
366 for condition in b_1.state.prerequisites
367 for prereq, is_satisfied in condition.items()
368 ] == [
369 # in-group prereq has been reset
370 ('a', False),
371 # off-group prereq has been "force satisfied"
372 ('d', 'force satisfied'),
373 ]
374
375 # the workflow should run the chain a => b => c as instructed
376 await complete(schd, '1/c')
377 assert triggers == {
378 ('1/a', None),
379 ('1/b', ('1/a',)), # original run
380 ('1/b', ('1/a', '1/d')), # force-triggered run
381 ('1/c', ('1/b',)),
382 }
383
384
385 async def test_trigger_group_in_flow(
386 flow,
387 scheduler,
388 run,
389 complete,
390 reflog,
391 db_select,
392 ):
393 """It should remove tasks from the triggered flow(s).
394
395 Tests the following statement from the proposal:
396
397 > Use the same flow numbers, as determined by the trigger command in the
398 > usual way, throughout the operation
399 >
400 > -- https://cylc.github.io/cylc-admin/proposal-group-trigger.html#details
401 """
402 id_ = flow({
403 'scheduling': {
404 'graph': {
405 'R1': 'a => b => c => d'
406 }
407 }
408 })
409 schd = scheduler(id_, paused_start=False)
410 async with run(schd):
411 # prevent shutdown after 1/c completes
412 await run_cmd(hold(schd, ['1/d']))
413
414 # run the chain, merge in flow "2" part way through
415 triggers = reflog(schd, flow_nums=True)
416 await complete(schd, '1/a')
417 await run_cmd(force_trigger_tasks(schd, ['1/b'], ['2']))
418 await complete(schd, '1/c')
419 assert triggers == {
420 # (task, flow_nums, triggered_off_of)
421 ('1/a', '[1]', None),
422 ('1/b', '[1, 2]', ('1/a',)), # flow "2" merged in
423 ('1/c', '[1, 2]', ('1/b',)), # flow "2" merged in
424 }
425
426 # re-run the chain in flow "2"
427 triggers = reflog(schd, flow_nums=True)
428 await run_cmd(force_trigger_tasks(schd, ['1/a', '1/b', '1/c'], ['2']))
429 await complete(schd, '1/c', timeout=10)
430 assert triggers == {
431 # (task, flow_nums, triggered_off_of)
432 ('1/a', '[2]', None),
433 ('1/b', '[2]', ('1/a',)),
434 ('1/c', '[2]', ('1/b',)),
435 }
436
437 # ensure that flow "2" was removed from the tasks in the original run
438 # by the group-trigger
439 assert set(db_select(
440 schd,
441 True,
442 'task_outputs',
443 'name',
444 'flow_nums',
445 )) == {
446 # original run
447 ('a', '[1]'),
448 ('b', '[1]'), # flow "2" has been removed
449 ('c', '[1]'), # flow "2" has been removed
450 ('d', '[1, 2]'),
451
452 # subsequent run
453 ('a', '[2]'),
454 ('b', '[2]'),
455 ('c', '[2]'),
456 }
457
458
459 async def test_trigger_n0_tasks(
460 flow,
461 scheduler,
462 run,
463 complete,
464 db_select,
465 ):
466 """It should trigger tasks within their flow if available, else all flows.
467
468 * N=0 tasks already have a flow assigned.
469 * N!=0 tasks do not yet have a flow assigned.
470
471 When we are triggering n!=0 tasks, there is no appropriate flow to run them
472 in (this would involve flow merge prediction), so we default to all active
473 flows as the most/only sensible default.
474
475 Before group trigger, we triggered tasks independently, i.e. we assumed
476 there were no dependencies between the tasks and ran them all
477 simultaneously. With the group trigger extension, we enhanced trigger to
478 make it aware of interdependent tasks.
479
480 Triggering independent tasks (pre group-trigger behaviour):
481 * If we trigger a n=0 task, we leave it in the flow it is already in.
482 * If we trigger a n!=0 task, we default to all active flows.
483
484 Triggering interdependent tasks (group trigger extension):
485 If the list of tasks being triggered contains any interdependent tasks,
486 we treat these interdependent tasks as a group.
487
488 * If we trigger a group which contains n=0 tasks, the whole group should
489 be triggered using the set of flows possessed by these n=0 tasks.
490 * If we trigger a group which does not contain n=0 tasks, we default to
491 all active flows.
492 """
493 id_ = flow({
494 'scheduling': {
495 'graph': {
496 'R1': '''
497 # group 1 (we will trigger a, b & c)
498 a => b => c => z
499
500 # group 2 (we will trigger e, f & g)
501 e => f => g => z
502
503 # group 3 (we will trigger y)
504 x => y => z
505 '''
506 }
507 }
508 })
509 schd = scheduler(id_, paused_start=False)
510 async with run(schd):
511 # cylc hold 1/x
512 await run_cmd(hold(schd, ['1/x']))
513
514 # group 1: spawn n>0 tasks into flows 2 & 3
515 await run_cmd(
516 set_prereqs_and_outputs(schd, ['1/b'], ['2'], None, ['all'])
517 )
518 await run_cmd(
519 set_prereqs_and_outputs(schd, ['1/c'], ['3'], None, ['all'])
520 )
521
522 # group 2: spawn n>0 tasks into flows 4 & 5
523 await run_cmd(
524 set_prereqs_and_outputs(schd, ['1/f'], ['4'], None, ['all'])
525 )
526 await run_cmd(
527 set_prereqs_and_outputs(schd, ['1/g'], ['5'], None, ['all'])
528 )
529
530 # trigger all three groups of tasks
531 await run_cmd(
532 force_trigger_tasks(
533 schd, ['1/a', '1/b', '1/c', '1/e', '1/f', '1/g', '1/y'], []
534 )
535 )
536
537 await complete(
538 schd, '1/a', '1/b', '1/c', '1/e', '1/f', '1/g', '1/y', '1/z'
539 )
540
541 assert set(db_select(
542 schd,
543 True,
544 'task_outputs',
545 'name',
546 'flow_nums',
547 )) == {
548 # junk entries inserted on spawn/set
549 ('a', '[1]'), # initial flow spawned on startup
550 ('b', '[]'), # created by "cylc set"
551 ('c', '[]'), # created by "cylc set"
552 ('e', '[1]'), # initial flow spawned on startup
553 ('f', '[]'), # created by "cylc set"
554 ('g', '[]'), # created by "cylc set"
555 ('x', '[1]'), # initial flow spawned on startup
556
557 # group 1: contained tasks in flows 1, 2 & 3
558 ('a', '[1, 2, 3]'),
559 ('b', '[1, 2, 3]'),
560 ('c', '[1, 2, 3]'),
561
562 # group 2: contained tasks in flows 1, 4 & 5
563 ('e', '[1, 4, 5]'),
564 ('f', '[1, 4, 5]'),
565 ('g', '[1, 4, 5]'),
566
567 # group 3: contained tasks in flows None
568 ('y', '[1, 2, 3, 4, 5]'),
569
570 # downstream task
571 ('z', '[1, 2, 3, 4, 5]'),
572 }
573
574
575 async def test_replay_outputs(flow, scheduler, start, complete, log_filter):
576 """Triggered group start tasks re-emit (kind of) earlier outputs.
577
578 https://github.com/cylc/cylc-flow/issues/6858
579
580 Example graph:
581 a:started => b => end
582 k:kustom => l => end
583 k:kustom => offg
584
585 If I trigger a, b, k, l AFTER a:started and k:kustom have completed:
586 cylc trigger workflow //1/a //1/b //1/k //1/l
587
588 Then I should expect outputs `k:kustom` and `a:started` to be re-used
589 to satify b and l in the triggered flow, but NOT off-group task offg.
590 """
591 msg_prereq = '[1/{}:waiting(runahead)] prerequisite force-satisfied: 1/{}'
592 msg_spawned = "[1/{}:waiting(runahead)] => waiting"
593 msg_removed = "Removed tasks: 1/{}"
594
595 wid = flow({
596 'scheduling': {
597 'graph': {
598 'R1': """
599 a:started => b => end
600 k:kustom => l => end
601 k:kustom => offg
602 """
603 }
604 },
605 'runtime': {
606 'a': {},
607 'k': {
608 'outputs': {'kustom': 'custom message'}
609 }
610 }
611 })
612 schd = scheduler(wid, paused_start=True)
613 async with start(schd):
614 # Set initial tasks a and k to "running" so they are recognized as
615 # live during the forthcoming trigger operation.
616
617 # Complete the a:started and k:kustom outputs.
618 await run_cmd(
619 set_prereqs_and_outputs(schd, ['1/a'], ['1'], ['started'], None)
620 )
621 await run_cmd(
622 set_prereqs_and_outputs(schd, ['1/k'], ['1'], ['kustom'], None)
623 )
624 await schd._main_loop()
625 # It should spawn b, l, and offg.
626 for task in ['b', 'l', 'offg']:
627 assert log_filter(contains=msg_spawned.format(task))
628
629 # Set a and k as running so they're recognized as live start tasks
630 # by the trigger operation.
631 for itask in schd.pool.get_tasks():
632 itask.state_reset(TASK_STATUS_RUNNING)
633
634 # Now trigger the group.
635 await run_cmd(
636 force_trigger_tasks(schd, ['1/a', '1/b', '1/k', '1/l'], [])
637 )
638 # It should remove b and l (in-group tasks)
639 for task in ['b', 'l']:
640 assert log_filter(contains=msg_removed.format(task))
641
642 # But they will be respawned immediately by re-satisfying dependence
643 # on the earlier outputs of a and k for in-group tasks:
644 assert log_filter(contains=msg_prereq.format('b', 'a:started'))
645 assert log_filter(contains=msg_prereq.format('l', 'k:custom message'))
646 # But not for the off-group task offg:
647 assert not log_filter(
648 contains=msg_prereq.format('offg', 'k:custom message'))
649
650
651 async def test_trigger_with_sequential_task(flow, scheduler, run, log_filter):
652 """It should trigger a failed sequential task.
653
654 See https://github.com/cylc/cylc-flow/issues/6911
655 """
656 id_ = flow({
657 'scheduling': {
658 'initial cycle point': '1',
659 'final cycle point': '2',
660 'cycling mode': 'integer',
661 'special tasks': {
662 'sequential': 'foo',
663 },
664 'graph': {
665 'R1': 'install => foo',
666 'P1': 'foo',
667 },
668 },
669 'runtime': {
670 'foo': {
671 'simulation': {
672 'fail cycle points': '2',
673 },
674 },
675 },
676 })
677 schd = scheduler(id_, paused_start=False)
678 async with run(schd):
679 # wait for 2/foo:failed
680 async with asyncio.timeout(5):
681 while True:
682 itask = schd.pool._get_task_by_id('2/foo')
683 if itask and itask.state.outputs.is_message_complete('failed'):
684 break
685 await asyncio.sleep(0)
686
687 # re-trigger 2/foo
688 await run_cmd(
689 force_trigger_tasks(
690 schd, ['2/foo'], []
691 )
692 )
693
694 # it should re-run
695 async with asyncio.timeout(5):
696 while True:
697 if log_filter(contains='[2/foo/02:running] (received)failed'):
698 break
699 await asyncio.sleep(0)
700
701
702 async def test_trigger_with_task_selector(flow, scheduler, start, monkeypatch):
703 """Test task matching with the trigger command.
704
705 This test is intended to extend the other integration tests for ID matching
706 with a real use case to ensure the code in cylc.flow.commands
707 (which parses and standardises IDs) is working correctly.
708 """
709 id_ = flow({
710 'scheduling': {
711 'graph': {
712 'R1': 'a & b & c & d & e & f & g'
713 }
714 }
715 })
716 schd: Scheduler = scheduler(id_)
717 async with start(schd):
718 trigger_calls = []
719
720 def _force_trigger_tasks(_schd, ids, *_, **__):
721 trigger_calls.append(
722 {id_.relative_id_with_selectors for id_ in ids}
723 )
724
725 monkeypatch.setattr(
726 'cylc.flow.commands._force_trigger_tasks', _force_trigger_tasks
727 )
728
729 schd.pool._get_task_by_id('1/a').state_reset(TASK_STATUS_SUBMITTED)
730 schd.pool._get_task_by_id('1/b').state_reset(TASK_STATUS_RUNNING)
731 schd.pool._get_task_by_id('1/c').state_reset(TASK_STATUS_SUCCEEDED)
732 schd.pool._get_task_by_id('1/d').state_reset(TASK_STATUS_FAILED)
733
734 await run_cmd(force_trigger_tasks(schd, ['*:submitted'], []))
735 assert trigger_calls == [{'1/a'}]
736 trigger_calls.clear()
737
738 await run_cmd(force_trigger_tasks(schd, ['*:running'], []))
739 assert trigger_calls == [{'1/b'}]
740 trigger_calls.clear()
741
742 await run_cmd(force_trigger_tasks(schd, ['*:succeeded'], []))
743 assert trigger_calls == [{'1/c'}]
744 trigger_calls.clear()
745
746 await run_cmd(force_trigger_tasks(schd, ['*:failed'], []))
747 assert trigger_calls == [{'1/d'}]
748 trigger_calls.clear()
749
750
751 async def test_pre_warm_start_group_trigger(flow, scheduler, run, complete):
752 """Group-triggered tasks that are before the start point should run in
753 order.
754
755 This is designed to handle re-running a family of one-time setup tasks
756 in a warm-started workflow.
757 https://github.com/cylc/cylc-flow/pull/7101
758 """
759 schd: Scheduler = scheduler(
760 flow({
761 'scheduling': {
762 'cycling mode': 'integer',
763 'runahead limit': 'P2',
764 'graph': {
765 'R1': 'start => c1 => c2 => c3 => foo',
766 'P1': 'foo[-P1] => foo',
767 },
768 },
769 'runtime': {
770 'COLD': {},
771 **{f'c{n}': {'inherit': 'COLD'} for n in (1, 2, 3)},
772 },
773 }),
774 paused_start=False,
775 startcp='5'
776 )
777 async with run(schd):
778 schd.pool.set_hold_point(IntegerPoint('4'))
779
780 await run_cmd(force_trigger_tasks(schd, ['1/COLD'], []))
781 assert schd.pool.get_task_ids() == {'1/c1', '5/foo'}
782
783 await complete(schd, '1/c1', timeout=10)
784 assert schd.pool.get_task_ids() == {'1/c2', '5/foo'}
785 assert schd.pool._get_task_by_id('1/c2').state(TASK_STATUS_WAITING)
786
787 await complete(schd, '1/c2', '1/c3', timeout=10)
788 assert schd.pool.get_task_ids() == {'5/foo'}
789
790 # Check list of pre-start tasks to trigger has been cleared:
791 assert not schd.pool.pre_start_tasks_to_trigger
792
793
794 async def test_pre_warm_start_trigger_flow_new(
795 flow, scheduler, run, complete
796 ):
797 """In a warm-started workflow, triggering tasks that are < startcp:
798 * Should not flow on in flow=1
799 * Should flow on in flow=new
800
801 As we don't have any history for pre-startcp tasks in a warm start,
802 we treat them as complete in flow=1.
803 https://github.com/cylc/cylc-flow/pull/7148
804 """
805 schd: Scheduler = scheduler(
806 flow({
807 'scheduling': {
808 'cycling mode': 'integer',
809 'graph': {
810 'P1': 'foo[-P1] => foo',
811 },
812 },
813 }),
814 paused_start=False,
815 startcp='10'
816 )
817 async with run(schd):
818 schd.pool.set_hold_point(IntegerPoint('9'))
819
820 # flow=1 - don't flow on:
821 await run_cmd(force_trigger_tasks(schd, ['1/foo'], []))
822 assert schd.pool.get_task_ids() == {'1/foo', '10/foo'}
823 await complete(schd, '1/foo', timeout=10)
824 assert schd.pool.get_task_ids() == {'10/foo'}
825
826 # flow=new - flow on:
827 await run_cmd(force_trigger_tasks(schd, ['3/foo'], [FLOW_NEW]))
828 assert schd.pool.get_task_ids() == {'3/foo', '10/foo'}
829 await complete(schd, '5/foo', timeout=10)
830 assert schd.pool.get_task_ids() == {'6/foo', '10/foo'}
831
832
833 async def test_pre_warm_start_interraction_with_auto_restart(
834 flow,
835 scheduler,
836 start,
837 log_filter,
838 ):
839 """Test interaction between warm-start pre-startcp tasks and auto-restart.
840
841 The list of pre-startcp tasks to run is held in memory only, no DB backup,
842 so get wiped out by restart.
843 """
844 schd: Scheduler = scheduler(
845 flow(
846 {
847 'scheduling': {
848 'cycling mode': 'integer',
849 'graph': {
850 'P1': 'foo[-P1] => foo',
851 },
852 },
853 }
854 ),
855 paused_start=False,
856 startcp='10',
857 )
858 async with start(schd):
859 # trigger a pre-initial task (pre start-cycle point)
860 await run_cmd(force_trigger_tasks(schd, ['^/foo'], []))
861 assert schd.pool.pre_start_tasks_to_trigger
862
863 # configure the workflow to auto-retsart
864 schd.auto_restart_mode = AutoRestartMode.RESTART_NORMAL
865 schd.auto_restart_time = 0
866
867 # the workflow should not auto-restart whilst there are pre-initial
868 # tasks in play
869 await schd.workflow_shutdown()
870 assert log_filter(
871 contains='Waiting for pre start-cycle tasks to complete'
872 )
873 assert schd.stop_mode is None
874
875 # remove the pre-initial task
876 await run_cmd(remove_tasks(schd, ['^/foo'], []))
877 assert schd.pool.pre_start_tasks_to_trigger == set()
878
879 # the workflow should now auto-restart as normal
880 await schd.workflow_shutdown()
881 assert schd.stop_mode is not None