[PATCH] run-tests: use different chg socket directories for different tests

Jun Wu quark at fb.com
Sun Mar 20 20:43:21 EDT 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1458519486 25200
#      Sun Mar 20 17:18:06 2016 -0700
# Node ID ccac69466d6b729fa09a35d7ee690a36735c48b6
# Parent  83127a9fe76ea8b9379d9efa3afefff075b4f920
run-tests: use different chg socket directories for different tests

Before this patch, if --chg or --with-chg is specified, all tests are using
a same chgserver socket. Since the chg client holds a lock when it starts a
new server, and every test needs at least a new chg server due to different
HGRCPATH affecting the confighash. The result is a lot of tests will be
timed out if -j is large (for example, 50 or 100).

This patch solves the issue by using different chg socket directories for
different tests.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -485,7 +485,7 @@
                  timeout=defaults['timeout'],
                  startport=defaults['port'], extraconfigopts=None,
                  py3kwarnings=False, shell=None, hgcommand=None,
-                 slowtimeout=defaults['slowtimeout']):
+                 slowtimeout=defaults['slowtimeout'], usechg=False):
         """Create a test from parameters.
 
         path is the full path to the file defining the test.
@@ -532,6 +532,7 @@
         self._py3kwarnings = py3kwarnings
         self._shell = _bytespath(shell)
         self._hgcommand = hgcommand or b'hg'
+        self._usechg = usechg
 
         self._aborted = False
         self._daemonpids = []
@@ -591,6 +592,11 @@
                 if e.errno != errno.ENOENT:
                     raise
 
+        if self._usechg:
+            self._chgsockdir = os.path.join(self._threadtmp, 'chgsock',
+                                            os.path.basename(self.path))
+            os.makedirs(self._chgsockdir)
+
     def run(self, result):
         """Run this test and report results against a TestResult instance."""
         # This function is extremely similar to unittest.TestCase.run(). Once
@@ -733,6 +739,10 @@
         else:
             shutil.rmtree(self._testtmp, True)
             shutil.rmtree(self._threadtmp, True)
+            if self._usechg:
+                # chgservers will stop automatically after they find the socket
+                # files are deleted
+                shutil.rmtree(self._chgsockdir, True)
 
         if (self._ret != 0 or self._out != self._refout) and not self._skipped \
             and not self._debug and self._out:
@@ -823,6 +833,9 @@
             if k.startswith('HG_'):
                 del env[k]
 
+        if self._usechg:
+            env['CHGSOCKNAME'] = os.path.join(self._chgsockdir, b'server')
+
         return env
 
     def _createhgrc(self, path):
@@ -1910,7 +1923,6 @@
         self._createdfiles = []
         self._hgcommand = None
         self._hgpath = None
-        self._chgsockdir = None
         self._portoffset = 0
         self._ports = {}
 
@@ -2035,12 +2047,9 @@
             self._tmpbindir = self._bindir
             self._pythondir = os.path.join(self._installdir, b"lib", b"python")
 
-        # set up crafted chg environment, then replace "hg" command by "chg"
+        # set CHGHG, then replace "hg" command by "chg"
         chgbindir = self._bindir
         if self.options.chg or self.options.with_chg:
-            self._chgsockdir = d = os.path.join(self._hgtmp, b'chgsock')
-            os.mkdir(d)
-            osenvironb[b'CHGSOCKNAME'] = os.path.join(d, b"server")
             osenvironb[b'CHGHG'] = os.path.join(self._bindir, self._hgcommand)
         if self.options.chg:
             self._hgcommand = b'chg'
@@ -2234,15 +2243,13 @@
                     extraconfigopts=self.options.extra_config_opt,
                     py3kwarnings=self.options.py3k_warnings,
                     shell=self.options.shell,
-                    hgcommand=self._hgcommand)
+                    hgcommand=self._hgcommand,
+                    usechg=bool(self.options.with_chg or self.options.chg))
         t.should_reload = True
         return t
 
     def _cleanup(self):
         """Clean up state from this test invocation."""
-        if self._chgsockdir:
-            self._killchgdaemons()
-
         if self.options.keep_tmpdir:
             return
 
@@ -2460,13 +2467,6 @@
                 sys.stdout.write(out)
             sys.exit(1)
 
-    def _killchgdaemons(self):
-        """Kill all background chg command servers spawned by tests"""
-        for f in os.listdir(self._chgsockdir):
-            if '.' in f:
-                continue
-            os.unlink(os.path.join(self._chgsockdir, f))
-
     def _outputcoverage(self):
         """Produce code coverage output."""
         from coverage import coverage


More information about the Mercurial-devel mailing list