Skip to content

Commit d8d4e39

Browse files
committed
add unit test
1 parent d5fffe9 commit d8d4e39

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/test_loop.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ def test_loop_basic(self) -> None:
6868
assert ret_code == expected_rc
6969
expected_rc += 1
7070

71+
def test_loop_timeout_vs_socket_timeout(self):
72+
"""
73+
loop() should throw MMQTTException if the timeout argument is bigger than the socket timeout.
74+
"""
75+
mqtt_client = MQTT.MQTT(
76+
broker="127.0.0.1",
77+
port=1883,
78+
socket_pool=socket,
79+
ssl_context=ssl.create_default_context(),
80+
socket_timeout=1
81+
)
82+
83+
mqtt_client.is_connected = lambda: True
84+
with self.assertRaises(MQTT.MMQTTException) as context:
85+
mqtt_client.loop(timeout=0.5)
86+
87+
assert "loop timeout" in str(context.exception)
88+
7189
def test_loop_is_connected(self):
7290
"""
7391
loop() should throw MMQTTException if not connected

0 commit comments

Comments
 (0)