From 5abeabc36d0af82d4e620c49c5ef5eb5d3785e90 Mon Sep 17 00:00:00 2001 From: Andrew Mirsky Date: Sat, 14 Jun 2025 15:10:40 -0400 Subject: [PATCH] marking test broker sys plugin as xfail --- tests/plugins/test_sys.py | 94 ++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/tests/plugins/test_sys.py b/tests/plugins/test_sys.py index 3b0d5be..6980ce7 100644 --- a/tests/plugins/test_sys.py +++ b/tests/plugins/test_sys.py @@ -13,49 +13,51 @@ from amqtt.mqtt.constants import QOS_0 logger = logging.getLogger(__name__) # test broker sys -# @pytest.mark.asyncio -# async def test_broker_sys_plugin() -> None: -# -# class MockEntryPoints: -# -# def select(self, group) -> list[EntryPoint]: -# match group: -# case 'tests.mock_plugins': -# return [ -# EntryPoint(name='BrokerSysPlugin', group='tests.mock_plugins', value='amqtt.plugins.sys.broker:BrokerSysPlugin'), -# ] -# case _: -# return list() -# -# -# with patch("amqtt.plugins.manager.entry_points", side_effect=MockEntryPoints) as mocked_mqtt_publish: -# -# config = { -# "listeners": { -# "default": {"type": "tcp", "bind": "127.0.0.1:1883", "max_connections": 10}, -# }, -# 'sys_interval': 1 -# } -# -# broker = Broker(plugin_namespace='tests.mock_plugins', config=config) -# await broker.start() -# client = MQTTClient() -# await client.connect("mqtt://127.0.0.1:1883/") -# await client.subscribe([("$SYS/broker/uptime", QOS_0),]) -# await client.publish('test/topic', b'my test message') -# await asyncio.sleep(2) -# sys_msg_count = 0 -# try: -# while True: -# message = await client.deliver_message(timeout_duration=0.5) -# if '$SYS' in message.topic: -# sys_msg_count += 1 -# except asyncio.TimeoutError: -# pass -# -# logger.warning(f">>> sys message: {message.topic} - {message.data}") -# await client.disconnect() -# await broker.shutdown() -# -# -# assert sys_msg_count > 1 +@pytest.mark.asyncio +@pytest.mark.xfail( + reason="see https://github.com/Yakifo/amqtt/issues/215", + strict=True, +) +async def test_broker_sys_plugin() -> None: + + class MockEntryPoints: + + def select(self, group) -> list[EntryPoint]: + match group: + case 'tests.mock_plugins': + return [ + EntryPoint(name='BrokerSysPlugin', group='tests.mock_plugins', value='amqtt.plugins.sys.broker:BrokerSysPlugin'), + ] + case _: + return list() + + with patch("amqtt.plugins.manager.entry_points", side_effect=MockEntryPoints) as mocked_mqtt_publish: + + config = { + "listeners": { + "default": {"type": "tcp", "bind": "127.0.0.1:1883", "max_connections": 10}, + }, + 'sys_interval': 1 + } + + broker = Broker(plugin_namespace='tests.mock_plugins', config=config) + await broker.start() + client = MQTTClient() + await client.connect("mqtt://127.0.0.1:1883/") + await client.subscribe([("$SYS/broker/uptime", QOS_0),]) + await client.publish('test/topic', b'my test message') + await asyncio.sleep(2) + sys_msg_count = 0 + try: + while True: + message = await client.deliver_message(timeout_duration=0.5) + if '$SYS' in message.topic: + sys_msg_count += 1 + except asyncio.TimeoutError: + pass + + logger.warning(f">>> sys message: {message.topic} - {message.data}") + await client.disconnect() + await broker.shutdown() + + assert sys_msg_count > 1