##// END OF EJS Templates
run-tests: refactor port number declaration...
Gregory Szorc -
r21514:59fe123d default
parent child Browse files
Show More
@@ -338,17 +338,16 b' class Test(unittest.TestCase):'
338 338 # Status code reserved for skipped tests (used by hghave).
339 339 SKIPPED_STATUS = 80
340 340
341 def __init__(self, options, path, count, tmpdir, abort, keeptmpdir=False,
341 def __init__(self, options, path, tmpdir, abort, keeptmpdir=False,
342 342 debug=False, nodiff=False, diffviewer=None,
343 interactive=False, timeout=defaults['timeout']):
343 interactive=False, timeout=defaults['timeout'],
344 startport=defaults['port']):
344 345 """Create a test from parameters.
345 346
346 347 options are parsed command line options that control test execution.
347 348
348 349 path is the full path to the file defining the test.
349 350
350 count is an identifier used to denote this test instance.
351
352 351 tmpdir is the main temporary directory to use for this test.
353 352
354 353 abort is a flag that turns to True if test execution should be aborted.
@@ -369,6 +368,11 b' class Test(unittest.TestCase):'
369 368
370 369 timeout controls the maximum run time of the test. It is ignored when
371 370 debug is True.
371
372 startport controls the starting port number to use for this test. Each
373 test will reserve 3 port numbers for execution. It is the caller's
374 responsibility to allocate a non-overlapping port range to Test
375 instances.
372 376 """
373 377
374 378 self.path = path
@@ -377,7 +381,6 b' class Test(unittest.TestCase):'
377 381 self.errpath = os.path.join(self._testdir, '%s.err' % self.name)
378 382
379 383 self._options = options
380 self._count = count
381 384 self._threadtmp = tmpdir
382 385 self._abort = abort
383 386 self._keeptmpdir = keeptmpdir
@@ -386,6 +389,7 b' class Test(unittest.TestCase):'
386 389 self._diffviewer = diffviewer
387 390 self._interactive = interactive
388 391 self._timeout = timeout
392 self._startport = startport
389 393 self._daemonpids = []
390 394
391 395 self._finished = None
@@ -487,8 +491,8 b' class Test(unittest.TestCase):'
487 491
488 492 This will return a tuple describing the result of the test.
489 493 """
490 replacements, port = self._getreplacements()
491 env = self._getenv(port)
494 replacements = self._getreplacements()
495 env = self._getenv()
492 496 self._daemonpids.append(env['DAEMON_PIDS'])
493 497 self._createhgrc(env['HGRCPATH'])
494 498
@@ -577,11 +581,10 b' class Test(unittest.TestCase):'
577 581 raise SkipTest('unknown test type')
578 582
579 583 def _getreplacements(self):
580 port = self._options.port + self._count * 3
581 584 r = [
582 (r':%s\b' % port, ':$HGPORT'),
583 (r':%s\b' % (port + 1), ':$HGPORT1'),
584 (r':%s\b' % (port + 2), ':$HGPORT2'),
585 (r':%s\b' % self._startport, ':$HGPORT'),
586 (r':%s\b' % (self._startport + 1), ':$HGPORT1'),
587 (r':%s\b' % (self._startport + 2), ':$HGPORT2'),
585 588 ]
586 589
587 590 if os.name == 'nt':
@@ -592,15 +595,15 b' class Test(unittest.TestCase):'
592 595 else:
593 596 r.append((re.escape(self._testtmp), '$TESTTMP'))
594 597
595 return r, port
598 return r
596 599
597 def _getenv(self, port):
600 def _getenv(self):
598 601 env = os.environ.copy()
599 602 env['TESTTMP'] = self._testtmp
600 603 env['HOME'] = self._testtmp
601 env["HGPORT"] = str(port)
602 env["HGPORT1"] = str(port + 1)
603 env["HGPORT2"] = str(port + 2)
604 env["HGPORT"] = str(self._startport)
605 env["HGPORT1"] = str(self._startport + 1)
606 env["HGPORT2"] = str(self._startport + 2)
604 607 env["HGRCPATH"] = os.path.join(self._threadtmp, '.hgrc')
605 608 env["DAEMON_PIDS"] = os.path.join(self._threadtmp, 'daemon.pids')
606 609 env["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"'
@@ -1507,13 +1510,14 b' class TestRunner(object):'
1507 1510 refpath = os.path.join(self.testdir, test)
1508 1511 tmpdir = os.path.join(self.hgtmp, 'child%d' % count)
1509 1512
1510 return testcls(self.options, refpath, count, tmpdir, self.abort,
1513 return testcls(self.options, refpath, tmpdir, self.abort,
1511 1514 keeptmpdir=self.options.keep_tmpdir,
1512 1515 debug=self.options.debug,
1513 1516 nodiff = self.options.nodiff,
1514 1517 diffviewer=self.options.view,
1515 1518 interactive=self.options.interactive,
1516 timeout=self.options.timeout)
1519 timeout=self.options.timeout,
1520 startport=self.options.port + count * 3)
1517 1521
1518 1522 def _cleanup(self):
1519 1523 """Clean up state from this test invocation."""
General Comments 0
You need to be logged in to leave comments. Login now