changeset 18057:6b88ded2a993

run-tests: support running tests in parallel on windows Previously, we used os.spawnvp, which doesn't exist on Windows, and isn't needed anyway (the command line begins with an absolute path). We also need a slightly more convoluted way to wait for processes without specifying an order on Windows, as it lacks os.wait.
author Bryan O'Sullivan <bryano@fb.com>
date Tue, 11 Dec 2012 15:13:23 -0800
parents 7c9b07f0da73
children fe5a41144982
files tests/run-tests.py
diffstat 1 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Tue Dec 11 13:44:00 2012 -0800
+++ b/tests/run-tests.py	Tue Dec 11 15:13:23 2012 -0800
@@ -56,6 +56,7 @@
 import threading
 import killdaemons as killmod
 import cPickle as pickle
+import Queue as queue
 
 processlock = threading.Lock()
 
@@ -1079,7 +1080,13 @@
                 blacklisted.append(test)
             else:
                 job.append(test)
-    fps = {}
+
+    waitq = queue.Queue()
+
+    # windows lacks os.wait, so we must emulate it
+    def waitfor(proc, rfd):
+        fp = os.fdopen(rfd, 'rb')
+        return lambda: waitq.put((proc.pid, proc.wait(), fp))
 
     for j, job in enumerate(jobs):
         if not job:
@@ -1090,16 +1097,18 @@
         childopts += ['--tmpdir', childtmp]
         cmdline = [PYTHON, sys.argv[0]] + opts + childopts + job
         vlog(' '.join(cmdline))
-        fps[os.spawnvp(os.P_NOWAIT, cmdline[0], cmdline)] = os.fdopen(rfd, 'rb')
+        proc = subprocess.Popen(cmdline, executable=cmdline[0])
+        threading.Thread(target=waitfor(proc, rfd)).start()
         os.close(wfd)
     signal.signal(signal.SIGINT, signal.SIG_IGN)
     failures = 0
     passed, skipped, failed = 0, 0, 0
     skips = []
     fails = []
-    while fps:
-        pid, status = os.wait()
-        fp = fps.pop(pid)
+    for job in jobs:
+        if not job:
+            continue
+        pid, status, fp = waitq.get()
         try:
             childresults = pickle.load(fp)
         except pickle.UnpicklingError: