Debian Codegraph @

tests/unit/test_indep_task_queues.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 # Tests for the task queue manager module
18
19 from collections import Counter
20 from unittest.mock import Mock
21
22 import pytest
23
24 from cylc.flow.task_proxy import TaskProxy
25 from cylc.flow.task_queues.independent import IndepQueueManager
26
27
28 MEMBERS = {"a", "b", "c", "d", "e", "f"}
29 ACTIVE = Counter(["a", "a", "d"])
30
31 ALL_TASK_NAMES = [
32 "o1", "o2", "o3", "o4", "o5", "o6", "o7",
33 "s1", "s2", "s3", "s4", "s5",
34 "b1", "b2", "b3", "b4", "b5",
35 "foo"
36 ]
37
38 DESCENDANTS = {
39 "root": ALL_TASK_NAMES + ["BIG", "SML", "OTH", "foo"],
40 "BIG": ["b1", "b2", "b3", "b4", "b5"],
41 "SML": ["s1", "s2", "s3", "s4", "s5"],
42 "OTH": ["o1", "o2", "o3", "o4", "o5", "o6", "o7"]
43 }
44
45 QCONFIG = {
46 "default": {
47 "limit": 6,
48 "members": [] # (auto: all task names)
49 },
50 "big": {
51 "members": ["BIG", "foo"],
52 "limit": 2
53 },
54 "sml": {
55 "members": ["SML", "foo"],
56 "limit": 3
57 }
58 }
59
60 READY_TASK_NAMES = ["b3", "s4", "o2", "s3", "b4", "o3", "o4", "o5", "o6", "o7"]
61
62
63 @pytest.mark.parametrize(
64 "active, expected_released, expected_foo_groups",
65 [
66 (
67 Counter(["b1", "b2", "s1", "o1"]),
68 ["s4", "o2", "s3", "o3", "o4", "o5", "o6"],
69 ["sml"]
70 )
71 ]
72 )
73 def test_queue_and_release(
74 active,
75 expected_released,
76 expected_foo_groups
77 ):
78 """Test task queue and release."""
79 # configure the queue
80 queue_mgr = IndepQueueManager(QCONFIG, ALL_TASK_NAMES, DESCENDANTS)
81
82 # add newly ready tasks to the queue
83 for name in READY_TASK_NAMES:
84 itask = Mock(spec=TaskProxy)
85 itask.tdef.name = name
86 itask.state.is_held = False
87 queue_mgr.push_task(itask)
88
89 # release tasks, given current active task counter
90 released = queue_mgr.release_tasks(active)
91 assert sorted(r.tdef.name for r in released) == sorted(expected_released)
92
93 # check that adopted orphans end up in the default queue
94 orphans = ["orphan1", "orphan2"]
95 queue_mgr.adopt_tasks(orphans)
96 for orphan in orphans:
97 assert orphan in queue_mgr.queues["default"].members
98
99 # check second assignment overrides first
100 for group in expected_foo_groups:
101 assert "foo" in queue_mgr.queues[group].members