changeset 36492:5c1cea8a3e60

run-tests: cache hghave results Spawning a process on Windows is expensive. I've got a version of test-lfs-test-server.t locally which prints the http request/responses that totals 819 lines, with 149 conditional lines, 11 #if tests, and 2 test cases. It takes just under 1 minute with this change to run both cases, vs just over 2 minutes without this change. Worse, when I explored adding ui.debug to the test, it takes 13 minutes due to all of the mismatches and retests, vs less than 1 minute with this change. Overall, the difference when running all tests is negligible- 103 minutes with this change, vs 105 without when using -j9. It also looks like an exit value of 2 from `hghave` is treated specially, but there's nothing preventing 2 missing features from also using this value.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 25 Feb 2018 17:22:25 -0500
parents 51a9f0246931
children 1bd132a021dd
files tests/run-tests.py
diffstat 1 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Mon Feb 26 23:34:29 2018 -0500
+++ b/tests/run-tests.py	Sun Feb 25 17:22:25 2018 -0500
@@ -1236,6 +1236,7 @@
             self.name = '%s (case %s)' % (self.name, _strpath(case))
             self.errpath = b'%s.%s.err' % (self.errpath[:-4], case)
             self._tmpname += b'-%s' % case
+        self._have = {}
 
     @property
     def refpath(self):
@@ -1275,11 +1276,15 @@
         return self._processoutput(exitcode, output, salt, after, expected)
 
     def _hghave(self, reqs):
+        allreqs = b' '.join(reqs)
+        if allreqs in self._have:
+            return self._have.get(allreqs)
+
         # TODO do something smarter when all other uses of hghave are gone.
         runtestdir = os.path.abspath(os.path.dirname(_bytespath(__file__)))
         tdir = runtestdir.replace(b'\\', b'/')
         proc = Popen4(b'%s -c "%s/hghave %s"' %
-                      (self._shell, tdir, b' '.join(reqs)),
+                      (self._shell, tdir, allreqs),
                       self._testtmp, 0, self._getenv())
         stdout, stderr = proc.communicate()
         ret = proc.wait()
@@ -1290,10 +1295,13 @@
             sys.exit(1)
 
         if ret != 0:
+            self._have[allreqs] = (False, stdout)
             return False, stdout
 
         if b'slow' in reqs:
             self._timeout = self._slowtimeout
+
+        self._have[allreqs] = (True, None)
         return True, None
 
     def _iftest(self, args):