Skip to content

Commit 479b23a

Browse files
committed
Improve wait for end of update task in TestSubscription
1 parent 77af1f5 commit 479b23a

File tree

1 file changed

+12
-3
lines changed
  • src/controller/python/test/test_scripts

1 file changed

+12
-3
lines changed

src/controller/python/test/test_scripts/base.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -1284,9 +1284,18 @@ async def _conductAttributeChange(devCtrl: ChipDeviceCtrl.ChipDeviceController,
12841284
"Failed to receive subscription update")
12851285
break
12861286

1287-
# thread changes 5 times, and sleeps for 3 seconds in between.
1288-
# Add an additional 3 seconds of slack. Timeout is in seconds.
1289-
await asyncio.wait_for(taskAttributeChange, 3)
1287+
# At this point the task should really have done the three attribute,
1288+
# otherwise something is wrong. Wait for just 1s in case of a race
1289+
# condition between the last attribute update and the callback.
1290+
try:
1291+
await asyncio.wait_for(taskAttributeChange, 1)
1292+
except asyncio.TimeoutError:
1293+
# If attribute change task did not finish something is wrong. Cancel
1294+
# the task.
1295+
taskAttributeChange.cancel()
1296+
# This will throw a asyncio.CancelledError and makes sure the test
1297+
# is declared failed.
1298+
await taskAttributeChange
12901299

12911300
return True if receivedUpdate == 5 else False
12921301

0 commit comments

Comments
 (0)