mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Fix test shutdown to ensure loop/threads are clean. (#3447)
* Fix test shutdown to ensure loop/threads are clean. We now ensure the loop is closed, it has completed, and the executer has completed. This ensure all threads are freed up with any test calling hass.stop(). * Fix lint issue with run_loop
This commit is contained in:
parent
8a99ce78c2
commit
256062fd99
@ -273,6 +273,7 @@ class HomeAssistant(object):
|
|||||||
self.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
self.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
yield from self.loop.run_in_executor(None, self.pool.block_till_done)
|
yield from self.loop.run_in_executor(None, self.pool.block_till_done)
|
||||||
yield from self.loop.run_in_executor(None, self.pool.stop)
|
yield from self.loop.run_in_executor(None, self.pool.stop)
|
||||||
|
self.executer.shutdown()
|
||||||
self.state = CoreState.not_running
|
self.state = CoreState.not_running
|
||||||
self.loop.stop()
|
self.loop.stop()
|
||||||
|
|
||||||
|
@ -55,10 +55,17 @@ def get_test_home_assistant(num_threads=None):
|
|||||||
loader.prepare(hass)
|
loader.prepare(hass)
|
||||||
|
|
||||||
# FIXME should not be a daemon. Means hass.stop() not called in teardown
|
# FIXME should not be a daemon. Means hass.stop() not called in teardown
|
||||||
threading.Thread(name="LoopThread", target=loop.run_forever,
|
stop_event = threading.Event()
|
||||||
daemon=True).start()
|
|
||||||
|
def run_loop():
|
||||||
|
loop.run_forever()
|
||||||
|
loop.close()
|
||||||
|
stop_event.set()
|
||||||
|
|
||||||
|
threading.Thread(name="LoopThread", target=run_loop, daemon=True).start()
|
||||||
|
|
||||||
orig_start = hass.start
|
orig_start = hass.start
|
||||||
|
orig_stop = hass.stop
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def fake_stop():
|
def fake_stop():
|
||||||
@ -72,7 +79,12 @@ def get_test_home_assistant(num_threads=None):
|
|||||||
orig_start()
|
orig_start()
|
||||||
hass.block_till_done()
|
hass.block_till_done()
|
||||||
|
|
||||||
|
def stop_hass():
|
||||||
|
orig_stop()
|
||||||
|
stop_event.wait()
|
||||||
|
|
||||||
hass.start = start_hass
|
hass.start = start_hass
|
||||||
|
hass.stop = stop_hass
|
||||||
|
|
||||||
return hass
|
return hass
|
||||||
|
|
||||||
|
@ -29,6 +29,9 @@ class TestBootstrap:
|
|||||||
|
|
||||||
def teardown_method(self, method):
|
def teardown_method(self, method):
|
||||||
"""Clean up."""
|
"""Clean up."""
|
||||||
|
if method == self.test_from_config_file:
|
||||||
|
return
|
||||||
|
|
||||||
dt_util.DEFAULT_TIME_ZONE = ORIG_TIMEZONE
|
dt_util.DEFAULT_TIME_ZONE = ORIG_TIMEZONE
|
||||||
self.hass.stop()
|
self.hass.stop()
|
||||||
loader._COMPONENT_CACHE = self.backup_cache
|
loader._COMPONENT_CACHE = self.backup_cache
|
||||||
|
Loading…
x
Reference in New Issue
Block a user