From c52f8727002ec84c1063069ea1ccf8160c527f49 Mon Sep 17 00:00:00 2001 From: Pierre Fersing Date: Sat, 13 Jan 2024 18:19:36 +0100 Subject: [PATCH] Fix test that try to loop_stop() when not using loop_start() --- tests/test_client.py | 52 ++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index 145f911c..6cb3c4e4 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -210,44 +210,40 @@ def on_disconnect(*args): mqttc.on_connect = on_connect mqttc.on_disconnect = on_disconnect + mqttc.connect("localhost", fake_broker.port) - try: - mqttc.connect("localhost", fake_broker.port) + fake_broker.start() - fake_broker.start() + # not yet connected, packet are not yet processed by loop() + assert not mqttc.is_connected() - # not yet connected, packet are not yet processed by loop() - assert not mqttc.is_connected() - - # connect packet is sent during connect() call - connect_packet = paho_test.gen_connect( - "test_with_loop", keepalive=60, - proto_ver=MQTTProtocolVersion.MQTTv311) - packet_in = fake_broker.receive_packet(1000) - assert packet_in # Check connection was not closed - assert packet_in == connect_packet + # connect packet is sent during connect() call + connect_packet = paho_test.gen_connect( + "test_with_loop", keepalive=60, + proto_ver=MQTTProtocolVersion.MQTTv311) + packet_in = fake_broker.receive_packet(1000) + assert packet_in # Check connection was not closed + assert packet_in == connect_packet - connack_packet = paho_test.gen_connack(rc=0) - count = fake_broker.send_packet(connack_packet) - assert count # Check connection was not closed - assert count == len(connack_packet) + connack_packet = paho_test.gen_connack(rc=0) + count = fake_broker.send_packet(connack_packet) + assert count # Check connection was not closed + assert count == len(connack_packet) - # call loop() to process the connack packet - assert mqttc.loop(timeout=1) == MQTTErrorCode.MQTT_ERR_SUCCESS + # call loop() to process the connack packet + assert mqttc.loop(timeout=1) == MQTTErrorCode.MQTT_ERR_SUCCESS - assert on_connect_reached.wait(1) - assert mqttc.is_connected() + assert on_connect_reached.wait(1) + assert mqttc.is_connected() - fake_broker.finish() + fake_broker.finish() - # call loop() to detect the connection lost - assert mqttc.loop(timeout=1) == MQTTErrorCode.MQTT_ERR_CONN_LOST + # call loop() to detect the connection lost + assert mqttc.loop(timeout=1) == MQTTErrorCode.MQTT_ERR_CONN_LOST - assert on_disconnect_reached.wait(1) - assert not mqttc.is_connected() + assert on_disconnect_reached.wait(1) + assert not mqttc.is_connected() - finally: - mqttc.loop_stop() class TestPublishBroker2Client: