From patchwork Fri May 2 18:38:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [067, of, 179, tests-refactor] run-tests: move scheduletests() into TestRunner From: Gregory Szorc X-Patchwork-Id: 4562 Message-Id: <753aa4f617abdc39a66b.1399055904@vm-ubuntu-main.gateway.sonic.net> To: mercurial-devel@selenic.com Date: Fri, 02 May 2014 11:38:24 -0700 # HG changeset patch # User Gregory Szorc # Date 1397977946 25200 # Sun Apr 20 00:12:26 2014 -0700 # Branch stable # Node ID 753aa4f617abdc39a66ba6499a9cf61b60fe3da8 # Parent 6a947b763b92cf759912ef4c5e4d7991b9f2d388 run-tests: move scheduletests() into TestRunner diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -988,55 +988,16 @@ def _gethgpath(): try: _hgpath = pipe.read().strip() finally: pipe.close() return _hgpath iolock = threading.Lock() -def scheduletests(runner, tests): - jobs = runner.options.jobs - done = queue.Queue() - running = 0 - count = 0 - - def job(test, count): - try: - t = runner.gettest(test, count) - done.put(t.run()) - del t # For side-effects. - except KeyboardInterrupt: - pass - except: # re-raises - done.put(('!', test, 'run-test raised an error, see traceback')) - raise - - try: - while tests or running: - if not done.empty() or running == jobs or not tests: - try: - code, test, msg = done.get(True, 1) - runner.results[code].append((test, msg)) - if runner.options.first and code not in '.si': - break - except queue.Empty: - continue - running -= 1 - if tests and not running == jobs: - test = tests.pop(0) - if runner.options.loop: - tests.append(test) - t = threading.Thread(target=job, name=test, args=(test, count)) - t.start() - running += 1 - count += 1 - except KeyboardInterrupt: - runner.abort[0] = True - class TestRunner(object): """Holds context for executing tests. Tests rely on a lot of state. This object holds it for them. """ TESTTYPES = [ ('.py', PythonTest, '.out'), @@ -1076,17 +1037,17 @@ class TestRunner(object): while tests: if os.path.exists(tests[0] + ".err"): break tests.pop(0) if not tests: print "running all tests" tests = orig - scheduletests(self, tests) + self._executetests(tests) failed = len(self.results['!']) warned = len(self.results['~']) tested = len(self.results['.']) + failed + warned skipped = len(self.results['s']) ignored = len(self.results['i']) print @@ -1304,16 +1265,56 @@ class TestRunner(object): covrun('-i', '-b', '"--directory=%s"' % htmldir, '"--omit=%s"' % omit) if self.options.annotate: adir = os.path.join(self.testdir, 'annotated') if not os.path.isdir(adir): os.mkdir(adir) covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit) + def _executetests(self, tests): + jobs = self.options.jobs + done = queue.Queue() + running = 0 + count = 0 + + def job(test, count): + try: + t = self.gettest(test, count) + done.put(t.run()) + del t # For side-effects. + except KeyboardInterrupt: + pass + except: # re-raises + done.put(('!', test, 'run-test raised an error, see traceback')) + raise + + try: + while tests or running: + if not done.empty() or running == jobs or not tests: + try: + code, test, msg = done.get(True, 1) + self.results[code].append((test, msg)) + if self.options.first and code not in '.si': + break + except queue.Empty: + continue + running -= 1 + if tests and not running == jobs: + test = tests.pop(0) + if self.options.loop: + tests.append(test) + t = threading.Thread(target=job, name=test, + args=(test, count)) + t.start() + running += 1 + count += 1 + except KeyboardInterrupt: + self.abort[0] = True + def main(args, parser=None): runner = TestRunner() parser = parser or getparser() (options, args) = parseargs(args, parser) runner.options = options os.umask(022)