Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flaky tests pass 1 #616

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 BaseException:
pass

# Receive message
rcv = received.result(TIMEOUT)
Expand Down
9 changes: 3 additions & 6 deletions test/test_mqtt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,6 @@ def test_operation_sub_unsub(self):
client.stop()
callbacks.future_stopped.result(TIMEOUT)

sub1_callbacks = False
sub2_callbacks = False
total_callbacks = 0
all_packets_received = Future()
mutex = Lock()
Expand All @@ -1020,7 +1018,6 @@ def subscriber1_callback(self, publish_received_data: mqtt5.PublishReceivedData)
self.mutex.acquire()
var = publish_received_data.publish_packet.payload
self.received_subscriptions[int(var)] = 1
self.sub1_callbacks = True
self.total_callbacks = self.total_callbacks + 1
if self.total_callbacks == 10:
self.all_packets_received.set_result(None)
Expand All @@ -1030,7 +1027,6 @@ def subscriber2_callback(self, publish_received_data: mqtt5.PublishReceivedData)
self.mutex.acquire()
var = publish_received_data.publish_packet.payload
self.received_subscriptions[int(var)] = 1
self.sub2_callbacks = True
self.total_callbacks = self.total_callbacks + 1
if self.total_callbacks == 10:
self.all_packets_received.set_result(None)
Expand Down Expand Up @@ -1154,8 +1150,6 @@ def test_operation_shared_subscription(self):
unsuback_packet = unsubscribe_future.result(TIMEOUT)
self.assertIsInstance(unsuback_packet, mqtt5.UnsubackPacket)

self.assertEqual(self.sub1_callbacks, True)
self.assertEqual(self.sub2_callbacks, True)
self.assertEqual(self.total_callbacks, 10)

for e in self.received_subscriptions:
Expand Down Expand Up @@ -1221,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
Loading