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:
channel.unary_unary(UNARY_UNARY)(_MESSAGE, wait_for_ready=True)
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.
channel.close()
def main_streaming_with_exception(server_target):
"""Initiate an RPC with wait_for_ready set and no server backing the RPC."""
channel = grpc.insecure_channel(server_target)
try:
channel.unary_stream(UNARY_STREAM)(_MESSAGE, wait_for_ready=True)
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.
channel.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Signal test client.')
parser.add_argument('server', help='Server target')
parser.add_argument('arity', help='Arity', choices=('unary', 'streaming'))
parser.add_argument(
'arity', help='Arity', choices=('unary', 'streaming'))
parser.add_argument(
'--exception', help='Whether the signal throws an exception',
'--exception',
help='Whether the signal throws an exception',
action='store_true')
args = parser.parse_args()
if args.arity == 'unary' and not args.exception:

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

Loading…
Cancel
Save