Skip to content

Commit add5b26

Browse files
authored
[Python] Eliminate ZCLSubscribeAttribute (#33337)
* Use asyncio sleep to unblock asyncio event loop * Avoid fixed sleep in TestCaseEviction Use asyncio Event and wait_for to wait for the change and continue immediately when received. * Make TestSubscription an async test The current test implementation starves the asyncio event loop by synchronously waiting for the threading.Condition. This prevents making the SubscriptionTransaction fully leveraging the async paradigm. It probably would be possible to mix asyncio.sleep() and threading, but instead embrace the async pradigm for this test. * Make TestSubscriptionResumption an async test The current test implementation starves the asyncio event loop by synchronously waiting for the threading.Condition. This prevents making the SubscriptionTransaction fully leveraging the async paradigm. It probably would be possible to mix asyncio.sleep() and threading, but instead embrace the async pradigm for this test. * Make TestSubscriptionResumptionCapacityStep1 an async test Eliminate use of ZCLSubscribeAttribute and embrace asyncio. * Make TestSubscriptionResumptionCapacityStep2 an async test Eliminate use of ZCLSubscribeAttribute and embrace asyncio. * Remove ZCLSubscribeAttribute from subscription_resumption_timeout_test Use ReadAttribute with asyncio in subscription_resumption_timeout_test as well. * Rewrite TestWriteBasicAttributes to drop ZCLRead/WriteAttribute * Improve wait for end of update task in TestSubscription
1 parent 11cb2b3 commit add5b26

6 files changed

+128
-126
lines changed

src/controller/python/test/test_scripts/base.py

+107-112
Large diffs are not rendered by default.

src/controller/python/test/test_scripts/mobile-device-test.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@ def TestDatamodel(test: BaseTestHelper, device_nodeid: int):
129129
"Failed to test Read Basic Attributes")
130130

131131
logger.info("Testing attribute writing")
132-
FailIfNot(test.TestWriteBasicAttributes(nodeid=device_nodeid,
133-
endpoint=ENDPOINT_ID,
134-
group=GROUP_ID),
132+
FailIfNot(asyncio.run(test.TestWriteBasicAttributes(nodeid=device_nodeid,
133+
endpoint=ENDPOINT_ID)),
135134
"Failed to test Write Basic Attributes")
136135

137136
logger.info("Testing attribute reading basic again")
@@ -141,11 +140,11 @@ def TestDatamodel(test: BaseTestHelper, device_nodeid: int):
141140
"Failed to test Read Basic Attributes")
142141

143142
logger.info("Testing subscription")
144-
FailIfNot(test.TestSubscription(nodeid=device_nodeid, endpoint=LIGHTING_ENDPOINT_ID),
143+
FailIfNot(asyncio.run(test.TestSubscription(nodeid=device_nodeid, endpoint=LIGHTING_ENDPOINT_ID)),
145144
"Failed to subscribe attributes.")
146145

147146
logger.info("Testing another subscription that kills previous subscriptions")
148-
FailIfNot(test.TestSubscription(nodeid=device_nodeid, endpoint=LIGHTING_ENDPOINT_ID),
147+
FailIfNot(asyncio.run(test.TestSubscription(nodeid=device_nodeid, endpoint=LIGHTING_ENDPOINT_ID)),
149148
"Failed to subscribe attributes.")
150149

151150
logger.info("Testing re-subscription")

src/controller/python/test/test_scripts/subscription_resumption_capacity_test_ctrl1.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
# Commissioning test.
2121

22+
import asyncio
2223
import os
2324
import sys
2425
from optparse import OptionParser
@@ -113,8 +114,8 @@ def main():
113114
"Failed on on-network commissioing")
114115

115116
FailIfNot(
116-
test.TestSubscriptionResumptionCapacityStep1(
117-
options.nodeid, TEST_ENDPOINT_ID, options.setuppin, options.subscriptionCapacity),
117+
asyncio.run(test.TestSubscriptionResumptionCapacityStep1(
118+
options.nodeid, TEST_ENDPOINT_ID, options.setuppin, options.subscriptionCapacity)),
118119
"Failed on step 1 of testing subscription resumption capacity")
119120

120121
timeoutTicker.stop()

src/controller/python/test/test_scripts/subscription_resumption_capacity_test_ctrl2.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
# Commissioning test.
2121

22+
import asyncio
2223
import os
2324
import sys
2425
from optparse import OptionParser
@@ -125,8 +126,9 @@ def main():
125126
"Failed on on-network commissioing")
126127

127128
FailIfNot(
128-
test.TestSubscriptionResumptionCapacityStep2(options.nodeid, TEST_ENDPOINT_ID, options.deviceAddress,
129-
TEST_SSH_PORT, options.remoteServerApp, options.subscriptionCapacity),
129+
asyncio.run(
130+
test.TestSubscriptionResumptionCapacityStep2(options.nodeid, TEST_ENDPOINT_ID, options.deviceAddress,
131+
TEST_SSH_PORT, options.remoteServerApp, options.subscriptionCapacity)),
130132
"Failed on testing subscription resumption capacity")
131133

132134
timeoutTicker.stop()

src/controller/python/test/test_scripts/subscription_resumption_test.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
# Commissioning test.
2121

22+
import asyncio
2223
import os
2324
import sys
2425
from optparse import OptionParser
@@ -115,8 +116,8 @@ def main():
115116
"Failed on on-network commissioing")
116117

117118
FailIfNot(
118-
test.TestSubscriptionResumption(options.nodeid, TEST_ENDPOINT_ID, options.deviceAddress,
119-
TEST_SSH_PORT, options.remoteServerApp), "Failed to resume subscription")
119+
asyncio.run(test.TestSubscriptionResumption(options.nodeid, TEST_ENDPOINT_ID, options.deviceAddress,
120+
TEST_SSH_PORT, options.remoteServerApp)), "Failed to resume subscription")
120121

121122
timeoutTicker.stop()
122123

src/controller/python/test/test_scripts/subscription_resumption_timeout_test.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919

2020
# Commissioning test.
2121

22+
import asyncio
2223
import os
2324
import sys
2425
from optparse import OptionParser
2526

2627
from base import BaseTestHelper, FailIfNot, TestFail, TestTimeout, logger
28+
from chip import clusters as Clusters
2729

2830
TEST_DISCRIMINATOR = 3840
2931
TEST_SETUPPIN = 20202021
@@ -101,10 +103,12 @@ def main():
101103

102104
FailIfNot(
103105
test.TestOnNetworkCommissioning(options.discriminator, options.setuppin, options.nodeid, options.deviceAddress),
104-
"Failed on on-network commissioing")
106+
"Failed on on-network commissioning")
107+
105108
try:
106-
test.devCtrl.ZCLSubscribeAttribute("BasicInformation", "NodeLabel", options.nodeid, TEST_ENDPOINT_ID, 1, 2,
107-
keepSubscriptions=True, autoResubscribe=False)
109+
asyncio.run(test.devCtrl.ReadAttribute(options.nodeid,
110+
[(TEST_ENDPOINT_ID, Clusters.BasicInformation.Attributes.NodeLabel)],
111+
None, False, reportInterval=(1, 2), keepSubscriptions=True, autoResubscribe=False))
108112
except Exception as ex:
109113
TestFail(f"Failed to subscribe attribute: {ex}")
110114

0 commit comments

Comments
 (0)