[Asterisk-code-review] test_config.py: Use cached dependencies when possible (testsuite[master])
Friendly Automation
asteriskteam at digium.com
Tue Jan 14 08:12:35 CST 2020
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/testsuite/+/13610 )
Change subject: test_config.py: Use cached dependencies when possible
......................................................................
test_config.py: Use cached dependencies when possible
The dependency evaluated for a given set of requirements will not have
a different result within the same run of the test suite, so cache the
Dependency itself and re-use it when possible.
This shaves about 2 seconds off of a ./runtests.py -l. Coupled with
the updated pjsua check, this gets us down to just north of 1 second
for a full test list.
Change-Id: Id0ddbc2021f77f3d1c4b50644e26665f1f4f9a0d
---
M lib/python/asterisk/test_config.py
1 file changed, 23 insertions(+), 1 deletion(-)
Approvals:
Kevin Harwell: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
diff --git a/lib/python/asterisk/test_config.py b/lib/python/asterisk/test_config.py
index b395e63..11c54d0 100644
--- a/lib/python/asterisk/test_config.py
+++ b/lib/python/asterisk/test_config.py
@@ -281,6 +281,8 @@
by that tests test.yaml file.
"""
+ dependency_cache = {}
+
def __init__(self, test_name, global_test_config=None):
"""Create a new TestConfig
@@ -442,7 +444,7 @@
if not self.deps:
self.deps = [
- Dependency(dep)
+ self.dependency_factory(dep)
for dep in self.config["properties"].get("dependencies") or []
]
return self.deps
@@ -487,3 +489,23 @@
# all tags matched successfully
return self.can_run
+
+ def dependency_factory(self, dep):
+ """Creates a Dependency from the given specification or returns
+ the Dependency if it already exists
+
+ Returns:
+ A Dependency
+ """
+ # freeze() implementation from https://stackoverflow.com/a/13264725/21926
+ def freeze(d):
+ if isinstance(d, dict):
+ return frozenset((key, freeze(value)) for key, value in d.items())
+ elif isinstance(d, list):
+ return tuple(freeze(value) for value in d)
+ return d
+
+ key = freeze(dep)
+ if key not in TestConfig.dependency_cache:
+ TestConfig.dependency_cache[key] = Dependency(dep)
+ return TestConfig.dependency_cache[key]
--
To view, visit https://gerrit.asterisk.org/c/testsuite/+/13610
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Change-Id: Id0ddbc2021f77f3d1c4b50644e26665f1f4f9a0d
Gerrit-Change-Number: 13610
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200114/b25b2a9a/attachment-0001.html>
More information about the asterisk-code-review
mailing list