Mercurial > hg
changeset 21528:32b9bbca2052
run-tests: pass jobs into TestSuite constructor
This starts a series of patches that will lessen the importance of
TestRunner. It will remove the TestRunner instance stored inside the
TestSuite.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 25 Apr 2014 14:51:53 -0700 |
parents | 1f05a7bcde50 |
children | 117e027390ab |
files | tests/run-tests.py |
diffstat | 1 files changed, 12 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/run-tests.py Fri May 16 13:15:07 2014 -0700 +++ b/tests/run-tests.py Fri Apr 25 14:51:53 2014 -0700 @@ -1151,12 +1151,19 @@ test.name, self.times[-1][1])) class TestSuite(unittest.TestSuite): - """Custom unitest TestSuite that knows how to execute concurrently.""" + """Custom unitest TestSuite that knows how to execute Mercurial tests.""" + + def __init__(self, runner, jobs=1, *args, **kwargs): + """Create a new instance that can run tests with a configuration. - def __init__(self, runner, *args, **kwargs): + jobs specifies the number of jobs to run concurrently. Each test + executes on its own thread. Tests actually spawn new processes, so + state mutation should not be an issue. + """ super(TestSuite, self).__init__(*args, **kwargs) self._runner = runner + self._jobs = jobs def run(self, result): options = self._runner.options @@ -1196,7 +1203,6 @@ tests.append(test) runtests = list(tests) - jobs = self._runner.options.jobs done = queue.Queue() running = 0 @@ -1212,7 +1218,7 @@ try: while tests or running: - if not done.empty() or running == jobs or not tests: + if not done.empty() or running == self._jobs or not tests: try: done.get(True, 1) if result and result.shouldStop: @@ -1220,7 +1226,7 @@ except queue.Empty: continue running -= 1 - if tests and not running == jobs: + if tests and not running == self._jobs: test = tests.pop(0) if self._runner.options.loop: tests.append(test) @@ -1483,7 +1489,7 @@ failed = False warned = False - suite = TestSuite(self, tests=tests) + suite = TestSuite(self, jobs=self.options.jobs, tests=tests) verbosity = 1 if self.options.verbose: verbosity = 2