<p>Sean Bright has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/testsuite/+/13586">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">test_config.py: Use cached dependencies when possible<br><br>The dependency evaluated for a given set of requirements will not have<br>a different result within the same run of the test suite, so cache the<br>Dependency itself and re-use it when possible.<br><br>This shaves about 2 seconds off of a ./runtests.py -l. Coupled with<br>the updated pjsua check, this gets us down to just north of 1 second<br>for a full test list.<br><br>Change-Id: Id0ddbc2021f77f3d1c4b50644e26665f1f4f9a0d<br>---<br>M lib/python/asterisk/test_config.py<br>1 file changed, 23 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/86/13586/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/lib/python/asterisk/test_config.py b/lib/python/asterisk/test_config.py</span><br><span>index b395e63..11c54d0 100644</span><br><span>--- a/lib/python/asterisk/test_config.py</span><br><span>+++ b/lib/python/asterisk/test_config.py</span><br><span>@@ -281,6 +281,8 @@</span><br><span> by that tests test.yaml file.</span><br><span> """</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ dependency_cache = {}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> def __init__(self, test_name, global_test_config=None):</span><br><span> """Create a new TestConfig</span><br><span> </span><br><span>@@ -442,7 +444,7 @@</span><br><span> </span><br><span> if not self.deps:</span><br><span> self.deps = [</span><br><span style="color: hsl(0, 100%, 40%);">- Dependency(dep)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.dependency_factory(dep)</span><br><span> for dep in self.config["properties"].get("dependencies") or []</span><br><span> ]</span><br><span> return self.deps</span><br><span>@@ -487,3 +489,23 @@</span><br><span> </span><br><span> # all tags matched successfully</span><br><span> return self.can_run</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def dependency_factory(self, dep):</span><br><span style="color: hsl(120, 100%, 40%);">+ """Creates a Dependency from the given specification or returns</span><br><span style="color: hsl(120, 100%, 40%);">+ the Dependency if it already exists</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ Returns:</span><br><span style="color: hsl(120, 100%, 40%);">+ A Dependency</span><br><span style="color: hsl(120, 100%, 40%);">+ """</span><br><span style="color: hsl(120, 100%, 40%);">+ # freeze() implementation from https://stackoverflow.com/a/13264725/21926</span><br><span style="color: hsl(120, 100%, 40%);">+ def freeze(d):</span><br><span style="color: hsl(120, 100%, 40%);">+ if isinstance(d, dict):</span><br><span style="color: hsl(120, 100%, 40%);">+ return frozenset((key, freeze(value)) for key, value in d.items())</span><br><span style="color: hsl(120, 100%, 40%);">+ elif isinstance(d, list):</span><br><span style="color: hsl(120, 100%, 40%);">+ return tuple(freeze(value) for value in d)</span><br><span style="color: hsl(120, 100%, 40%);">+ return d</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ key = freeze(dep)</span><br><span style="color: hsl(120, 100%, 40%);">+ if key not in TestConfig.dependency_cache:</span><br><span style="color: hsl(120, 100%, 40%);">+ TestConfig.dependency_cache[key] = Dependency(dep)</span><br><span style="color: hsl(120, 100%, 40%);">+ return TestConfig.dependency_cache[key]</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/testsuite/+/13586">change 13586</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/testsuite/+/13586"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: testsuite </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: Id0ddbc2021f77f3d1c4b50644e26665f1f4f9a0d </div>
<div style="display:none"> Gerrit-Change-Number: 13586 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>