Skip to content
Snippets Groups Projects
Commit 59fe123d authored by Gregory Szorc's avatar Gregory Szorc
Browse files

run-tests: refactor port number declaration

Instead of making port numbers derived from count and a global initial
port, we now pass a start port to Test.__init__ and do the calculation
at a higher level.
parent acfd19f3
No related branches found
No related tags found
No related merge requests found
...@@ -338,5 +338,5 @@ ...@@ -338,5 +338,5 @@
# Status code reserved for skipped tests (used by hghave). # Status code reserved for skipped tests (used by hghave).
SKIPPED_STATUS = 80 SKIPPED_STATUS = 80
def __init__(self, options, path, count, tmpdir, abort, keeptmpdir=False, def __init__(self, options, path, tmpdir, abort, keeptmpdir=False,
debug=False, nodiff=False, diffviewer=None, debug=False, nodiff=False, diffviewer=None,
...@@ -342,8 +342,9 @@ ...@@ -342,8 +342,9 @@
debug=False, nodiff=False, diffviewer=None, debug=False, nodiff=False, diffviewer=None,
interactive=False, timeout=defaults['timeout']): interactive=False, timeout=defaults['timeout'],
startport=defaults['port']):
"""Create a test from parameters. """Create a test from parameters.
options are parsed command line options that control test execution. options are parsed command line options that control test execution.
path is the full path to the file defining the test. path is the full path to the file defining the test.
...@@ -344,11 +345,9 @@ ...@@ -344,11 +345,9 @@
"""Create a test from parameters. """Create a test from parameters.
options are parsed command line options that control test execution. options are parsed command line options that control test execution.
path is the full path to the file defining the test. path is the full path to the file defining the test.
count is an identifier used to denote this test instance.
tmpdir is the main temporary directory to use for this test. tmpdir is the main temporary directory to use for this test.
abort is a flag that turns to True if test execution should be aborted. abort is a flag that turns to True if test execution should be aborted.
...@@ -369,6 +368,11 @@ ...@@ -369,6 +368,11 @@
timeout controls the maximum run time of the test. It is ignored when timeout controls the maximum run time of the test. It is ignored when
debug is True. debug is True.
startport controls the starting port number to use for this test. Each
test will reserve 3 port numbers for execution. It is the caller's
responsibility to allocate a non-overlapping port range to Test
instances.
""" """
self.path = path self.path = path
...@@ -377,7 +381,6 @@ ...@@ -377,7 +381,6 @@
self.errpath = os.path.join(self._testdir, '%s.err' % self.name) self.errpath = os.path.join(self._testdir, '%s.err' % self.name)
self._options = options self._options = options
self._count = count
self._threadtmp = tmpdir self._threadtmp = tmpdir
self._abort = abort self._abort = abort
self._keeptmpdir = keeptmpdir self._keeptmpdir = keeptmpdir
...@@ -386,6 +389,7 @@ ...@@ -386,6 +389,7 @@
self._diffviewer = diffviewer self._diffviewer = diffviewer
self._interactive = interactive self._interactive = interactive
self._timeout = timeout self._timeout = timeout
self._startport = startport
self._daemonpids = [] self._daemonpids = []
self._finished = None self._finished = None
...@@ -487,8 +491,8 @@ ...@@ -487,8 +491,8 @@
This will return a tuple describing the result of the test. This will return a tuple describing the result of the test.
""" """
replacements, port = self._getreplacements() replacements = self._getreplacements()
env = self._getenv(port) env = self._getenv()
self._daemonpids.append(env['DAEMON_PIDS']) self._daemonpids.append(env['DAEMON_PIDS'])
self._createhgrc(env['HGRCPATH']) self._createhgrc(env['HGRCPATH'])
...@@ -577,5 +581,4 @@ ...@@ -577,5 +581,4 @@
raise SkipTest('unknown test type') raise SkipTest('unknown test type')
def _getreplacements(self): def _getreplacements(self):
port = self._options.port + self._count * 3
r = [ r = [
...@@ -581,7 +584,7 @@ ...@@ -581,7 +584,7 @@
r = [ r = [
(r':%s\b' % port, ':$HGPORT'), (r':%s\b' % self._startport, ':$HGPORT'),
(r':%s\b' % (port + 1), ':$HGPORT1'), (r':%s\b' % (self._startport + 1), ':$HGPORT1'),
(r':%s\b' % (port + 2), ':$HGPORT2'), (r':%s\b' % (self._startport + 2), ':$HGPORT2'),
] ]
if os.name == 'nt': if os.name == 'nt':
...@@ -592,5 +595,5 @@ ...@@ -592,5 +595,5 @@
else: else:
r.append((re.escape(self._testtmp), '$TESTTMP')) r.append((re.escape(self._testtmp), '$TESTTMP'))
return r, port return r
...@@ -596,5 +599,5 @@ ...@@ -596,5 +599,5 @@
def _getenv(self, port): def _getenv(self):
env = os.environ.copy() env = os.environ.copy()
env['TESTTMP'] = self._testtmp env['TESTTMP'] = self._testtmp
env['HOME'] = self._testtmp env['HOME'] = self._testtmp
...@@ -598,9 +601,9 @@ ...@@ -598,9 +601,9 @@
env = os.environ.copy() env = os.environ.copy()
env['TESTTMP'] = self._testtmp env['TESTTMP'] = self._testtmp
env['HOME'] = self._testtmp env['HOME'] = self._testtmp
env["HGPORT"] = str(port) env["HGPORT"] = str(self._startport)
env["HGPORT1"] = str(port + 1) env["HGPORT1"] = str(self._startport + 1)
env["HGPORT2"] = str(port + 2) env["HGPORT2"] = str(self._startport + 2)
env["HGRCPATH"] = os.path.join(self._threadtmp, '.hgrc') env["HGRCPATH"] = os.path.join(self._threadtmp, '.hgrc')
env["DAEMON_PIDS"] = os.path.join(self._threadtmp, 'daemon.pids') env["DAEMON_PIDS"] = os.path.join(self._threadtmp, 'daemon.pids')
env["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"' env["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"'
...@@ -1507,9 +1510,9 @@ ...@@ -1507,9 +1510,9 @@
refpath = os.path.join(self.testdir, test) refpath = os.path.join(self.testdir, test)
tmpdir = os.path.join(self.hgtmp, 'child%d' % count) tmpdir = os.path.join(self.hgtmp, 'child%d' % count)
return testcls(self.options, refpath, count, tmpdir, self.abort, return testcls(self.options, refpath, tmpdir, self.abort,
keeptmpdir=self.options.keep_tmpdir, keeptmpdir=self.options.keep_tmpdir,
debug=self.options.debug, debug=self.options.debug,
nodiff = self.options.nodiff, nodiff = self.options.nodiff,
diffviewer=self.options.view, diffviewer=self.options.view,
interactive=self.options.interactive, interactive=self.options.interactive,
...@@ -1511,9 +1514,10 @@ ...@@ -1511,9 +1514,10 @@
keeptmpdir=self.options.keep_tmpdir, keeptmpdir=self.options.keep_tmpdir,
debug=self.options.debug, debug=self.options.debug,
nodiff = self.options.nodiff, nodiff = self.options.nodiff,
diffviewer=self.options.view, diffviewer=self.options.view,
interactive=self.options.interactive, interactive=self.options.interactive,
timeout=self.options.timeout) timeout=self.options.timeout,
startport=self.options.port + count * 3)
def _cleanup(self): def _cleanup(self):
"""Clean up state from this test invocation.""" """Clean up state from this test invocation."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment