diff --git a/src/python_testing/TC_DEM_2_10.py b/src/python_testing/TC_DEM_2_10.py index 81e1ca83cb18a8..17d5e192709ec6 100644 --- a/src/python_testing/TC_DEM_2_10.py +++ b/src/python_testing/TC_DEM_2_10.py @@ -150,7 +150,7 @@ async def test_TC_DEM_2_10(self): asserts.assert_less_equal(count, 10, "More than 10 reports received") self.step("9") - sub_handler.cancel() + await sub_handler.cancel() self.step("10") await self.send_test_event_trigger_forecast_adjustment_clear() diff --git a/src/python_testing/matter_testing_support.py b/src/python_testing/matter_testing_support.py index e4bbdac56ddf92..d39c499eb296a8 100644 --- a/src/python_testing/matter_testing_support.py +++ b/src/python_testing/matter_testing_support.py @@ -422,10 +422,15 @@ async def start(self, dev_ctrl, node_id: int, endpoint: int, fabric_filtered: bo self._subscription.SetAttributeUpdateCallback(self.__call__) return self._subscription - def cancel(self): + async def cancel(self): """This cancels a subscription.""" - self._subscription.Shutdown() - self._subscription = None + # Wait for the asyncio.CancelledError to be called before returning + try: + self._subscription.Shutdown() + await asyncio.sleep(5) + except asyncio.CancelledError: + pass + def __call__(self, path: TypedAttributePath, transaction: SubscriptionTransaction): """This is the subscription callback when an attribute report is received.