Skip to content

Commit

Permalink
missing looptime and test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulcahey committed Mar 31, 2024
1 parent f8ddfe0 commit 10099e7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def _update_last_seen(*args, **kwargs): # pylint: disable=unused-argument
assert basic_ch.read_attributes.await_count == 2
assert basic_ch.read_attributes.await_args[0][0] == ["manufacturer"]
assert zha_device.available is True
assert zha_device.on_network is True


@patch(
Expand Down
29 changes: 29 additions & 0 deletions tests/test_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ async def test_device_left(
zha_gateway.device_left(zigpy_dev_basic)
await zha_gateway.async_block_till_done()
assert zha_dev_basic.available is False
assert zha_dev_basic.on_network is False


async def test_gateway_group_methods(
Expand Down Expand Up @@ -390,6 +391,7 @@ async def test_gateway_force_multi_pan_channel(


@pytest.mark.parametrize("radio_concurrency", [1, 2, 8])
@pytest.mark.looptime
async def test_startup_concurrency_limit(
radio_concurrency: int,
zigpy_app_controller: ControllerApplication,
Expand Down Expand Up @@ -567,3 +569,30 @@ def test_gateway_raw_device_initialized(
event="raw_device_initialized",
),
)


@pytest.mark.looptime
async def test_pollers_skip(
zha_gateway: Gateway,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test pollers skip when they should."""

assert "Global updater interval skipped" not in caplog.text
assert "Device availability checker interval skipped" not in caplog.text

assert zha_gateway.config.allow_polling is True
zha_gateway.config.allow_polling = False
assert zha_gateway.config.allow_polling is False

sleep_time = max(
zha_gateway.global_updater.__polling_interval,
zha_gateway._device_availability_checker.__polling_interval,
)
sleep_time += 2

await asyncio.sleep(sleep_time)
await zha_gateway.async_block_till_done(wait_background_tasks=True)

assert "Global updater interval skipped" in caplog.text
assert "Device availability checker interval skipped" in caplog.text
10 changes: 5 additions & 5 deletions zha/application/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ async def update_listeners(self):
_LOGGER.debug("Global updater running update callback")
listener()
else:
_LOGGER.debug("Global updater pass skipped")
_LOGGER.debug("Global updater interval skipped")
_LOGGER.debug("Global updater interval finished")


Expand Down Expand Up @@ -378,9 +378,9 @@ def stop(self):
@periodic(_REFRESH_INTERVAL)
async def check_device_availability(self):
"""Check device availability."""
_LOGGER.debug("Global updater device availability checker starting")
_LOGGER.debug("Device availability checker interval starting")
if self._gateway.config.allow_polling:
_LOGGER.debug("Global updater checking device availability")
_LOGGER.debug("Checking device availability")
# 20 because most devices will not make remote calls
await gather_with_limited_concurrency(
20,
Expand All @@ -390,6 +390,6 @@ async def check_device_availability(self):
if not dev.is_coordinator
),
)
_LOGGER.debug("Global updater device availability checker finished")
_LOGGER.debug("Device availability checker interval finished")
else:
_LOGGER.debug("Global updater device availability checker skipped")
_LOGGER.debug("Device availability checker interval skipped")

0 comments on commit 10099e7

Please sign in to comment.