Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dwsutherland committed May 30, 2024
1 parent 2d810c7 commit c412f5a
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions cylc/uiserver/tests/test_data_store_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,21 @@
from cylc.flow.network import ZMQSocketBase
from cylc.flow.workflow_files import ContactFileFields as CFF

from cylc.uiserver.data_store_mgr import DataStoreMgr
from cylc.uiserver.data_store_mgr import (
DataStoreMgr,
MAX_LEVEL,
SUBSCRIPTION_LEVELS
)

from .conftest import AsyncClientFixture


async def test_entire_workflow_update(
async def test_workflow_update(
async_client: AsyncClientFixture,
data_store_mgr: DataStoreMgr,
make_entire_workflow
):
"""Test that ``entire_workflow_update`` is executed successfully."""
"""Test that ``_workflow_update`` is executed successfully."""
w_id = 'workflow_id'
entire_workflow = make_entire_workflow(f'{w_id}')
async_client.will_return(entire_workflow.SerializeToString())
Expand All @@ -45,10 +49,13 @@ async def test_entire_workflow_update(
'req_client': async_client
}

# Call the entire_workflow_update function.
# Call the _workflow_update function.
# This should use the client defined above (``async_client``) when
# calling ``workflow_request``.
await data_store_mgr._entire_workflow_update()
await data_store_mgr._workflow_update(
[w_id],
SUBSCRIPTION_LEVELS[MAX_LEVEL]["request"]
)

# The ``DataStoreMgr`` sets the workflow data retrieved in its
# own ``.data`` dictionary, which will contain Protobuf message
Expand All @@ -61,12 +68,12 @@ async def test_entire_workflow_update(
assert entire_workflow.workflow.id == w_id_data['workflow'].id


async def test_entire_workflow_update_ignores_timeout_message(
async def test_workflow_update_ignores_timeout_message(
async_client: AsyncClientFixture,
data_store_mgr: DataStoreMgr
):
"""
Test that ``entire_workflow_update`` ignores if the client
Test that ``_workflow_update`` ignores if the client
receives a ``MSG_TIMEOUT`` message.
"""
w_id = 'workflow_id'
Expand All @@ -77,24 +84,27 @@ async def test_entire_workflow_update_ignores_timeout_message(
'req_client': async_client
}

# Call the entire_workflow_update function.
# Call the _workflow_update function.
# This should use the client defined above (``async_client``) when
# calling ``workflow_request``.
await data_store_mgr._entire_workflow_update()
await data_store_mgr._workflow_update(
[w_id],
SUBSCRIPTION_LEVELS[MAX_LEVEL]["request"]
)

# When a ClientTimeout happens, the ``DataStoreMgr`` object ignores
# that message. So it means that its ``.data`` dictionary MUST NOT
# have an entry for the Workflow ID.
assert w_id not in data_store_mgr.data


async def test_entire_workflow_update_gather_error(
async def test_workflow_update_gather_error(
async_client: AsyncClientFixture,
data_store_mgr: DataStoreMgr,
caplog: pytest.LogCaptureFixture,
):
"""
Test that if ``asyncio.gather`` in ``entire_workflow_update``
Test that if ``asyncio.gather`` in ``_workflow_update``
has a coroutine raising an error, it will handle the error correctly.
"""
# The ``AsyncClient`` will raise an error. This will happen when
Expand All @@ -110,10 +120,13 @@ async def test_entire_workflow_update_gather_error(
'req_client': async_client
}

# Call the entire_workflow_update function.
# Call the _workflow_update function.
# This should use the client defined above (``async_client``) when
# calling ``workflow_request``.
await data_store_mgr._entire_workflow_update()
await data_store_mgr._workflow_update(
['workflow_id'],
SUBSCRIPTION_LEVELS[MAX_LEVEL]["request"]
)
assert caplog.record_tuples == [
('cylc', 40, 'Error communicating with myflow'),
('cylc', 40, 'x'),
Expand All @@ -124,19 +137,22 @@ async def test_entire_workflow_update_gather_error(
assert exc_info and exc_info[0] == ValueError


async def test_entire_workflow_update__stopped_workflow(
async def test_workflow_update__stopped_workflow(
async_client: AsyncClientFixture,
data_store_mgr: DataStoreMgr,
caplog: pytest.LogCaptureFixture,
):
"""Test that DataStoreMgr._entire_workflow_update() handles a stopped
"""Test that DataStoreMgr._workflow_update() handles a stopped
workflow reasonably."""
exc = WorkflowStopped('myflow')
async_client.will_return(exc)
data_store_mgr.workflows_mgr.workflows['workflow_id'] = {
'req_client': async_client
}
await data_store_mgr._entire_workflow_update()
await data_store_mgr._workflow_update(
['workflow_id'],
SUBSCRIPTION_LEVELS[MAX_LEVEL]["request"]
)
assert caplog.record_tuples == [
('cylc', 40, f'WorkflowStopped: {exc}'),
]
Expand Down

0 comments on commit c412f5a

Please sign in to comment.