From 323b5e4de9ff2dc59d9967726aa0bdc7a4d0bd5a Mon Sep 17 00:00:00 2001 From: TheJulianJES Date: Thu, 11 Apr 2024 18:32:46 +0200 Subject: [PATCH 1/4] Fix watchdog test --- tests/application/test_connect.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/application/test_connect.py b/tests/application/test_connect.py index 79fa9104..e19a7baa 100644 --- a/tests/application/test_connect.py +++ b/tests/application/test_connect.py @@ -203,11 +203,10 @@ async def test_disconnect_failure(device, make_application): @pytest.mark.parametrize("device", [FormedLaunchpadCC26X2R1]) async def test_watchdog(device, make_application): app, znp_server = make_application(server_cls=device) - await app.startup(auto_form=False) - app._watchdog_feed = AsyncMock(wraps=app._watchdog_feed) with patch("zigpy.application.ControllerApplication._watchdog_period", new=0.1): + await app.startup(auto_form=False) await asyncio.sleep(0.6) assert len(app._watchdog_feed.mock_calls) >= 5 From a5270d6b23e36931b55c65f78b0e3b3ef1a7b296 Mon Sep 17 00:00:00 2001 From: TheJulianJES Date: Thu, 11 Apr 2024 18:35:47 +0200 Subject: [PATCH 2/4] Use mock patch annotation for watchdog period --- tests/application/test_connect.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/application/test_connect.py b/tests/application/test_connect.py index e19a7baa..d666c1a7 100644 --- a/tests/application/test_connect.py +++ b/tests/application/test_connect.py @@ -1,4 +1,3 @@ -import asyncio from unittest.mock import AsyncMock, patch import pytest @@ -201,14 +200,12 @@ async def test_disconnect_failure(device, make_application): @pytest.mark.parametrize("device", [FormedLaunchpadCC26X2R1]) +@patch("zigpy_znp.zigbee.application.ControllerApplication._watchdog_period", new=0.1) async def test_watchdog(device, make_application): app, znp_server = make_application(server_cls=device) app._watchdog_feed = AsyncMock(wraps=app._watchdog_feed) - with patch("zigpy.application.ControllerApplication._watchdog_period", new=0.1): - await app.startup(auto_form=False) - await asyncio.sleep(0.6) - + await app.startup(auto_form=False) assert len(app._watchdog_feed.mock_calls) >= 5 await app.shutdown() From 0b5f87ca19e707aa5bd1fb41142d9e4bd20d604a Mon Sep 17 00:00:00 2001 From: TheJulianJES Date: Thu, 11 Apr 2024 20:48:44 +0200 Subject: [PATCH 3/4] Fix TSNs --- tests/application/test_joining.py | 4 ++-- tests/application/test_requests.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/application/test_joining.py b/tests/application/test_joining.py index 6db28283..1523dff0 100644 --- a/tests/application/test_joining.py +++ b/tests/application/test_joining.py @@ -40,7 +40,7 @@ async def test_permit_join(device, mocker, make_application): request=zdo_request_matcher( dst_addr=t.AddrModeAddress(t.AddrMode.Broadcast, 0xFFFC), command_id=zdo_t.ZDOCmd.Mgmt_Permit_Joining_req, - TSN=7, + TSN=2, zdo_PermitDuration=10, zdo_TC_Significant=0, ), @@ -117,7 +117,7 @@ async def test_join_device(device, make_application): IsBroadcast=t.Bool.false, ClusterId=32822, SecurityUse=0, - TSN=7, + TSN=1, MacDst=0x0000, Data=b"\x00", ), diff --git a/tests/application/test_requests.py b/tests/application/test_requests.py index 1e9ba5a7..e123a30b 100644 --- a/tests/application/test_requests.py +++ b/tests/application/test_requests.py @@ -51,7 +51,7 @@ async def test_zigpy_request(device, make_application): app, znp_server = make_application(device) await app.startup(auto_form=False) - TSN = 7 + TSN = 1 device = app.add_initialized_device(ieee=t.EUI64(range(8)), nwk=0xAABB) @@ -111,7 +111,7 @@ async def test_zigpy_request_failure(device, make_application, mocker): app, znp_server = make_application(device) await app.startup(auto_form=False) - TSN = 7 + TSN = 1 device = app.add_initialized_device(ieee=t.EUI64(range(8)), nwk=0xAABB) @@ -456,7 +456,7 @@ async def inner(): @pytest.mark.parametrize("device", [FormedLaunchpadCC26X2R1]) async def test_request_recovery_route_rediscovery_zdo(device, make_application, mocker): - TSN = 7 + TSN = 1 app, znp_server = make_application(server_cls=device) From 3051bbe64d10eea236f7e3ec6d2dfdfed60823c1 Mon Sep 17 00:00:00 2001 From: TheJulianJES Date: Thu, 11 Apr 2024 21:36:10 +0200 Subject: [PATCH 4/4] Re-add sleep to make sure watchdog loop has enough time for 5 "feeds" --- tests/application/test_connect.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/application/test_connect.py b/tests/application/test_connect.py index d666c1a7..5c6aa54b 100644 --- a/tests/application/test_connect.py +++ b/tests/application/test_connect.py @@ -1,3 +1,4 @@ +import asyncio from unittest.mock import AsyncMock, patch import pytest @@ -206,6 +207,7 @@ async def test_watchdog(device, make_application): app._watchdog_feed = AsyncMock(wraps=app._watchdog_feed) await app.startup(auto_form=False) + await asyncio.sleep(0.6) assert len(app._watchdog_feed.mock_calls) >= 5 await app.shutdown()