sys broker test failure causes other tests to yield false negatives

pull/218/head^2
Andrew Mirsky 2025-06-14 15:15:00 -04:00
rodzic 4da47315ab
commit a255dc0e54
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: A98E67635CDF2C39
1 zmienionych plików z 50 dodań i 48 usunięć

Wyświetl plik

@ -13,51 +13,53 @@ from amqtt.mqtt.constants import QOS_0
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# test broker sys # test broker sys
@pytest.mark.asyncio # @pytest.mark.asyncio
@pytest.mark.xfail( # @pytest.mark.xfail(
reason="see https://github.com/Yakifo/amqtt/issues/215", # reason="see https://github.com/Yakifo/amqtt/issues/215",
strict=True, # strict=False,
) # )
async def test_broker_sys_plugin() -> None: # async def test_broker_sys_plugin() -> None:
#
class MockEntryPoints: # class MockEntryPoints:
#
def select(self, group) -> list[EntryPoint]: # def select(self, group) -> list[EntryPoint]:
match group: # match group:
case 'tests.mock_plugins': # case 'tests.mock_plugins':
return [ # return [
EntryPoint(name='BrokerSysPlugin', group='tests.mock_plugins', value='amqtt.plugins.sys.broker:BrokerSysPlugin'), # EntryPoint(name='BrokerSysPlugin', group='tests.mock_plugins', value='amqtt.plugins.sys.broker:BrokerSysPlugin'),
] # ]
case _: # case _:
return list() # return list()
#
with patch("amqtt.plugins.manager.entry_points", side_effect=MockEntryPoints) as mocked_mqtt_publish: #
# with patch("amqtt.plugins.manager.entry_points", side_effect=MockEntryPoints) as mocked_mqtt_publish:
config = { #
"listeners": { # config = {
"default": {"type": "tcp", "bind": "127.0.0.1:1883", "max_connections": 10}, # "listeners": {
}, # "default": {"type": "tcp", "bind": "127.0.0.1:1883", "max_connections": 10},
'sys_interval': 1 # },
} # 'sys_interval': 1
# }
broker = Broker(plugin_namespace='tests.mock_plugins', config=config) #
await broker.start() # broker = Broker(plugin_namespace='tests.mock_plugins', config=config)
client = MQTTClient() # await broker.start()
await client.connect("mqtt://127.0.0.1:1883/") # client = MQTTClient()
await client.subscribe([("$SYS/broker/uptime", QOS_0),]) # await client.connect("mqtt://127.0.0.1:1883/")
await client.publish('test/topic', b'my test message') # await client.subscribe([("$SYS/broker/uptime", QOS_0),])
await asyncio.sleep(2) # await client.publish('test/topic', b'my test message')
sys_msg_count = 0 # await asyncio.sleep(2)
try: # sys_msg_count = 0
while True: # try:
message = await client.deliver_message(timeout_duration=0.5) # while True:
if '$SYS' in message.topic: # message = await client.deliver_message(timeout_duration=0.5)
sys_msg_count += 1 # if '$SYS' in message.topic:
except asyncio.TimeoutError: # sys_msg_count += 1
pass # except asyncio.TimeoutError:
# pass
logger.warning(f">>> sys message: {message.topic} - {message.data}") #
await client.disconnect() # logger.warning(f">>> sys message: {message.topic} - {message.data}")
await broker.shutdown() # await client.disconnect()
# await broker.shutdown()
assert sys_msg_count > 1 #
#
# assert sys_msg_count > 1