From 26c12705166704eae122572aa20eedb7154edd26 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 8 May 2024 22:49:47 +0200 Subject: [PATCH] Improve wait for end of update task in TestSubscription --- src/controller/python/test/test_scripts/base.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/controller/python/test/test_scripts/base.py b/src/controller/python/test/test_scripts/base.py index 1ad49174c05c66..069677421f1d17 100644 --- a/src/controller/python/test/test_scripts/base.py +++ b/src/controller/python/test/test_scripts/base.py @@ -1284,9 +1284,18 @@ async def _conductAttributeChange(devCtrl: ChipDeviceCtrl.ChipDeviceController, "Failed to receive subscription update") break - # thread changes 5 times, and sleeps for 3 seconds in between. - # Add an additional 3 seconds of slack. Timeout is in seconds. - await asyncio.wait_for(taskAttributeChange, 3) + # At this point the task should really have done the three attribute, + # otherwise something is wrong. Wait for just 1s in case of a race + # condition between the last attribute update and the callback. + try: + await asyncio.wait_for(taskAttributeChange, 1) + except asyncio.TimeoutError: + # If attribute change task did not finish something is wrong. Cancel + # the task. + taskAttributeChange.cancel() + # This will throw a asyncio.CancelledError and makes sure the test + # is declared failed. + await taskAttributeChange return True if receivedUpdate == 5 else False