##// END OF EJS Templates
run-test: ensure the test ports are available before launching test...
Pierre-Yves David -
r24967:00790cc2 default
parent child Browse files
Show More
@@ -49,6 +49,7 b' import os'
49 import shutil
49 import shutil
50 import subprocess
50 import subprocess
51 import signal
51 import signal
52 import socket
52 import sys
53 import sys
53 import tempfile
54 import tempfile
54 import time
55 import time
@@ -78,6 +79,18 b' if sys.version_info < (2, 5):'
78
79
79 wifexited = getattr(os, "WIFEXITED", lambda x: False)
80 wifexited = getattr(os, "WIFEXITED", lambda x: False)
80
81
82 def checkportisavailable(port):
83 """return true if a port seems free to bind on localhost"""
84 try:
85 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
86 s.bind(('localhost', port))
87 s.close()
88 return True
89 except socket.error, exc:
90 if not exc.errno == errno.EADDRINUSE:
91 raise
92 return False
93
81 closefds = os.name == 'posix'
94 closefds = os.name == 'posix'
82 def Popen4(cmd, wd, timeout, env=None):
95 def Popen4(cmd, wd, timeout, env=None):
83 processlock.acquire()
96 processlock.acquire()
@@ -1608,6 +1621,8 b' class TestRunner(object):'
1608 self._coveragefile = None
1621 self._coveragefile = None
1609 self._createdfiles = []
1622 self._createdfiles = []
1610 self._hgpath = None
1623 self._hgpath = None
1624 self._portoffset = 0
1625 self._ports = {}
1611
1626
1612 def run(self, args, parser=None):
1627 def run(self, args, parser=None):
1613 """Run the test suite."""
1628 """Run the test suite."""
@@ -1812,6 +1827,24 b' class TestRunner(object):'
1812 if warned:
1827 if warned:
1813 return 80
1828 return 80
1814
1829
1830 def _getport(self, count):
1831 port = self._ports.get(count) # do we have a cached entry?
1832 if port is None:
1833 port = self.options.port + self._portoffset
1834 portneeded = 3
1835 # above 100 tries we just give up and let test reports failure
1836 for tries in xrange(100):
1837 allfree = True
1838 for idx in xrange(portneeded):
1839 if not checkportisavailable(port + idx):
1840 allfree = False
1841 break
1842 self._portoffset += portneeded
1843 if allfree:
1844 break
1845 self._ports[count] = port
1846 return port
1847
1815 def _gettest(self, test, count):
1848 def _gettest(self, test, count):
1816 """Obtain a Test by looking at its filename.
1849 """Obtain a Test by looking at its filename.
1817
1850
@@ -1833,7 +1866,7 b' class TestRunner(object):'
1833 keeptmpdir=self.options.keep_tmpdir,
1866 keeptmpdir=self.options.keep_tmpdir,
1834 debug=self.options.debug,
1867 debug=self.options.debug,
1835 timeout=self.options.timeout,
1868 timeout=self.options.timeout,
1836 startport=self.options.port + count * 3,
1869 startport=self._getport(count),
1837 extraconfigopts=self.options.extra_config_opt,
1870 extraconfigopts=self.options.extra_config_opt,
1838 py3kwarnings=self.options.py3k_warnings,
1871 py3kwarnings=self.options.py3k_warnings,
1839 shell=self.options.shell)
1872 shell=self.options.shell)
General Comments 0
You need to be logged in to leave comments. Login now