Skip to content

Commit

Permalink
Fix the cancelling of subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterC1965 committed Aug 22, 2024
1 parent e95b739 commit 69f2ea1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/python_testing/TC_DEM_2_10.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 8 additions & 3 deletions src/python_testing/matter_testing_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 69f2ea1

Please sign in to comment.