Track tasks only during shutdown and tests (#4428)
* Track tasks only when needed * Tweak async_block_till_done
This commit is contained in:
1 parent
42c99b0ccb
commit
eacdce9ed9
4 files changed
+42
-48
No files matched your search
+4
-10
@@ -9,8 +9,7 @@ import pytz
|
||||
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.exceptions import InvalidEntityFormatError
|
||||
from homeassistant.util.async import (
|
||||
run_callback_threadsafe, run_coroutine_threadsafe)
|
||||
from homeassistant.util.async import run_coroutine_threadsafe
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.util.unit_system import (METRIC_SYSTEM)
|
||||
from homeassistant.const import (
|
||||
@@ -129,7 +128,7 @@ class TestHomeAssistant(unittest.TestCase):
|
||||
"""Test Coro."""
|
||||
call_count.append('call')
|
||||
|
||||
for i in range(50):
|
||||
for i in range(3):
|
||||
self.hass.add_job(test_coro())
|
||||
|
||||
run_coroutine_threadsafe(
|
||||
@@ -137,13 +136,8 @@ class TestHomeAssistant(unittest.TestCase):
|
||||
loop=self.hass.loop
|
||||
).result()
|
||||
|
||||
with patch.object(self.hass.loop, 'call_later') as mock_later:
|
||||
run_callback_threadsafe(
|
||||
self.hass.loop, self.hass._async_tasks_cleanup).result()
|
||||
assert mock_later.called
|
||||
|
||||
assert len(self.hass._pending_tasks) == 0
|
||||
assert len(call_count) == 50
|
||||
assert len(self.hass._pending_tasks) == 3
|
||||
assert len(call_count) == 3
|
||||
|
||||
def test_async_add_job_pending_tasks_coro(self):
|
||||
"""Add a coro to pending tasks."""
|
||||
|
||||
Reference in new issue
Block a user