Debian Codegraph @

tests/integration/test_dbstatecheck.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 backend method of workflow_state"""
18
19 import pytest
20
21 from cylc.flow.commands import (
22 run_cmd,
23 force_trigger_tasks
24 )
25 from cylc.flow.dbstatecheck import CylcWorkflowDBChecker
26 from cylc.flow.scheduler import Scheduler
27
28
29 @pytest.fixture(scope='module')
30 async def checker(
31 mod_flow, mod_scheduler, mod_run, mod_complete
32 ):
33 """Make a real world database.
34
35 We could just write the database manually but this is a better
36 test of the overall working of the function under test.
37 """
38 wid = mod_flow({
39 'scheduling': {
40 'initial cycle point': '1000',
41 'final cycle point': '1001',
42 'graph': {
43 'P1Y': '''
44 good:succeeded
45 bad:failed?
46 output:custom_output
47 '''
48 },
49 },
50 'runtime': {
51 'bad': {'simulation': {'fail cycle points': '1000'}},
52 'output': {
53 'outputs': {'trigger': 'message', 'custom_output': 'foo'}
54 }
55 }
56 })
57 schd: Scheduler = mod_scheduler(wid, paused_start=False)
58 async with mod_run(schd):
59 # allow a cycle of the main loop to pass so that flow 2 can be
60 # added to db
61 await mod_complete(schd)
62
63 # trigger a new task in flow 2
64 await run_cmd(force_trigger_tasks(schd, ['1000/good'], ['2']))
65
66 # update the database
67 schd.process_workflow_db_queue()
68
69 # yield a DB checker
70 with CylcWorkflowDBChecker(
71 'somestring', 'utterbunkum', schd.workflow_db_mgr.pub_path
72 ) as _checker:
73 yield _checker
74
75
76 def test_basic(checker):
77 """Pass no args, get unfiltered output"""
78 result = checker.workflow_state_query()
79 expect = [
80 ['bad', '10000101T0000Z', 'failed'],
81 ['bad', '10010101T0000Z', 'succeeded'],
82 ['good', '10000101T0000Z', 'succeeded'],
83 ['good', '10010101T0000Z', 'succeeded'],
84 ['output', '10000101T0000Z', 'succeeded'],
85 ['output', '10010101T0000Z', 'succeeded'],
86 ['good', '10000101T0000Z', 'waiting', '(flows=2)'],
87 ['good', '10010101T0000Z', 'waiting', '(flows=2)'], ]
88 assert sorted(result) == sorted(expect)
89
90
91 def test_task(checker):
92 """Filter by task name"""
93 result = checker.workflow_state_query(task='bad')
94 assert sorted(result) == ([
95 ['bad', '10000101T0000Z', 'failed'],
96 ['bad', '10010101T0000Z', 'succeeded']
97 ])
98
99
100 def test_point(checker):
101 """Filter by point"""
102 result = checker.workflow_state_query(cycle='10000101T0000Z')
103 assert sorted(result) == sorted([
104 ['bad', '10000101T0000Z', 'failed'],
105 ['good', '10000101T0000Z', 'succeeded'],
106 ['output', '10000101T0000Z', 'succeeded'],
107 ['good', '10000101T0000Z', 'waiting', '(flows=2)'],
108 ])
109
110
111 def test_status(checker):
112 """Filter by status"""
113 result = checker.workflow_state_query(selector='failed')
114 expect = [
115 ['bad', '10000101T0000Z', 'failed'],
116 ]
117 assert result == expect
118
119
120 def test_output(checker):
121 """Filter by flow number"""
122 result = checker.workflow_state_query(selector='message', is_message=True)
123 expect = [
124 [
125 'output',
126 '10000101T0000Z',
127 "{'submitted': 'submitted', 'started': 'started', 'succeeded': "
128 "'succeeded', 'trigger': 'message', 'custom_output': 'foo'}",
129 ],
130 [
131 'output',
132 '10010101T0000Z',
133 "{'submitted': 'submitted', 'started': 'started', 'succeeded': "
134 "'succeeded', 'trigger': 'message', 'custom_output': 'foo'}",
135 ],
136 ]
137 assert result == expect
138
139
140 def test_flownum(checker):
141 """Pass no args, get unfiltered output"""
142 result = checker.workflow_state_query(flow_num=2)
143 expect = [
144 ['good', '10000101T0000Z', 'waiting', '(flows=2)'],
145 ['good', '10010101T0000Z', 'waiting', '(flows=2)'],
146 ]
147 assert result == expect