Skip to content

Commit 69f2ea1

Browse files
committed
Fix the cancelling of subscriptions
1 parent e95b739 commit 69f2ea1

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/python_testing/TC_DEM_2_10.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ async def test_TC_DEM_2_10(self):
150150
asserts.assert_less_equal(count, 10, "More than 10 reports received")
151151

152152
self.step("9")
153-
sub_handler.cancel()
153+
await sub_handler.cancel()
154154

155155
self.step("10")
156156
await self.send_test_event_trigger_forecast_adjustment_clear()

src/python_testing/matter_testing_support.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,15 @@ async def start(self, dev_ctrl, node_id: int, endpoint: int, fabric_filtered: bo
422422
self._subscription.SetAttributeUpdateCallback(self.__call__)
423423
return self._subscription
424424

425-
def cancel(self):
425+
async def cancel(self):
426426
"""This cancels a subscription."""
427-
self._subscription.Shutdown()
428-
self._subscription = None
427+
# Wait for the asyncio.CancelledError to be called before returning
428+
try:
429+
self._subscription.Shutdown()
430+
await asyncio.sleep(5)
431+
except asyncio.CancelledError:
432+
pass
433+
429434

430435
def __call__(self, path: TypedAttributePath, transaction: SubscriptionTransaction):
431436
"""This is the subscription callback when an attribute report is received.

0 commit comments

Comments
 (0)