Skip to content

Commit bc1fe01

Browse files
committed
Tweak slow TC device indication/ZDO announce unit test
1 parent 2df388d commit bc1fe01

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tests/application/test_joining.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import contextlib
3+
from unittest import mock
34

45
import pytest
56
import zigpy.util
@@ -272,6 +273,7 @@ async def test_on_zdo_device_join_and_announce_fast(device, make_application, mo
272273
await app.shutdown()
273274

274275

276+
@mock.patch("zigpy_znp.zigbee.application.DEVICE_JOIN_MAX_DELAY", new=0.1)
275277
@pytest.mark.parametrize("device", FORMED_DEVICES)
276278
async def test_on_zdo_device_join_and_announce_slow(device, make_application, mocker):
277279
app, znp_server = make_application(server_cls=device)
@@ -283,7 +285,6 @@ async def test_on_zdo_device_join_and_announce_slow(device, make_application, mo
283285
)
284286

285287
mocker.patch.object(app, "handle_join", wraps=app.handle_join)
286-
mocker.patch("zigpy_znp.zigbee.application.DEVICE_JOIN_MAX_DELAY", new=0.1)
287288

288289
nwk = 0x1234
289290
ieee = t.EUI64.convert("11:22:33:44:55:66:77:88")
@@ -295,11 +296,13 @@ async def test_on_zdo_device_join_and_announce_slow(device, make_application, mo
295296
# We're waiting for the device to announce itself
296297
assert app.handle_join.call_count == 0
297298

298-
await asyncio.sleep(0.3)
299+
# Wait for the trust center join timeout to elapse
300+
while app.handle_join.call_count == 0:
301+
await asyncio.sleep(0.1)
299302

300-
# Too late, it already happened
301303
app.handle_join.assert_called_once_with(nwk=nwk, ieee=ieee, parent_nwk=0x0001)
302304

305+
# Finally, send the device announcement
303306
znp_server.send(
304307
c.ZDO.MsgCbIncoming.Callback(
305308
Src=nwk,
@@ -327,9 +330,10 @@ async def test_on_zdo_device_join_and_announce_slow(device, make_application, mo
327330
)
328331
)
329332

330-
await asyncio.sleep(0.1)
333+
await asyncio.sleep(0.5)
331334

332335
# The announcement will trigger another join indication
333336
assert app.handle_join.call_count == 2
334337

338+
app.get_device(ieee=ieee).cancel_initialization()
335339
await app.shutdown()

0 commit comments

Comments
 (0)