Limit worker pool to 10 threads (#3560)

* Limit worker pool to 10 threads

* Comment evdev in requirements

* Allow skipping RFXtrx tests locally

* Fix worker pool size tests

* lol whut
This commit is contained in:
Paulus Schoutsen 2016-09-28 00:05:38 -07:00 committed by GitHub
parent a084232cf5
commit 4b8bc90d16
15 changed files with 41 additions and 5 deletions

View file

@ -118,7 +118,8 @@ def _setup_component(hass: core.HomeAssistant, domain: str, config) -> bool:
# Assumption: if a component does not depend on groups
# it communicates with devices
if 'group' not in getattr(component, 'DEPENDENCIES', []):
if 'group' not in getattr(component, 'DEPENDENCIES', []) and \
hass.pool.worker_count <= 10:
hass.pool.add_worker()
hass.bus.fire(

View file

@ -6,7 +6,6 @@ https://home-assistant.io/components/switch.rfxtrx/
"""
import logging
import homeassistant.components.rfxtrx as rfxtrx
from homeassistant.components.switch import SwitchDevice

View file

@ -81,7 +81,7 @@ eliqonline==1.0.12
enocean==0.31
# homeassistant.components.keyboard_remote
evdev==0.6.1
# evdev==0.6.1
# homeassistant.components.climate.honeywell
# homeassistant.components.thermostat.honeywell

View file

@ -16,6 +16,7 @@ COMMENT_REQUIREMENTS = (
'python-lirc',
'gattlib',
'pyuserinput',
'evdev',
)
IGNORE_PACKAGES = (

View file

@ -38,6 +38,7 @@ class TestUVCSetup(unittest.TestCase):
return {'model': 'UVC'}
hass = mock.MagicMock()
hass.pool.worker_count = 2
hass.config.components = ['http']
mock_remote.return_value.index.return_value = fake_cameras
mock_remote.return_value.get_camera.side_effect = fake_get_camera
@ -65,6 +66,7 @@ class TestUVCSetup(unittest.TestCase):
{'uuid': 'two', 'name': 'Back', 'id': 'id2'},
]
hass = mock.MagicMock()
hass.pool.worker_count = 2
hass.config.components = ['http']
mock_remote.return_value.index.return_value = fake_cameras
mock_remote.return_value.get_camera.return_value = {'model': 'UVC'}
@ -92,6 +94,7 @@ class TestUVCSetup(unittest.TestCase):
{'uuid': 'two', 'name': 'Back', 'id': 'id2'},
]
hass = mock.MagicMock()
hass.pool.worker_count = 2
hass.config.components = ['http']
mock_remote.return_value.index.return_value = fake_cameras
mock_remote.return_value.get_camera.return_value = {'model': 'UVC'}
@ -109,6 +112,7 @@ class TestUVCSetup(unittest.TestCase):
def test_setup_incomplete_config(self, mock_uvc):
""""Test the setup with incomplete configuration."""
hass = mock.MagicMock()
hass.pool.worker_count = 2
hass.config.components = ['http']
assert setup_component(
@ -133,6 +137,7 @@ class TestUVCSetup(unittest.TestCase):
'key': 'secret',
}
hass = mock.MagicMock()
hass.pool.worker_count = 2
hass.config.components = ['http']
for error in errors:

View file

@ -1,12 +1,15 @@
"""The tests for the Rfxtrx cover platform."""
import unittest
import pytest
from homeassistant.bootstrap import _setup_component
from homeassistant.components import rfxtrx as rfxtrx_core
from tests.common import get_test_home_assistant
@pytest.mark.skipif("os.environ.get('RFXTRX') == 'SKIP'")
class TestCoverRfxtrx(unittest.TestCase):
"""Test the Rfxtrx cover platform."""

View file

@ -1,12 +1,15 @@
"""The tests for the Rfxtrx light platform."""
import unittest
import pytest
from homeassistant.bootstrap import _setup_component
from homeassistant.components import rfxtrx as rfxtrx_core
from tests.common import get_test_home_assistant
@pytest.mark.skipif("os.environ.get('RFXTRX') == 'SKIP'")
class TestLightRfxtrx(unittest.TestCase):
"""Test the Rfxtrx light platform."""

View file

@ -1,12 +1,15 @@
"""The tests for the Rfxtrx roller shutter platform."""
import unittest
import pytest
from homeassistant.bootstrap import _setup_component
from homeassistant.components import rfxtrx as rfxtrx_core
from tests.common import get_test_home_assistant
@pytest.mark.skipif("os.environ.get('RFXTRX') == 'SKIP'")
class TestRollershutterRfxtrx(unittest.TestCase):
"""Test the Rfxtrx roller shutter platform."""

View file

@ -1,6 +1,8 @@
"""The tests for the Rfxtrx sensor platform."""
import unittest
import pytest
from homeassistant.bootstrap import _setup_component
from homeassistant.components import rfxtrx as rfxtrx_core
from homeassistant.const import TEMP_CELSIUS
@ -8,6 +10,7 @@ from homeassistant.const import TEMP_CELSIUS
from tests.common import get_test_home_assistant
@pytest.mark.skipif("os.environ.get('RFXTRX') == 'SKIP'")
class TestSensorRfxtrx(unittest.TestCase):
"""Test the Rfxtrx sensor platform."""

View file

@ -1,12 +1,15 @@
"""The tests for the Rfxtrx switch platform."""
import unittest
import pytest
from homeassistant.bootstrap import _setup_component
from homeassistant.components import rfxtrx as rfxtrx_core
from tests.common import get_test_home_assistant
@pytest.mark.skipif("os.environ.get('RFXTRX') == 'SKIP'")
class TestSwitchRfxtrx(unittest.TestCase):
"""Test the Rfxtrx switch platform."""

View file

@ -17,6 +17,7 @@ class TestInfluxDB(unittest.TestCase):
def setUp(self):
"""Setup things to be run when tests are started."""
self.hass = mock.MagicMock()
self.hass.pool.worker_count = 2
self.handler_method = None
def test_setup_config_full(self, mock_client):

View file

@ -19,6 +19,7 @@ class TestLogentries(unittest.TestCase):
}
}
hass = mock.MagicMock()
hass.pool.worker_count = 2
self.assertTrue(setup_component(hass, logentries.DOMAIN, config))
self.assertTrue(hass.bus.listen.called)
self.assertEqual(EVENT_STATE_CHANGED,
@ -32,6 +33,7 @@ class TestLogentries(unittest.TestCase):
}
}
hass = mock.MagicMock()
hass.pool.worker_count = 2
self.assertTrue(setup_component(hass, logentries.DOMAIN, config))
self.assertTrue(hass.bus.listen.called)
self.assertEqual(EVENT_STATE_CHANGED,
@ -48,6 +50,7 @@ class TestLogentries(unittest.TestCase):
}
}
self.hass = mock.MagicMock()
self.hass.pool.worker_count = 2
setup_component(self.hass, logentries.DOMAIN, config)
self.handler_method = self.hass.bus.listen.call_args_list[0][0][1]

