Skip to content

Commit 717654a

Browse files
authored
chore: Attempt to reduce a01 test flakiness by fixing shutdown to reduce number of active threads (#420)
* chore: Add timeout to queue request to diagnose * chore: fix a01 client cleanup * chore: fix lint errors
1 parent 1cec274 commit 717654a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tests/test_a01_api.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
from . import mqtt_packet
3737
from .conftest import QUEUE_TIMEOUT
3838

39+
RELEASE_TIMEOUT = 2
40+
3941

4042
@pytest.fixture(name="a01_mqtt_client")
4143
async def a01_mqtt_client_fixture(
@@ -59,9 +61,11 @@ async def a01_mqtt_client_fixture(
5961
try:
6062
yield client
6163
finally:
62-
if not client.is_connected():
64+
# Cleanup is best effort to reduce number of active threads
65+
if client.is_connected():
6366
try:
64-
await client.async_release()
67+
async with asyncio.timeout(RELEASE_TIMEOUT):
68+
await client.async_release()
6569
except Exception:
6670
pass
6771

@@ -207,8 +211,8 @@ async def test_set_value(
207211
"""Test sending an arbitrary MQTT message and parsing the response."""
208212
# Clear existing messages received during setup
209213
assert received_requests.qsize() == 2
210-
assert received_requests.get(block=True)
211-
assert received_requests.get(block=True)
214+
assert received_requests.get(block=True, timeout=QUEUE_TIMEOUT)
215+
assert received_requests.get(block=True, timeout=QUEUE_TIMEOUT)
212216
assert received_requests.empty()
213217

214218
# Prepare the response message

0 commit comments

Comments
 (0)