[Asterisk-code-review] test_config.py: Use cached dependencies when possible (testsuite[13])

Sean Bright asteriskteam at digium.com
Thu Jan 9 10:04:17 CST 2020


Sean Bright has uploaded this change for review. ( https://gerrit.asterisk.org/c/testsuite/+/13586 )


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(-)



  git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/86/13586/1

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/+/13586
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: testsuite
Gerrit-Branch: 13
Gerrit-Change-Id: Id0ddbc2021f77f3d1c4b50644e26665f1f4f9a0d
Gerrit-Change-Number: 13586
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200109/c526dbdd/attachment.html>


More information about the asterisk-code-review mailing list