tests/run-tests.py
changeset 52311 d49144a1422f
parent 52284 7f8d0c2c3692
child 52313 0b708a375490
--- a/tests/run-tests.py	Mon Nov 18 15:42:09 2024 +0100
+++ b/tests/run-tests.py	Thu Nov 21 01:07:47 2024 -0500
@@ -84,6 +84,8 @@
 WINDOWS = os.name == r'nt'
 shellquote = shlex.quote
 
+# The number of HGPORTx ports allocated to each test.
+HGPORT_COUNT = 4
 
 processlock = threading.Lock()
 
@@ -1401,16 +1403,16 @@
         output. This function defines how some of that normalization will
         occur.
         """
-        r = [
-            # This list should be parallel to defineport in _getenv
-            self._portmap(0),
-            self._portmap(1),
-            self._portmap(2),
-            self._portmap(3),
-            (br'([^0-9])%s' % re.escape(self._localip()), br'\1$LOCALIP'),
-            (br'\bHG_TXNID=TXN:[a-f0-9]{40}\b', br'HG_TXNID=TXN:$ID$'),
-        ]
-        r.append((self._escapepath(self._testtmp), b'$TESTTMP'))
+        r = [self._portmap(port) for port in range(HGPORT_COUNT)]
+
+        r.extend(
+            [
+                (br'([^0-9])%s' % re.escape(self._localip()), br'\1$LOCALIP'),
+                (br'\bHG_TXNID=TXN:[a-f0-9]{40}\b', br'HG_TXNID=TXN:$ID$'),
+                (self._escapepath(self._testtmp), b'$TESTTMP'),
+            ]
+        )
+
         if WINDOWS:
             # JSON output escapes backslashes in Windows paths, so also catch a
             # double-escape.
@@ -1509,9 +1511,8 @@
         formated_timeout = _bytes2sys(b"%d" % default_defaults['timeout'][1])
         env['HGTEST_TIMEOUT_DEFAULT'] = formated_timeout
         env['HGTEST_TIMEOUT'] = _bytes2sys(b"%d" % self._timeout)
-        # This number should match portneeded in _getport
-        for port in range(4):
-            # This list should be parallel to _portmap in _getreplacements
+
+        for port in range(HGPORT_COUNT):
             defineport(port)
         env["HGRCPATH"] = _bytes2sys(os.path.join(self._threadtmp, b'.hgrc'))
         env["DAEMON_PIDS"] = _bytes2sys(
@@ -3727,7 +3728,7 @@
     def _getport(self, count):
         port = self._ports.get(count)  # do we have a cached entry?
         if port is None:
-            portneeded = 4
+            portneeded = HGPORT_COUNT
             # above 100 tries we just give up and let test reports failure
             for tries in range(100):
                 allfree = True