Commit 1f7b742b authored by Ben Joyce's avatar Ben Joyce Committed by Commit Bot

Buffer the output from processes.

Collect the outputs and print it out as it would be if not ran in
parallel.

Bug: 1138506
Change-Id: I92a3e098f7ef4a02bfcf51d948810db91bf7d0bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2535668Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarPeter Wen <wnwen@chromium.org>
Commit-Queue: benjamin joyce <bjoyce@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828022}
parent c4995a76
......@@ -2,11 +2,14 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import collections
import json
import logging
import multiprocessing
import os
import select
import subprocess
import sys
import zipfile
from pylib import constants
......@@ -141,9 +144,12 @@ class LocalMachineJunitTestRun(test_run.TestRun):
AddPropertiesJar(cmd_list, temp_dir, self._test_instance.resource_apk)
procs = [subprocess.Popen(cmd) for cmd in cmd_list]
for proc in procs:
proc.wait()
procs = [
subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT) for cmd in cmd_list
]
PrintProcessesStdout(procs)
results_list = []
try:
......@@ -218,6 +224,38 @@ def GroupTestsForShard(num_of_shards, test_classes):
return test_dict
def PrintProcessesStdout(procs):
"""Prints the stdout of all the processes.
Buffers the stdout of the processes and prints it when finished.
Args:
procs: A list of subprocesses.
Returns: N/A
"""
streams = [p.stdout for p in procs]
outputs = collections.defaultdict(list)
first_fd = streams[0].fileno()
while streams:
rstreams, _, _ = select.select(streams, [], [])
for stream in rstreams:
line = stream.readline()
if line:
# Print out just one output so user can see work being done rather
# than waiting for it all at the end.
if stream.fileno() == first_fd:
sys.stdout.write(line)
else:
outputs[stream.fileno()].append(line)
else:
streams.remove(stream) # End of stream.
for p in procs:
sys.stdout.write(''.join(outputs[p.stdout.fileno()]))
def _GetTestClasses(file_path):
test_jar_paths = subprocess.check_output([file_path, '--print-classpath'])
test_jar_paths = test_jar_paths.split(':')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment