Skip to content

Commit

Permalink
Update will tests with pause and retry connect in the 311 case
Browse files Browse the repository at this point in the history
  • Loading branch information
Bret Ambrose committed Jan 6, 2025
1 parent f9d25b4 commit a1c406b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion test/test_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,16 @@ def on_message(**kwargs):
ping_timeout_ms=10000,
keep_alive_secs=30
)
disconnecter.connect().result(TIMEOUT)

# A race condition exists in IoT Core where the interrupter may get refused rather than the existing
# connection getting dropped. Loop until we successfully connect.
continue_connecting = True
while continue_connecting:
try:
disconnecter.connect().result(TIMEOUT)
continue_connecting = False
except:
pass

# Receive message
rcv = received.result(TIMEOUT)
Expand Down
3 changes: 3 additions & 0 deletions test/test_mqtt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,9 @@ def test_operation_will(self):
suback_packet = subscribe_future.result(TIMEOUT)
self.assertIsInstance(suback_packet, mqtt5.SubackPacket)

# wait a few seconds to minimize chance of eventual consistency race condition between subscribe and publish
time.sleep(2)

disconnect_packet = mqtt5.DisconnectPacket(reason_code=mqtt5.DisconnectReasonCode.DISCONNECT_WITH_WILL_MESSAGE)
client1.stop(disconnect_packet=disconnect_packet)
callbacks1.future_stopped.result(TIMEOUT)
Expand Down

0 comments on commit a1c406b

Please sign in to comment.