Remove ThreadPool with async executor (#4154)

* Remove ThreadPool with async executor

* Fix zigbee

* update unittest

* fix remote api

* add pending task to remote

* fix lint

* remove unused import

* remove old stuff for lazy tests

* fix bug and add a exception handler to executor

* change executor handling

* change to wait from gather

* fix unittest
This commit is contained in:
Pascal Vizeli 2016-11-05 17:27:55 +01:00 committed by Paulus Schoutsen
parent b67f1fed52
commit ece58ce78f
10 changed files with 37 additions and 346 deletions

View file

@ -56,7 +56,7 @@ def test_async_add_job_add_threaded_job_to_pool(mock_iscoro):
ha.HomeAssistant.async_add_job(hass, job)
assert len(hass.loop.call_soon.mock_calls) == 0
assert len(hass.loop.create_task.mock_calls) == 0
assert len(hass.pool.add_job.mock_calls) == 1
assert len(hass.loop.run_in_executor.mock_calls) == 1
def test_async_run_job_calls_callback():
@ -195,7 +195,6 @@ class TestEventBus(unittest.TestCase):
def test_unsubscribe_listener(self):
"""Test unsubscribe listener from returned function."""
self.hass.allow_pool = False
calls = []
@ha.callback
@ -219,7 +218,6 @@ class TestEventBus(unittest.TestCase):
def test_listen_once_event_with_callback(self):
"""Test listen_once_event method."""
self.hass.allow_pool = False
runs = []
@ha.callback
@ -237,7 +235,6 @@ class TestEventBus(unittest.TestCase):
def test_listen_once_event_with_coroutine(self):
"""Test listen_once_event method."""
self.hass.allow_pool = False
runs = []
@asyncio.coroutine
@ -283,7 +280,6 @@ class TestEventBus(unittest.TestCase):
def test_callback_event_listener(self):
"""Test a event listener listeners."""
self.hass.allow_pool = False
callback_calls = []
@ha.callback
@ -297,7 +293,6 @@ class TestEventBus(unittest.TestCase):
def test_coroutine_event_listener(self):
"""Test a event listener listeners."""
self.hass.allow_pool = False
coroutine_calls = []
@asyncio.coroutine
@ -376,7 +371,6 @@ class TestStateMachine(unittest.TestCase):
self.states = self.hass.states
self.states.set("light.Bowl", "on")
self.states.set("switch.AC", "off")
self.hass.allow_pool = False
# pylint: disable=invalid-name
def tearDown(self):
@ -523,7 +517,6 @@ class TestServiceRegistry(unittest.TestCase):
def test_has_service(self):
"""Test has_service method."""
self.hass.allow_pool = False
self.assertTrue(
self.services.has_service("tesT_domaiN", "tesT_servicE"))
self.assertFalse(
@ -533,7 +526,6 @@ class TestServiceRegistry(unittest.TestCase):
def test_services(self):
"""Test services."""
self.hass.allow_pool = False
expected = {
'test_domain': {'test_service': {'description': '', 'fields': {}}}
}
@ -556,7 +548,6 @@ class TestServiceRegistry(unittest.TestCase):
def test_call_non_existing_with_blocking(self):
"""Test non-existing with blocking."""
self.hass.allow_pool = False
prior = ha.SERVICE_CALL_LIMIT
try:
ha.SERVICE_CALL_LIMIT = 0.01
@ -567,7 +558,6 @@ class TestServiceRegistry(unittest.TestCase):
def test_async_service(self):
"""Test registering and calling an async service."""
self.hass.allow_pool = False
calls = []
@asyncio.coroutine
@ -584,7 +574,6 @@ class TestServiceRegistry(unittest.TestCase):
def test_callback_service(self):
"""Test registering and calling an async service."""
self.hass.allow_pool = False
calls = []
@ha.callback
@ -638,72 +627,6 @@ class TestConfig(unittest.TestCase):
self.assertEqual(expected, self.config.as_dict())
class TestWorkerPool(unittest.TestCase):
"""Test WorkerPool methods."""
def test_exception_during_job(self):
"""Test exception during a job."""
pool = ha.create_worker_pool(1)
def malicious_job(_):
raise Exception("Test breaking worker pool")
calls = []
def register_call(_):
calls.append(1)
pool.add_job((malicious_job, None))
pool.block_till_done()
pool.add_job((register_call, None))
pool.block_till_done()
self.assertEqual(1, len(calls))
class TestWorkerPoolMonitor(object):
"""Test monitor_worker_pool."""
@patch('homeassistant.core._LOGGER.warning')
def test_worker_pool_monitor(self, mock_warning, event_loop):
"""Test we log an error and increase threshold."""
hass = MagicMock()
hass.pool.worker_count = 3
schedule_handle = MagicMock()
hass.loop.call_later.return_value = schedule_handle
ha._async_monitor_worker_pool(hass)
assert hass.loop.call_later.called
assert hass.bus.async_listen_once.called
assert not schedule_handle.called
check_threshold = hass.loop.call_later.mock_calls[0][1][1]
hass.pool.queue_size = 8
check_threshold()
assert not mock_warning.called
hass.pool.queue_size = 9
check_threshold()
assert mock_warning.called
mock_warning.reset_mock()
assert not mock_warning.called
check_threshold()
assert not mock_warning.called
hass.pool.queue_size = 17
check_threshold()
assert not mock_warning.called
hass.pool.queue_size = 18
check_threshold()
assert mock_warning.called
hass.bus.async_listen_once.mock_calls[0][1][1](None)
assert schedule_handle.cancel.called
class TestAsyncCreateTimer(object):
"""Test create timer."""