Use eager_start for background service call tasks (#111620)

This commit is contained in:
J. Nick Koston 2024-02-27 12:06:32 -10:00 committed by GitHub
parent c8b7f098e5
commit c4d719a7cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 6 deletions

View File

@ -2293,6 +2293,7 @@ class ServiceRegistry:
self._hass.async_create_task( self._hass.async_create_task(
self._run_service_call_catch_exceptions(coro, service_call), self._run_service_call_catch_exceptions(coro, service_call),
f"service call background {service_call.domain}.{service_call.service}", f"service call background {service_call.domain}.{service_call.service}",
eager_start=True,
) )
return None return None

View File

@ -1,5 +1,4 @@
"""Tests for the Android TV Remote remote platform.""" """Tests for the Android TV Remote remote platform."""
import asyncio
from unittest.mock import MagicMock, call from unittest.mock import MagicMock, call
from androidtvremote2 import ConnectionClosed from androidtvremote2 import ConnectionClosed
@ -237,7 +236,7 @@ async def test_media_player_play_media(
) )
# Give background task time to run # Give background task time to run
await asyncio.sleep(0) await hass.async_block_till_done()
await hass.services.async_call( await hass.services.async_call(
"media_player", "media_player",
@ -249,7 +248,11 @@ async def test_media_player_play_media(
}, },
blocking=True, blocking=True,
) )
assert mock_api.send_key_command.call_count == 2 await hass.async_block_till_done()
# 4 7s should be sent
# 2 1s should be sent
assert mock_api.send_key_command.call_count == 6
await hass.services.async_call( await hass.services.async_call(
"media_player", "media_player",

View File

@ -615,6 +615,7 @@ async def test_service_calls(
# check backup with different timezone # check backup with different timezone
await hass.config.async_update(time_zone="Europe/London") await hass.config.async_update(time_zone="Europe/London")
await hass.async_block_till_done()
await hass.services.async_call( await hass.services.async_call(
"hassio", "hassio",

View File

@ -4,7 +4,6 @@ Test setup of RFLink lights component/platform. State tracking and
control of RFLink switch devices. control of RFLink switch devices.
""" """
import asyncio
from homeassistant.components.light import ATTR_BRIGHTNESS from homeassistant.components.light import ATTR_BRIGHTNESS
from homeassistant.components.rflink import EVENT_BUTTON_PRESSED from homeassistant.components.rflink import EVENT_BUTTON_PRESSED
@ -281,19 +280,21 @@ async def test_signal_repetitions_cancelling(hass: HomeAssistant, monkeypatch) -
# setup mocking rflink module # setup mocking rflink module
_, _, protocol, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch) _, _, protocol, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
await hass.async_block_till_done()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test"} DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
) )
await hass.async_block_till_done()
# Get background service time to start running
await asyncio.sleep(0)
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}, blocking=True DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}, blocking=True
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert [call[0][1] for call in protocol.send_command_ack.call_args_list] == [ assert [call[0][1] for call in protocol.send_command_ack.call_args_list] == [
"off",
"off",
"off", "off",
"on", "on",
"on", "on",