forked from cylc/cylc-flow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from wxtim/fix-workflow-state-check.tests3
more tests
- Loading branch information
Showing
3 changed files
with
245 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# 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/>. | ||
|
||
"""Tests for the backend method of workflow_state""" | ||
|
||
|
||
from asyncio import sleep | ||
import pytest | ||
from textwrap import dedent | ||
from typing import TYPE_CHECKING | ||
|
||
from cylc.flow.dbstatecheck import CylcWorkflowDBChecker as Checker | ||
|
||
|
||
if TYPE_CHECKING: | ||
from cylc.flow.dbstatecheck import CylcWorkflowDBChecker | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
async def checker( | ||
mod_flow, mod_scheduler, mod_run, mod_complete | ||
) -> 'CylcWorkflowDBChecker': | ||
"""Make a real world database. | ||
We could just write the database manually but this is a better | ||
test of the overall working of the function under test. | ||
""" | ||
wid = mod_flow({ | ||
'scheduling': { | ||
'graph': {'P1Y': dedent(''' | ||
good:succeeded | ||
bad:failed? | ||
output:custom_output | ||
''')}, | ||
'initial cycle point': '1000', | ||
'final cycle point': '1001' | ||
}, | ||
'runtime': { | ||
'bad': {'simulation': {'fail cycle points': '1000'}}, | ||
'output': {'outputs': {'trigger': 'message'}} | ||
} | ||
}) | ||
schd = mod_scheduler(wid, paused_start=False) | ||
async with mod_run(schd): | ||
await mod_complete(schd) | ||
schd.pool.force_trigger_tasks(['1000/good'], [2]) | ||
# Allow a cycle of the main loop to pass so that flow 2 can be | ||
# added to db | ||
await sleep(1) | ||
yield Checker( | ||
'somestring', 'utterbunkum', | ||
schd.workflow_db_mgr.pub_path | ||
) | ||
|
||
|
||
def test_basic(checker): | ||
"""Pass no args, get unfiltered output""" | ||
result = checker.workflow_state_query() | ||
expect = [ | ||
['bad', '10000101T0000Z', 'failed'], | ||
['bad', '10010101T0000Z', 'succeeded'], | ||
['good', '10000101T0000Z', 'succeeded'], | ||
['good', '10010101T0000Z', 'succeeded'], | ||
['output', '10000101T0000Z', 'succeeded'], | ||
['output', '10010101T0000Z', 'succeeded'], | ||
['good', '10000101T0000Z', 'waiting', '(flows=2)'], | ||
] | ||
assert result == expect | ||
|
||
|
||
def test_task(checker): | ||
"""Filter by task name""" | ||
result = checker.workflow_state_query(task='bad') | ||
assert result == [ | ||
['bad', '10000101T0000Z', 'failed'], | ||
['bad', '10010101T0000Z', 'succeeded'] | ||
] | ||
|
||
|
||
def test_point(checker): | ||
"""Filter by point""" | ||
result = checker.workflow_state_query(cycle='10000101T0000Z') | ||
assert result == [ | ||
['bad', '10000101T0000Z', 'failed'], | ||
['good', '10000101T0000Z', 'succeeded'], | ||
['output', '10000101T0000Z', 'succeeded'], | ||
['good', '10000101T0000Z', 'waiting', '(flows=2)'], | ||
] | ||
|
||
|
||
def test_status(checker): | ||
"""Filter by status""" | ||
result = checker.workflow_state_query(selector='failed') | ||
expect = [ | ||
['bad', '10000101T0000Z', 'failed'], | ||
] | ||
assert result == expect | ||
|
||
|
||
def test_output(checker): | ||
"""Filter by flow number""" | ||
result = checker.workflow_state_query(selector='message', is_message=True) | ||
expect = [ | ||
[ | ||
'output', | ||
'10000101T0000Z', | ||
"{'submitted': 'submitted', 'started': 'started', 'succeeded': " | ||
"'succeeded', 'trigger': 'message'}", | ||
], | ||
[ | ||
'output', | ||
'10010101T0000Z', | ||
"{'submitted': 'submitted', 'started': 'started', 'succeeded': " | ||
"'succeeded', 'trigger': 'message'}", | ||
], | ||
] | ||
assert result == expect | ||
|
||
|
||
def test_flownum(checker): | ||
"""Pass no args, get unfiltered output""" | ||
result = checker.workflow_state_query(flow_num=2) | ||
expect = [ | ||
['good', '10000101T0000Z', 'waiting', '(flows=2)'], | ||
] | ||
assert result == expect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters