Skip to content

Commit 0ef45e8

Browse files
committed
test: explicitly disconnect threads
1 parent 887eef8 commit 0ef45e8

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

roborock/roborock_future.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@ async def async_get(self, timeout: float | int) -> tuple[Any, VacuumError | None
3333
async with async_timeout.timeout(timeout):
3434
return await self.fut
3535
finally:
36-
self.fut.cancel()
36+
try:
37+
self.fut.cancel()
38+
except Exception:
39+
pass

tests/conftest.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,22 @@ def handle_select(rlist: list, wlist: list, *args: Any) -> list:
138138

139139

140140
@pytest.fixture(name="mqtt_client")
141-
def mqtt_client(mock_create_connection: None, mock_select: None) -> Generator[RoborockMqttClientV1, None, None]:
141+
async def mqtt_client(mock_create_connection: None, mock_select: None) -> Generator[RoborockMqttClientV1, None, None]:
142142
user_data = UserData.from_dict(USER_DATA)
143143
home_data = HomeData.from_dict(HOME_DATA_RAW)
144144
device_info = DeviceData(
145145
device=home_data.devices[0],
146146
model=home_data.products[0].model,
147147
)
148148
client = RoborockMqttClientV1(user_data, device_info)
149-
yield client
150-
# Clean up any resources after the test
149+
try:
150+
yield client
151+
finally:
152+
if not client.is_connected():
153+
try:
154+
await client.async_release()
155+
except Exception:
156+
pass
151157

152158

153159
@pytest.fixture(name="mock_rest", autouse=True)
@@ -226,11 +232,19 @@ def handle_write(data: bytes) -> None:
226232

227233

228234
@pytest.fixture(name="local_client")
229-
def local_client_fixture(mock_create_local_connection: None) -> Generator[RoborockLocalClientV1, None, None]:
235+
async def local_client_fixture(mock_create_local_connection: None) -> Generator[RoborockLocalClientV1, None, None]:
230236
home_data = HomeData.from_dict(HOME_DATA_RAW)
231237
device_info = DeviceData(
232238
device=home_data.devices[0],
233239
model=home_data.products[0].model,
234240
host=TEST_LOCAL_API_HOST,
235241
)
236-
yield RoborockLocalClientV1(device_info)
242+
client = RoborockLocalClientV1(device_info)
243+
try:
244+
yield client
245+
finally:
246+
if not client.is_connected():
247+
try:
248+
await client.async_release()
249+
except Exception:
250+
pass

tests/test_a01_api.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737

3838
@pytest.fixture(name="a01_mqtt_client")
39-
async def a01_mqtt_client_fixture(mock_create_connection: None, mock_select: None) -> RoborockMqttClientA01:
39+
async def a01_mqtt_client_fixture(mock_create_connection: None, mock_select: None) -> AsyncGenerator[RoborockMqttClientA01, None]:
4040
user_data = UserData.from_dict(USER_DATA)
4141
home_data = HomeData.from_dict(
4242
{
@@ -49,7 +49,15 @@ async def a01_mqtt_client_fixture(mock_create_connection: None, mock_select: Non
4949
device=home_data.devices[0],
5050
model=home_data.products[0].model,
5151
)
52-
return RoborockMqttClientA01(user_data, device_info, RoborockCategory.WASHING_MACHINE)
52+
client = RoborockMqttClientA01(user_data, device_info, RoborockCategory.WASHING_MACHINE)
53+
try:
54+
yield client
55+
finally:
56+
if not client.is_connected():
57+
try:
58+
await client.async_release()
59+
except Exception:
60+
pass
5361

5462

5563
@pytest.fixture(name="connected_a01_mqtt_client")

0 commit comments

Comments
 (0)