View file

@ -24,7 +24,9 @@ class TestUpdater(unittest.TestCase):
def test_logger_setup(self):
"""Use logger to create a logging filter."""
setup_component(MagicMock(), logger.DOMAIN, self.log_config)
hass = MagicMock()
hass.pool.worker_count = 2
setup_component(hass, logger.DOMAIN, self.log_config)
self.assertTrue(len(logging.root.handlers) > 0)
handler = logging.root.handlers[-1]
@ -37,7 +39,9 @@ class TestUpdater(unittest.TestCase):
def test_logger_test_filters(self):
"""Test resulting filter operation."""
setup_component(MagicMock(), logger.DOMAIN, self.log_config)
hass = MagicMock()
hass.pool.worker_count = 2
setup_component(hass, logger.DOMAIN, self.log_config)
log_filter = logging.root.handlers[-1].filters[0]

View file

@ -22,6 +22,7 @@ class TestSplunk(unittest.TestCase):
}
hass = mock.MagicMock()
hass.pool.worker_count = 2
self.assertTrue(setup_component(hass, splunk.DOMAIN, config))
self.assertTrue(hass.bus.listen.called)
self.assertEqual(EVENT_STATE_CHANGED,
@ -37,6 +38,7 @@ class TestSplunk(unittest.TestCase):
}
hass = mock.MagicMock()
hass.pool.worker_count = 2
self.assertTrue(setup_component(hass, splunk.DOMAIN, config))
self.assertTrue(hass.bus.listen.called)
self.assertEqual(EVENT_STATE_CHANGED,
@ -56,6 +58,7 @@ class TestSplunk(unittest.TestCase):
}
self.hass = mock.MagicMock()
self.hass.pool.worker_count = 2
setup_component(self.hass, splunk.DOMAIN, config)
self.handler_method = self.hass.bus.listen.call_args_list[0][0][1]

View file

@ -38,6 +38,7 @@ class TestStatsd(unittest.TestCase):
}
}
hass = mock.MagicMock()
hass.pool.worker_count = 2
self.assertTrue(setup_component(hass, statsd.DOMAIN, config))
mock_connection.assert_called_once_with(
host='host',
@ -61,6 +62,7 @@ class TestStatsd(unittest.TestCase):
config['statsd'][statsd.CONF_PREFIX] = statsd.DEFAULT_PREFIX
hass = mock.MagicMock()
hass.pool.worker_count = 2
self.assertTrue(setup_component(hass, statsd.DOMAIN, config))
mock_connection.assert_called_once_with(
host='host',
@ -80,6 +82,7 @@ class TestStatsd(unittest.TestCase):
config['statsd'][statsd.CONF_RATE] = statsd.DEFAULT_RATE
hass = mock.MagicMock()
hass.pool.worker_count = 2
setup_component(hass, statsd.DOMAIN, config)
self.assertTrue(hass.bus.listen.called)
handler_method = hass.bus.listen.call_args_list[0][0][1]
@ -121,6 +124,7 @@ class TestStatsd(unittest.TestCase):
config['statsd'][statsd.CONF_RATE] = statsd.DEFAULT_RATE
hass = mock.MagicMock()
hass.pool.worker_count = 2
setup_component(hass, statsd.DOMAIN, config)
self.assertTrue(hass.bus.listen.called)
handler_method = hass.bus.listen.call_args_list[0][0][1]