| 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 |
import asyncio |
| 18 |
|
| 19 |
from cylc.flow.network.subscriber import ( |
| 20 |
WorkflowSubscriber, |
| 21 |
process_delta_msg, |
| 22 |
) |
| 23 |
|
| 24 |
|
| 25 |
async def test_publisher(flow, scheduler, run, one_conf, port_range): |
| 26 |
"""It should publish deltas when the flow starts.""" |
| 27 |
id_ = flow(one_conf) |
| 28 |
schd = scheduler(id_, paused_start=False) |
| 29 |
async with run(schd): |
| 30 |
# create a subscriber |
| 31 |
subscriber = WorkflowSubscriber( |
| 32 |
schd.workflow, |
| 33 |
host=schd.host, |
| 34 |
port=schd.server.pub_port, |
| 35 |
topics=[b'workflow'] |
| 36 |
) |
| 37 |
|
| 38 |
async with asyncio.timeout(2): |
| 39 |
# wait for the first delta from the workflow |
| 40 |
btopic, msg = await subscriber.socket.recv_multipart() |
| 41 |
|
| 42 |
_, delta = process_delta_msg(btopic, msg, None) |
| 43 |
for key in ('added', 'updated'): |
| 44 |
if getattr(getattr(delta, key), 'id', None): |
| 45 |
assert schd.id == getattr(delta, key).id |
| 46 |
break |
| 47 |
else: |
| 48 |
raise Exception("Delta wasn't added or updated") |