Skip to content

Commit

Permalink
test: Add tests for reuse and concurrent use of .messages
Browse files Browse the repository at this point in the history
  • Loading branch information
empicano committed Jul 1, 2024
1 parent 8552522 commit 25aa68f
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,9 @@ async def test_aexit_client_is_already_disconnected_failure() -> None:
await client.__aexit__(None, None, None)


@pytest.mark.xfail
@pytest.mark.network
async def test_messages_generator_is_reusable() -> None:
"""Test that the messages generator is reusable after dis- and reconnection."""
async def test_messages_view_is_reusable() -> None:
"""Test that ``.messages`` is reusable after dis- and reconnection."""
topic = TOPIC_PREFIX + "test_messages_generator_is_reusable"
client = Client(HOSTNAME)
async with client:
Expand All @@ -409,3 +408,21 @@ async def test_messages_generator_is_reusable() -> None:
# TODO(felix): Switch to anext function from Python 3.10
message = await client.messages.__anext__()
assert message.payload == b"foo"


@pytest.mark.network
async def test_messages_view_multiple_tasks_concurrently() -> None:
"""Test that ``.messages`` can be used concurrently by multiple tasks."""
topic = TOPIC_PREFIX + "test_messages_generator_is_reentrant"
async with Client(HOSTNAME) as client, anyio.create_task_group() as tg:

async def handle() -> None:
# TODO(felix): Switch to anext function from Python 3.10
await client.messages.__anext__()

tg.start_soon(handle)
tg.start_soon(handle)
await anyio.wait_all_tasks_blocked()
await client.subscribe(topic)
await client.publish(topic, "foo")
await client.publish(topic, "bar")

0 comments on commit 25aa68f

Please sign in to comment.