|
1 | 1 | import asyncio
|
2 | 2 | import json
|
| 3 | +import logging |
3 | 4 | from collections.abc import AsyncGenerator
|
4 | 5 | from queue import Queue
|
5 | 6 | from typing import Any
|
@@ -168,7 +169,7 @@ async def test_async_connect(received_requests: Queue, connected_mqtt_client: Ro
|
168 | 169 | assert received_requests.qsize() >= 2 # Connect and Subscribe
|
169 | 170 |
|
170 | 171 |
|
171 |
| -async def test_connect_failure( |
| 172 | +async def test_connect_failure_response( |
172 | 173 | received_requests: Queue, response_queue: Queue, mqtt_client: RoborockMqttClientV1
|
173 | 174 | ) -> None:
|
174 | 175 | """Test the broker responding with a connect failure."""
|
@@ -203,6 +204,24 @@ async def test_disconnect_failure(connected_mqtt_client: RoborockMqttClientV1) -
|
203 | 204 | await connected_mqtt_client.async_disconnect()
|
204 | 205 |
|
205 | 206 |
|
| 207 | +async def test_disconnect_failure_response( |
| 208 | + received_requests: Queue, |
| 209 | + response_queue: Queue, |
| 210 | + connected_mqtt_client: RoborockMqttClientV1, |
| 211 | + caplog: pytest.LogCaptureFixture, |
| 212 | +) -> None: |
| 213 | + """Test the broker responding with a connect failure.""" |
| 214 | + |
| 215 | + # Enqueue a failed message -- however, the client does not process any |
| 216 | + # further messages and there is no parsing error, and no failed log messages. |
| 217 | + response_queue.put(mqtt_packet.gen_disconnect(reason_code=1)) |
| 218 | + assert connected_mqtt_client.is_connected() |
| 219 | + with caplog.at_level(logging.ERROR, logger="homeassistant.components.nest"): |
| 220 | + await connected_mqtt_client.async_disconnect() |
| 221 | + assert not connected_mqtt_client.is_connected() |
| 222 | + assert not caplog.records |
| 223 | + |
| 224 | + |
206 | 225 | async def test_async_release(connected_mqtt_client: RoborockMqttClientV1) -> None:
|
207 | 226 | """Test the async_release API will disconnect the client."""
|
208 | 227 | await connected_mqtt_client.async_release()
|
|
0 commit comments