mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 18:28:14 +02:00
Remove duplicate mid handling in MQTT (#116531)
This commit is contained in:
@ -2074,16 +2074,34 @@ async def test_handle_mqtt_on_callback(
|
||||
) -> None:
|
||||
"""Test receiving an ACK callback before waiting for it."""
|
||||
await mqtt_mock_entry()
|
||||
# Simulate an ACK for mid == 1, this will call mqtt_mock._mqtt_handle_mid(mid)
|
||||
mqtt_client_mock.on_publish(mqtt_client_mock, None, 1)
|
||||
await hass.async_block_till_done()
|
||||
# Make sure the ACK has been received
|
||||
await hass.async_block_till_done()
|
||||
# Now call publish without call back, this will call _wait_for_mid(msg_info.mid)
|
||||
await mqtt.async_publish(hass, "no_callback/test-topic", "test-payload")
|
||||
# Since the mid event was already set, we should not see any timeout warning in the log
|
||||
with patch.object(mqtt_client_mock, "get_mid", return_value=100):
|
||||
# Simulate an ACK for mid == 100, this will call mqtt_mock._async_get_mid_future(mid)
|
||||
mqtt_client_mock.on_publish(mqtt_client_mock, None, 100)
|
||||
await hass.async_block_till_done()
|
||||
# Make sure the ACK has been received
|
||||
await hass.async_block_till_done()
|
||||
# Now call publish without call back, this will call _async_async_wait_for_mid(msg_info.mid)
|
||||
await mqtt.async_publish(hass, "no_callback/test-topic", "test-payload")
|
||||
# Since the mid event was already set, we should not see any timeout warning in the log
|
||||
await hass.async_block_till_done()
|
||||
assert "No ACK from MQTT server" not in caplog.text
|
||||
|
||||
|
||||
async def test_handle_mqtt_on_callback_after_timeout(
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
) -> None:
|
||||
"""Test receiving an ACK after a timeout."""
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
# Simulate the mid future getting a timeout
|
||||
mqtt_mock()._async_get_mid_future(100).set_exception(asyncio.TimeoutError)
|
||||
# Simulate an ACK for mid == 100, being received after the timeout
|
||||
mqtt_client_mock.on_publish(mqtt_client_mock, None, 100)
|
||||
await hass.async_block_till_done()
|
||||
assert "No ACK from MQTT server" not in caplog.text
|
||||
assert "InvalidStateError" not in caplog.text
|
||||
|
||||
|
||||
async def test_publish_error(
|
||||
|
Reference in New Issue
Block a user