File: test_workflow_status.py

package info (click to toggle)
cylc-flow 8.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,368 kB
  • sloc: python: 87,751; sh: 17,109; sql: 233; xml: 171; javascript: 78; lisp: 55; makefile: 11
file content (175 lines) | stat: -rw-r--r-- 5,130 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from types import SimpleNamespace

import pytest
from metomi.isodatetime.data import TimePoint

from cylc.flow.cycling.integer import IntegerPoint
from cylc.flow.workflow_status import (
    WORKFLOW_STATUS_RUNNING_TO_HOLD,
    WORKFLOW_STATUS_RUNNING_TO_STOP,
    StopMode,
    WorkflowStatus,
    get_workflow_status,
    get_workflow_status_msg,
)

STOP_TIME = TimePoint(year=2006).to_local_time_zone()


def schd(
    final_point=None,
    hold_point=None,
    is_paused=False,
    is_stalled=None,
    stop_clock_time=None,
    stop_mode=None,
    stop_point=None,
    stop_task_id=None,
    reload_pending=False,
):
    return SimpleNamespace(
        is_paused=is_paused,
        is_stalled=is_stalled,
        stop_clock_time=stop_clock_time,
        stop_mode=stop_mode,
        reload_pending=reload_pending,
        pool=SimpleNamespace(
            hold_point=hold_point,
            stop_point=stop_point,
            stop_task_id=stop_task_id,
        ),
        config=SimpleNamespace(final_point=final_point),
        options=SimpleNamespace(utc_mode=True),
    )


@pytest.mark.parametrize(
    'kwargs, state, message',
    [
        # test each of the states
        (
            {'is_paused': True},
            WorkflowStatus.PAUSED,
            'paused'
        ),
        (
            {'reload_pending': 'message'},
            WorkflowStatus.PAUSED,
            'reloading: message'
        ),
        (
            {'stop_mode': StopMode.AUTO},
            WorkflowStatus.STOPPING,
            'stopping: waiting for active jobs to complete'
        ),
        (
            {'hold_point': 2},
            WorkflowStatus.RUNNING,
            WORKFLOW_STATUS_RUNNING_TO_HOLD % 2
        ),
        (
            {'stop_point': 4},
            WorkflowStatus.RUNNING,
            WORKFLOW_STATUS_RUNNING_TO_STOP % 4
        ),
        (
            {'stop_clock_time': int(STOP_TIME.seconds_since_unix_epoch)},
            WorkflowStatus.RUNNING,
            WORKFLOW_STATUS_RUNNING_TO_STOP % str(STOP_TIME)
        ),
        (
            {'stop_task_id': '6/foo'},
            WorkflowStatus.RUNNING,
            WORKFLOW_STATUS_RUNNING_TO_STOP % '6/foo'
        ),
        (
            {'final_point': 8},
            WorkflowStatus.RUNNING,
            WORKFLOW_STATUS_RUNNING_TO_STOP % 8
        ),
        (
            {'is_stalled': True},
            WorkflowStatus.RUNNING,
            'stalled'
        ),
        (
            {},
            WorkflowStatus.RUNNING,
            'running'
        ),

        # test combinations
        (
            # stopping should trump stalled, paused & running
            {
                'stop_mode': StopMode.REQUEST_NOW,
                'is_stalled': True,
                'is_paused': True
            },
            WorkflowStatus.STOPPING,
            'stopping: shutting down'
        ),
        (
            {'is_stalled': True, 'is_paused': True},
            WorkflowStatus.PAUSED,
            'stalled and paused',
        ),
        (
            # earliest of stop point, hold point and stop task id
            {
                'stop_point': IntegerPoint(4),
                'hold_point': IntegerPoint(2),
                'stop_task_id': '6/foo',
            },
            WorkflowStatus.RUNNING,
            WORKFLOW_STATUS_RUNNING_TO_HOLD % 2,
        ),
        (
            {
                'stop_point': IntegerPoint(11),
                'hold_point': IntegerPoint(15),
                'stop_task_id': '9/bar',
            },
            WorkflowStatus.RUNNING,
            WORKFLOW_STATUS_RUNNING_TO_STOP % '9/bar',
        ),
        (
            {
                'stop_point': IntegerPoint(3),
                'hold_point': IntegerPoint(3),
            },
            WorkflowStatus.RUNNING,
            WORKFLOW_STATUS_RUNNING_TO_STOP % 3,
        ),
        (
            # stop point trumps final point
            {
                'stop_point': IntegerPoint(1),
                'final_point': IntegerPoint(2),
            },
            WorkflowStatus.RUNNING,
            WORKFLOW_STATUS_RUNNING_TO_STOP % 1,
        ),
    ]
)
def test_get_workflow_status(kwargs, state, message, set_cycling_type):
    set_cycling_type()
    scheduler = schd(**kwargs)
    assert get_workflow_status(scheduler) == state
    assert get_workflow_status_msg(scheduler) == message