mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Create tasks eagerly with core create_task (#113781)
This commit is contained in:
parent
85e13bdb87
commit
2582172ad1
@ -701,7 +701,9 @@ class HomeAssistant:
|
|||||||
|
|
||||||
target: target to call.
|
target: target to call.
|
||||||
"""
|
"""
|
||||||
self.loop.call_soon_threadsafe(self.async_create_task, target, name)
|
self.loop.call_soon_threadsafe(
|
||||||
|
functools.partial(self.async_create_task, target, name, eager_start=True)
|
||||||
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_create_task(
|
def async_create_task(
|
||||||
|
@ -297,6 +297,9 @@ async def test_stream_retries(
|
|||||||
|
|
||||||
stream.set_update_callback(update_callback)
|
stream.set_update_callback(update_callback)
|
||||||
|
|
||||||
|
open_future1 = hass.loop.create_future()
|
||||||
|
open_future2 = hass.loop.create_future()
|
||||||
|
futures = [open_future2, open_future1]
|
||||||
cur_time = 0
|
cur_time = 0
|
||||||
|
|
||||||
def time_side_effect():
|
def time_side_effect():
|
||||||
@ -308,18 +311,22 @@ async def test_stream_retries(
|
|||||||
cur_time += 40
|
cur_time += 40
|
||||||
return cur_time
|
return cur_time
|
||||||
|
|
||||||
|
def av_open_side_effect(*args, **kwargs):
|
||||||
|
hass.loop.call_soon_threadsafe(futures.pop().set_result, None)
|
||||||
|
raise av.error.InvalidDataError(-2, "error")
|
||||||
|
|
||||||
with patch("av.open") as av_open, patch(
|
with patch("av.open") as av_open, patch(
|
||||||
"homeassistant.components.stream.time"
|
"homeassistant.components.stream.time"
|
||||||
) as mock_time, patch(
|
) as mock_time, patch(
|
||||||
"homeassistant.components.stream.STREAM_RESTART_INCREMENT", 0
|
"homeassistant.components.stream.STREAM_RESTART_INCREMENT", 0
|
||||||
):
|
):
|
||||||
av_open.side_effect = av.error.InvalidDataError(-2, "error")
|
av_open.side_effect = av_open_side_effect
|
||||||
mock_time.time.side_effect = time_side_effect
|
mock_time.time.side_effect = time_side_effect
|
||||||
# Request stream. Enable retries which are disabled by default in tests.
|
# Request stream. Enable retries which are disabled by default in tests.
|
||||||
should_retry.return_value = True
|
should_retry.return_value = True
|
||||||
await stream.start()
|
await stream.start()
|
||||||
stream._thread.join()
|
await open_future1
|
||||||
stream._thread = None
|
await open_future2
|
||||||
assert av_open.call_count == 2
|
assert av_open.call_count == 2
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
@ -237,6 +237,7 @@ async def test_record_stream_audio(
|
|||||||
# Fire the IdleTimer
|
# Fire the IdleTimer
|
||||||
future = dt_util.utcnow() + timedelta(seconds=30)
|
future = dt_util.utcnow() + timedelta(seconds=30)
|
||||||
async_fire_time_changed(hass, future)
|
async_fire_time_changed(hass, future)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
await make_recording
|
await make_recording
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user