Make runner support single threaded mode

pull/20771/head
Lidi Zheng 5 years ago
parent 58cdbe7a83
commit e2dcb2883d
  1. 2
      src/python/grpcio_tests/commands.py
  2. 13
      src/python/grpcio_tests/tests/_runner.py

@ -127,7 +127,7 @@ class TestAio(setuptools.Command):
import tests
loader = tests.Loader()
loader.loadTestsFromNames(['tests_aio'])
runner = tests.Runner()
runner = tests.Runner(dedicated_threads=False)
result = runner.run(loader.suite)
if not result.wasSuccessful():
sys.exit('Test failure')

@ -117,8 +117,15 @@ class AugmentedCase(collections.namedtuple('AugmentedCase', ['case', 'id'])):
class Runner(object):
def __init__(self):
def __init__(self, dedicated_threads=True):
"""Constructs the Runner object.
Args:
dedicated_threads: A bool indicates whether to spawn each unit test
in separate thread or not.
"""
self._skipped_tests = []
self._dedicated_threads = dedicated_threads
def skip_tests(self, tests):
self._skipped_tests = tests
@ -194,6 +201,7 @@ class Runner(object):
sys.stdout.write('Running {}\n'.format(
augmented_case.case.id()))
sys.stdout.flush()
if self._dedicated_threads:
case_thread = threading.Thread(
target=augmented_case.case.run, args=(result,))
try:
@ -212,6 +220,8 @@ class Runner(object):
sys.stdout.flush()
result_out.truncate(0)
check_kill_self()
else:
augmented_case.case.run(result)
result.stopTestRun()
stdout_pipe.close()
stderr_pipe.close()
@ -223,3 +233,4 @@ class Runner(object):
with open('report.xml', 'wb') as report_xml_file:
_result.jenkins_junit_xml(result).write(report_xml_file)
return result

Loading…
Cancel
Save