mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 10:17:51 +00:00
Ensure we properly close HASS instances. (#6234)
This commit is contained in:
parent
7b3b755aaf
commit
86d4d10176
@ -23,7 +23,7 @@ import homeassistant.util.yaml as yaml
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_ON, STATE_OFF, DEVICE_DEFAULT_NAME, EVENT_TIME_CHANGED,
|
STATE_ON, STATE_OFF, DEVICE_DEFAULT_NAME, EVENT_TIME_CHANGED,
|
||||||
EVENT_STATE_CHANGED, EVENT_PLATFORM_DISCOVERED, ATTR_SERVICE,
|
EVENT_STATE_CHANGED, EVENT_PLATFORM_DISCOVERED, ATTR_SERVICE,
|
||||||
ATTR_DISCOVERED, SERVER_PORT)
|
ATTR_DISCOVERED, SERVER_PORT, EVENT_HOMEASSISTANT_STOP)
|
||||||
from homeassistant.components import sun, mqtt, recorder
|
from homeassistant.components import sun, mqtt, recorder
|
||||||
from homeassistant.components.http.auth import auth_middleware
|
from homeassistant.components.http.auth import auth_middleware
|
||||||
from homeassistant.components.http.const import (
|
from homeassistant.components.http.const import (
|
||||||
@ -32,6 +32,7 @@ from homeassistant.util.async import run_callback_threadsafe
|
|||||||
|
|
||||||
_TEST_INSTANCE_PORT = SERVER_PORT
|
_TEST_INSTANCE_PORT = SERVER_PORT
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
INST_COUNT = 0
|
||||||
|
|
||||||
|
|
||||||
def get_test_config_dir(*add_path):
|
def get_test_config_dir(*add_path):
|
||||||
@ -85,6 +86,8 @@ def get_test_home_assistant():
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_test_home_assistant(loop):
|
def async_test_home_assistant(loop):
|
||||||
"""Return a Home Assistant object pointing at test config dir."""
|
"""Return a Home Assistant object pointing at test config dir."""
|
||||||
|
global INST_COUNT
|
||||||
|
INST_COUNT += 1
|
||||||
loop._thread_ident = threading.get_ident()
|
loop._thread_ident = threading.get_ident()
|
||||||
|
|
||||||
hass = ha.HomeAssistant(loop)
|
hass = ha.HomeAssistant(loop)
|
||||||
@ -122,6 +125,13 @@ def async_test_home_assistant(loop):
|
|||||||
|
|
||||||
hass.async_start = mock_async_start
|
hass.async_start = mock_async_start
|
||||||
|
|
||||||
|
@ha.callback
|
||||||
|
def clear_instance(event):
|
||||||
|
global INST_COUNT
|
||||||
|
INST_COUNT -= 1
|
||||||
|
|
||||||
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, clear_instance)
|
||||||
|
|
||||||
return hass
|
return hass
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,6 +38,15 @@ location.elevation = test_real(location.elevation)
|
|||||||
util.get_local_ip = lambda: '127.0.0.1'
|
util.get_local_ip = lambda: '127.0.0.1'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def verify_cleanup():
|
||||||
|
"""Verify that the test has cleaned up resources correctly."""
|
||||||
|
yield
|
||||||
|
|
||||||
|
from tests import common
|
||||||
|
assert common.INST_COUNT < 2
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def hass(loop):
|
def hass(loop):
|
||||||
"""Fixture to provide a test instance of HASS."""
|
"""Fixture to provide a test instance of HASS."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user