Fix homekit_controller test race (#110917)

pull/110651/head
J. Nick Koston 2024-02-19 02:42:17 -06:00 committed by GitHub
parent 88f72009c6
commit 19cf80d5c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 0 deletions

View File

@ -1067,6 +1067,7 @@ async def test_mdns_update_to_paired_during_pairing(
"source": config_entries.SOURCE_ZEROCONF, "source": config_entries.SOURCE_ZEROCONF,
} }
finish_pairing_started = asyncio.Event()
mdns_update_to_paired = asyncio.Event() mdns_update_to_paired = asyncio.Event()
original_async_start_pairing = device.async_start_pairing 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) finish_pairing = await original_async_start_pairing(*args, **kwargs)
async def _finish_pairing(*args, **kwargs): async def _finish_pairing(*args, **kwargs):
finish_pairing_started.set()
# Insert an event wait to make sure # Insert an event wait to make sure
# we trigger the mdns update in the middle of the pairing # we trigger the mdns update in the middle of the pairing
await mdns_update_to_paired.wait() 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"} 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 # Make sure when the device is discovered as paired via mdns
# it does not abort pairing if it happens before pairing is finished # it does not abort pairing if it happens before pairing is finished
result2 = await hass.config_entries.flow.async_init( result2 = await hass.config_entries.flow.async_init(