Skip to content

Commit f5216e8

Browse files
authored
Clean up subscriptions from fabric sync tests (#35485)
1 parent dfa0987 commit f5216e8

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

src/python_testing/TC_BRBINFO_4_1.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ async def setup_class(self):
123123
self.set_of_dut_endpoints_before_adding_device = set(root_part_list)
124124

125125
super().setup_class()
126+
self._active_change_event_subscription = None
126127
self.app_process = None
127128
self.app_process_paused = False
128129
app = self.user_params.get("th_icd_server_app_path", None)
@@ -156,6 +157,10 @@ async def setup_class(self):
156157
params.commissioningParameters.setupManualCode, params.commissioningParameters.setupQRCode)
157158

158159
def teardown_class(self):
160+
if self._active_change_event_subscription is not None:
161+
self._active_change_event_subscription.Shutdown()
162+
self._active_change_event_subscription = None
163+
159164
# In case the th_icd_server_app_path does not exist, then we failed the test
160165
# and there is nothing to remove
161166
if self.app_process is not None:
@@ -239,8 +244,8 @@ async def test_TC_BRBINFO_4_1(self):
239244
self.q = queue.Queue()
240245
urgent = 1
241246
cb = SimpleEventCallback("ActiveChanged", event.cluster_id, event.event_id, self.q)
242-
subscription = await self.default_controller.ReadEvent(nodeid=self.dut_node_id, events=[(dynamic_endpoint_id, event, urgent)], reportInterval=[1, 3])
243-
subscription.SetEventUpdateCallback(callback=cb)
247+
self._active_change_event_subscription = await self.default_controller.ReadEvent(nodeid=self.dut_node_id, events=[(dynamic_endpoint_id, event, urgent)], reportInterval=[1, 3])
248+
self._active_change_event_subscription.SetEventUpdateCallback(callback=cb)
244249

245250
self.step("3")
246251
stay_active_duration_ms = 1000

src/python_testing/TC_MCORE_FS_1_2.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@ class TC_MCORE_FS_1_2(MatterBaseTest):
6363
@async_test_body
6464
async def setup_class(self):
6565
super().setup_class()
66+
self._partslist_subscription = None
6667
self._app_th_server_process = None
6768
self._th_server_kvs = None
6869

6970
def teardown_class(self):
71+
if self._partslist_subscription is not None:
72+
self._partslist_subscription.Shutdown()
73+
self._partslist_subscription = None
74+
7075
if self._app_th_server_process is not None:
7176
logging.warning("Stopping app with SIGTERM")
7277
self._app_th_server_process.send_signal(signal.SIGTERM.value)
@@ -142,7 +147,7 @@ async def test_TC_MCORE_FS_1_2(self):
142147
subscription_contents = [
143148
(root_endpoint, Clusters.Descriptor.Attributes.PartsList)
144149
]
145-
sub = await self.default_controller.ReadAttribute(
150+
self._partslist_subscription = await self.default_controller.ReadAttribute(
146151
nodeid=self.dut_node_id,
147152
attributes=subscription_contents,
148153
reportInterval=(min_report_interval_sec, max_report_interval_sec),
@@ -152,8 +157,8 @@ async def test_TC_MCORE_FS_1_2(self):
152157
parts_list_queue = queue.Queue()
153158
attribute_handler = AttributeChangeAccumulator(
154159
name=self.default_controller.name, expected_attribute=Clusters.Descriptor.Attributes.PartsList, output=parts_list_queue)
155-
sub.SetAttributeUpdateCallback(attribute_handler)
156-
cached_attributes = sub.GetAttributes()
160+
self._partslist_subscription.SetAttributeUpdateCallback(attribute_handler)
161+
cached_attributes = self._partslist_subscription.GetAttributes()
157162
step_1_dut_parts_list = cached_attributes[root_endpoint][Clusters.Descriptor][Clusters.Descriptor.Attributes.PartsList]
158163

159164
asserts.assert_true(type_matches(step_1_dut_parts_list, list), "PartsList is expected to be a list")

src/python_testing/TC_MCORE_FS_1_5.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,20 @@ class TC_MCORE_FS_1_5(MatterBaseTest):
6161
@async_test_body
6262
async def setup_class(self):
6363
super().setup_class()
64+
self._partslist_subscription = None
65+
self._cadmin_subscription = None
6466
self._app_th_server_process = None
6567
self._th_server_kvs = None
6668

6769
def teardown_class(self):
70+
if self._partslist_subscription is not None:
71+
self._partslist_subscription.Shutdown()
72+
self._partslist_subscription = None
73+
74+
if self._cadmin_subscription is not None:
75+
self._cadmin_subscription.Shutdown()
76+
self._cadmin_subscription = None
77+
6878
if self._app_th_server_process is not None:
6979
logging.warning("Stopping app with SIGTERM")
7080
self._app_th_server_process.send_signal(signal.SIGTERM.value)
@@ -142,7 +152,7 @@ async def test_TC_MCORE_FS_1_5(self):
142152
parts_list_subscription_contents = [
143153
(root_endpoint, Clusters.Descriptor.Attributes.PartsList)
144154
]
145-
parts_list_sub = await self.default_controller.ReadAttribute(
155+
self._partslist_subscription = await self.default_controller.ReadAttribute(
146156
nodeid=self.dut_node_id,
147157
attributes=parts_list_subscription_contents,
148158
reportInterval=(min_report_interval_sec, max_report_interval_sec),
@@ -152,8 +162,8 @@ async def test_TC_MCORE_FS_1_5(self):
152162
parts_list_queue = queue.Queue()
153163
parts_list_attribute_handler = AttributeChangeAccumulator(
154164
name=self.default_controller.name, expected_attribute=Clusters.Descriptor.Attributes.PartsList, output=parts_list_queue)
155-
parts_list_sub.SetAttributeUpdateCallback(parts_list_attribute_handler)
156-
parts_list_cached_attributes = parts_list_sub.GetAttributes()
165+
self._partslist_subscription.SetAttributeUpdateCallback(parts_list_attribute_handler)
166+
parts_list_cached_attributes = self._partslist_subscription.GetAttributes()
157167
step_1_dut_parts_list = parts_list_cached_attributes[root_endpoint][Clusters.Descriptor][Clusters.Descriptor.Attributes.PartsList]
158168

159169
asserts.assert_true(type_matches(step_1_dut_parts_list, list), "PartsList is expected to be a list")
@@ -219,7 +229,7 @@ async def test_TC_MCORE_FS_1_5(self):
219229
cadmin_subscription_contents = [
220230
(newly_added_endpoint, Clusters.AdministratorCommissioning)
221231
]
222-
cadmin_sub = await self.default_controller.ReadAttribute(
232+
self._cadmin_subscription = await self.default_controller.ReadAttribute(
223233
nodeid=self.dut_node_id,
224234
attributes=cadmin_subscription_contents,
225235
reportInterval=(min_report_interval_sec, max_report_interval_sec),
@@ -230,7 +240,7 @@ async def test_TC_MCORE_FS_1_5(self):
230240
# This AttributeChangeAccumulator is really just to let us know when new subscription came in
231241
cadmin_attribute_handler = AttributeChangeAccumulator(
232242
name=self.default_controller.name, expected_attribute=Clusters.AdministratorCommissioning.Attributes.WindowStatus, output=cadmin_queue)
233-
cadmin_sub.SetAttributeUpdateCallback(cadmin_attribute_handler)
243+
self._cadmin_subscription.SetAttributeUpdateCallback(cadmin_attribute_handler)
234244
time.sleep(1)
235245

236246
self.step(7)

0 commit comments

Comments
 (0)