Turn the single threaded runner on by default.

pull/20771/head
Lidi Zheng 5 years ago
parent c66bdcdbe0
commit 2fbd97217b
  1. 6
      src/python/grpcio_tests/tests/_runner.py
  2. 4
      src/python/grpcio_tests/tests_aio/unit/_test_server.py

@ -117,7 +117,7 @@ class AugmentedCase(collections.namedtuple('AugmentedCase', ['case', 'id'])):
class Runner(object): class Runner(object):
def __init__(self, dedicated_threads=True): def __init__(self, dedicated_threads=False):
"""Constructs the Runner object. """Constructs the Runner object.
Args: Args:
@ -202,11 +202,13 @@ class Runner(object):
augmented_case.case.id())) augmented_case.case.id()))
sys.stdout.flush() sys.stdout.flush()
if self._dedicated_threads: if self._dedicated_threads:
# (Deprecated) Spawns dedicated thread for each test case.
case_thread = threading.Thread( case_thread = threading.Thread(
target=augmented_case.case.run, args=(result,)) target=augmented_case.case.run, args=(result,))
try: try:
with stdout_pipe, stderr_pipe: with stdout_pipe, stderr_pipe:
case_thread.start() case_thread.start()
# If the thread is exited unexpected, stop testing.
while case_thread.is_alive(): while case_thread.is_alive():
check_kill_self() check_kill_self()
time.sleep(0) time.sleep(0)
@ -214,6 +216,7 @@ class Runner(object):
except: # pylint: disable=try-except-raise except: # pylint: disable=try-except-raise
# re-raise the exception after forcing the with-block to end # re-raise the exception after forcing the with-block to end
raise raise
# Records the result of the test case run.
result.set_output(augmented_case.case, stdout_pipe.output(), result.set_output(augmented_case.case, stdout_pipe.output(),
stderr_pipe.output()) stderr_pipe.output())
sys.stdout.write(result_out.getvalue()) sys.stdout.write(result_out.getvalue())
@ -221,6 +224,7 @@ class Runner(object):
result_out.truncate(0) result_out.truncate(0)
check_kill_self() check_kill_self()
else: else:
# Donates current thread to test case execution.
augmented_case.case.run(result) augmented_case.case.run(result)
result.stopTestRun() result.stopTestRun()
stdout_pipe.close() stdout_pipe.close()

@ -24,7 +24,7 @@ from src.proto.grpc.testing import test_pb2_grpc
from tests.unit.framework.common import test_constants from tests.unit.framework.common import test_constants
class TestServiceServicer(test_pb2_grpc.TestServiceServicer): class _TestServiceServicer(test_pb2_grpc.TestServiceServicer):
async def UnaryCall(self, request, context): async def UnaryCall(self, request, context):
return messages_pb2.SimpleResponse() return messages_pb2.SimpleResponse()
@ -36,7 +36,7 @@ class TestServiceServicer(test_pb2_grpc.TestServiceServicer):
async def start_test_server(): async def start_test_server():
server = aio.server(options=(('grpc.so_reuseport', 0),)) server = aio.server(options=(('grpc.so_reuseport', 0),))
test_pb2_grpc.add_TestServiceServicer_to_server(TestServiceServicer(), test_pb2_grpc.add_TestServiceServicer_to_server(_TestServiceServicer(),
server) server)
port = server.add_insecure_port('[::]:0') port = server.add_insecure_port('[::]:0')
await server.start() await server.start()

Loading…
Cancel
Save