Patchwork [067,of,179,tests-refactor] run-tests: move scheduletests() into TestRunner

login
register
mail settings
Submitter Gregory Szorc
Date May 2, 2014, 6:38 p.m.
Message ID <753aa4f617abdc39a66b.1399055904@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4562/
State Accepted
Commit ff4ce72cc8d6407ca0298aa1091bd4bc98b0dbba
Headers show

Comments

Gregory Szorc - May 2, 2014, 6:38 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397977946 25200
#      Sun Apr 20 00:12:26 2014 -0700
# Branch stable
# Node ID 753aa4f617abdc39a66ba6499a9cf61b60fe3da8
# Parent  6a947b763b92cf759912ef4c5e4d7991b9f2d388
run-tests: move scheduletests() into TestRunner

Patch

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)