From 19cf80d5c59caaffae738dc175bddf2cab0ec500 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 19 Feb 2024 02:42:17 -0600 Subject: [PATCH] Fix homekit_controller test race (#110917) --- tests/components/homekit_controller/test_config_flow.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/components/homekit_controller/test_config_flow.py b/tests/components/homekit_controller/test_config_flow.py index 8da6290d914..2b375566b5b 100644 --- a/tests/components/homekit_controller/test_config_flow.py +++ b/tests/components/homekit_controller/test_config_flow.py @@ -1067,6 +1067,7 @@ async def test_mdns_update_to_paired_during_pairing( "source": config_entries.SOURCE_ZEROCONF, } + finish_pairing_started = asyncio.Event() mdns_update_to_paired = asyncio.Event() original_async_start_pairing = device.async_start_pairing @@ -1075,6 +1076,7 @@ async def test_mdns_update_to_paired_during_pairing( finish_pairing = await original_async_start_pairing(*args, **kwargs) async def _finish_pairing(*args, **kwargs): + finish_pairing_started.set() # Insert an event wait to make sure # we trigger the mdns update in the middle of the pairing await mdns_update_to_paired.wait() @@ -1098,6 +1100,8 @@ async def test_mdns_update_to_paired_during_pairing( result["flow_id"], user_input={"pairing_code": "111-22-333"} ) ) + # Ensure the task starts + await finish_pairing_started.wait() # Make sure when the device is discovered as paired via mdns # it does not abort pairing if it happens before pairing is finished result2 = await hass.config_entries.flow.async_init(