Skip to content

Commit

Permalink
[Python] Eliminate ZCLSubscribeAttribute (#33337)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
agners authored May 13, 2024
1 parent 11cb2b3 commit add5b26
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 126 deletions.
219 changes: 107 additions & 112 deletions src/controller/python/test/test_scripts/base.py

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions src/controller/python/test/test_scripts/mobile-device-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ def TestDatamodel(test: BaseTestHelper, device_nodeid: int):
"Failed to test Read Basic Attributes")

logger.info("Testing attribute writing")
FailIfNot(test.TestWriteBasicAttributes(nodeid=device_nodeid,
endpoint=ENDPOINT_ID,
group=GROUP_ID),
FailIfNot(asyncio.run(test.TestWriteBasicAttributes(nodeid=device_nodeid,
endpoint=ENDPOINT_ID)),
"Failed to test Write Basic Attributes")

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

logger.info("Testing subscription")
FailIfNot(test.TestSubscription(nodeid=device_nodeid, endpoint=LIGHTING_ENDPOINT_ID),
FailIfNot(asyncio.run(test.TestSubscription(nodeid=device_nodeid, endpoint=LIGHTING_ENDPOINT_ID)),
"Failed to subscribe attributes.")

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

logger.info("Testing re-subscription")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

# Commissioning test.

import asyncio
import os
import sys
from optparse import OptionParser
Expand Down Expand Up @@ -113,8 +114,8 @@ def main():
"Failed on on-network commissioing")

FailIfNot(
test.TestSubscriptionResumptionCapacityStep1(
options.nodeid, TEST_ENDPOINT_ID, options.setuppin, options.subscriptionCapacity),
asyncio.run(test.TestSubscriptionResumptionCapacityStep1(
options.nodeid, TEST_ENDPOINT_ID, options.setuppin, options.subscriptionCapacity)),
"Failed on step 1 of testing subscription resumption capacity")

timeoutTicker.stop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

# Commissioning test.

import asyncio
import os
import sys
from optparse import OptionParser
Expand Down Expand Up @@ -125,8 +126,9 @@ def main():
"Failed on on-network commissioing")

FailIfNot(
test.TestSubscriptionResumptionCapacityStep2(options.nodeid, TEST_ENDPOINT_ID, options.deviceAddress,
TEST_SSH_PORT, options.remoteServerApp, options.subscriptionCapacity),
asyncio.run(
test.TestSubscriptionResumptionCapacityStep2(options.nodeid, TEST_ENDPOINT_ID, options.deviceAddress,
TEST_SSH_PORT, options.remoteServerApp, options.subscriptionCapacity)),
"Failed on testing subscription resumption capacity")

timeoutTicker.stop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

# Commissioning test.

import asyncio
import os
import sys
from optparse import OptionParser
Expand Down Expand Up @@ -115,8 +116,8 @@ def main():
"Failed on on-network commissioing")

FailIfNot(
test.TestSubscriptionResumption(options.nodeid, TEST_ENDPOINT_ID, options.deviceAddress,
TEST_SSH_PORT, options.remoteServerApp), "Failed to resume subscription")
asyncio.run(test.TestSubscriptionResumption(options.nodeid, TEST_ENDPOINT_ID, options.deviceAddress,
TEST_SSH_PORT, options.remoteServerApp)), "Failed to resume subscription")

timeoutTicker.stop()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@

# Commissioning test.

import asyncio
import os
import sys
from optparse import OptionParser

from base import BaseTestHelper, FailIfNot, TestFail, TestTimeout, logger
from chip import clusters as Clusters

TEST_DISCRIMINATOR = 3840
TEST_SETUPPIN = 20202021
Expand Down Expand Up @@ -101,10 +103,12 @@ def main():

FailIfNot(
test.TestOnNetworkCommissioning(options.discriminator, options.setuppin, options.nodeid, options.deviceAddress),
"Failed on on-network commissioing")
"Failed on on-network commissioning")

try:
test.devCtrl.ZCLSubscribeAttribute("BasicInformation", "NodeLabel", options.nodeid, TEST_ENDPOINT_ID, 1, 2,
keepSubscriptions=True, autoResubscribe=False)
asyncio.run(test.devCtrl.ReadAttribute(options.nodeid,
[(TEST_ENDPOINT_ID, Clusters.BasicInformation.Attributes.NodeLabel)],
None, False, reportInterval=(1, 2), keepSubscriptions=True, autoResubscribe=False))
except Exception as ex:
TestFail(f"Failed to subscribe attribute: {ex}")

Expand Down

0 comments on commit add5b26

Please sign in to comment.