pull/19988/head
Richard Belleville 5 years ago
parent ca2fcd647a
commit 84855a18a9
  1. 16
      src/python/grpcio_tests/tests/unit/_signal_client.py
  2. 7
      src/python/grpcio_tests/tests/unit/_signal_handling_test.py

@ -79,31 +79,33 @@ def main_unary_with_exception(server_target):
try: try:
channel.unary_unary(UNARY_UNARY)(_MESSAGE, wait_for_ready=True) channel.unary_unary(UNARY_UNARY)(_MESSAGE, wait_for_ready=True)
except KeyboardInterrupt: except KeyboardInterrupt:
sys.stderr.write("Running signal handler.\n"); sys.stderr.flush() sys.stderr.write("Running signal handler.\n")
sys.stderr.flush()
sys.stderr.write("Calling Channel.close()"); sys.stderr.flush()
# This call should not hang. # This call should not hang.
channel.close() channel.close()
def main_streaming_with_exception(server_target): def main_streaming_with_exception(server_target):
"""Initiate an RPC with wait_for_ready set and no server backing the RPC.""" """Initiate an RPC with wait_for_ready set and no server backing the RPC."""
channel = grpc.insecure_channel(server_target) channel = grpc.insecure_channel(server_target)
try: try:
channel.unary_stream(UNARY_STREAM)(_MESSAGE, wait_for_ready=True) channel.unary_stream(UNARY_STREAM)(_MESSAGE, wait_for_ready=True)
except KeyboardInterrupt: except KeyboardInterrupt:
sys.stderr.write("Running signal handler.\n"); sys.stderr.flush() sys.stderr.write("Running signal handler.\n")
sys.stderr.flush()
sys.stderr.write("Calling Channel.close()"); sys.stderr.flush()
# This call should not hang. # This call should not hang.
channel.close() channel.close()
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Signal test client.') parser = argparse.ArgumentParser(description='Signal test client.')
parser.add_argument('server', help='Server target') parser.add_argument('server', help='Server target')
parser.add_argument('arity', help='Arity', choices=('unary', 'streaming'))
parser.add_argument( parser.add_argument(
'arity', help='Arity', choices=('unary', 'streaming')) '--exception',
parser.add_argument( help='Whether the signal throws an exception',
'--exception', help='Whether the signal throws an exception',
action='store_true') action='store_true')
args = parser.parse_args() args = parser.parse_args()
if args.arity == 'unary' and not args.exception: if args.arity == 'unary' and not args.exception:

@ -13,7 +13,6 @@
# limitations under the License. # limitations under the License.
"""Test of responsiveness to signals.""" """Test of responsiveness to signals."""
import contextlib
import logging import logging
import os import os
import signal import signal
@ -21,7 +20,6 @@ import subprocess
import tempfile import tempfile
import threading import threading
import unittest import unittest
import socket
import sys import sys
import grpc import grpc
@ -185,8 +183,9 @@ class SignalHandlingTest(unittest.TestCase):
server_target = '{}:{}'.format(_HOST, self._port) server_target = '{}:{}'.format(_HOST, self._port)
with tempfile.TemporaryFile(mode='r') as client_stdout: with tempfile.TemporaryFile(mode='r') as client_stdout:
with tempfile.TemporaryFile(mode='r') as client_stderr: with tempfile.TemporaryFile(mode='r') as client_stderr:
client = _start_client(('--exception', server_target, 'streaming'), client = _start_client(
client_stdout, client_stderr) ('--exception', server_target, 'streaming'), client_stdout,
client_stderr)
self._handler.await_connected_client() self._handler.await_connected_client()
client.send_signal(signal.SIGINT) client.send_signal(signal.SIGINT)
client.wait() client.wait()

Loading…
Cancel
Save