|
|
|
@ -64,7 +64,10 @@ class _Handler(object): |
|
|
|
|
def handle_unary_unary(self, request, servicer_context): |
|
|
|
|
self._control.control() |
|
|
|
|
if servicer_context is not None: |
|
|
|
|
servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) |
|
|
|
|
servicer_context.set_trailing_metadata((( |
|
|
|
|
'testkey', |
|
|
|
|
'testvalue', |
|
|
|
|
),)) |
|
|
|
|
# TODO(https://github.com/grpc/grpc/issues/8483): test the values |
|
|
|
|
# returned by these methods rather than only "smoke" testing that |
|
|
|
|
# the return after having been called. |
|
|
|
@ -78,7 +81,10 @@ class _Handler(object): |
|
|
|
|
yield request |
|
|
|
|
self._control.control() |
|
|
|
|
if servicer_context is not None: |
|
|
|
|
servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) |
|
|
|
|
servicer_context.set_trailing_metadata((( |
|
|
|
|
'testkey', |
|
|
|
|
'testvalue', |
|
|
|
|
),)) |
|
|
|
|
|
|
|
|
|
def handle_stream_unary(self, request_iterator, servicer_context): |
|
|
|
|
if servicer_context is not None: |
|
|
|
@ -90,13 +96,19 @@ class _Handler(object): |
|
|
|
|
response_elements.append(request) |
|
|
|
|
self._control.control() |
|
|
|
|
if servicer_context is not None: |
|
|
|
|
servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) |
|
|
|
|
servicer_context.set_trailing_metadata((( |
|
|
|
|
'testkey', |
|
|
|
|
'testvalue', |
|
|
|
|
),)) |
|
|
|
|
return b''.join(response_elements) |
|
|
|
|
|
|
|
|
|
def handle_stream_stream(self, request_iterator, servicer_context): |
|
|
|
|
self._control.control() |
|
|
|
|
if servicer_context is not None: |
|
|
|
|
servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) |
|
|
|
|
servicer_context.set_trailing_metadata((( |
|
|
|
|
'testkey', |
|
|
|
|
'testvalue', |
|
|
|
|
),)) |
|
|
|
|
for request in request_iterator: |
|
|
|
|
self._control.control() |
|
|
|
|
yield request |
|
|
|
@ -244,8 +256,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
self.assertSequenceEqual(expected_responses, responses) |
|
|
|
|
|
|
|
|
|
def testSuccessfulStreamRequestBlockingUnaryResponse(self): |
|
|
|
|
requests = tuple(b'\x07\x08' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
expected_response = self._handler.handle_stream_unary( |
|
|
|
|
iter(requests), None) |
|
|
|
|
request_iterator = iter(requests) |
|
|
|
@ -253,14 +265,14 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
multi_callable = _stream_unary_multi_callable(self._channel) |
|
|
|
|
response = multi_callable( |
|
|
|
|
request_iterator, |
|
|
|
|
metadata=( |
|
|
|
|
('test', 'SuccessfulStreamRequestBlockingUnaryResponse'),)) |
|
|
|
|
metadata=(('test', |
|
|
|
|
'SuccessfulStreamRequestBlockingUnaryResponse'),)) |
|
|
|
|
|
|
|
|
|
self.assertEqual(expected_response, response) |
|
|
|
|
|
|
|
|
|
def testSuccessfulStreamRequestBlockingUnaryResponseWithCall(self): |
|
|
|
|
requests = tuple(b'\x07\x08' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
expected_response = self._handler.handle_stream_unary( |
|
|
|
|
iter(requests), None) |
|
|
|
|
request_iterator = iter(requests) |
|
|
|
@ -276,8 +288,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
self.assertIs(grpc.StatusCode.OK, call.code()) |
|
|
|
|
|
|
|
|
|
def testSuccessfulStreamRequestFutureUnaryResponse(self): |
|
|
|
|
requests = tuple(b'\x07\x08' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
expected_response = self._handler.handle_stream_unary( |
|
|
|
|
iter(requests), None) |
|
|
|
|
request_iterator = iter(requests) |
|
|
|
@ -293,8 +305,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
self.assertIsNone(response_future.traceback()) |
|
|
|
|
|
|
|
|
|
def testSuccessfulStreamRequestStreamResponse(self): |
|
|
|
|
requests = tuple(b'\x77\x58' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x77\x58' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
expected_responses = tuple( |
|
|
|
|
self._handler.handle_stream_stream(iter(requests), None)) |
|
|
|
|
request_iterator = iter(requests) |
|
|
|
@ -326,8 +338,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
|
|
|
|
|
def testConcurrentBlockingInvocations(self): |
|
|
|
|
pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) |
|
|
|
|
requests = tuple(b'\x07\x08' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
expected_response = self._handler.handle_stream_unary( |
|
|
|
|
iter(requests), None) |
|
|
|
|
expected_responses = [expected_response |
|
|
|
@ -342,15 +354,15 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
request_iterator, |
|
|
|
|
metadata=(('test', 'ConcurrentBlockingInvocations'),)) |
|
|
|
|
response_futures[index] = response_future |
|
|
|
|
responses = tuple(response_future.result() |
|
|
|
|
for response_future in response_futures) |
|
|
|
|
responses = tuple( |
|
|
|
|
response_future.result() for response_future in response_futures) |
|
|
|
|
|
|
|
|
|
pool.shutdown(wait=True) |
|
|
|
|
self.assertSequenceEqual(expected_responses, responses) |
|
|
|
|
|
|
|
|
|
def testConcurrentFutureInvocations(self): |
|
|
|
|
requests = tuple(b'\x07\x08' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
expected_response = self._handler.handle_stream_unary( |
|
|
|
|
iter(requests), None) |
|
|
|
|
expected_responses = [expected_response |
|
|
|
@ -364,8 +376,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
request_iterator, |
|
|
|
|
metadata=(('test', 'ConcurrentFutureInvocations'),)) |
|
|
|
|
response_futures[index] = response_future |
|
|
|
|
responses = tuple(response_future.result() |
|
|
|
|
for response_future in response_futures) |
|
|
|
|
responses = tuple( |
|
|
|
|
response_future.result() for response_future in response_futures) |
|
|
|
|
|
|
|
|
|
self.assertSequenceEqual(expected_responses, responses) |
|
|
|
|
|
|
|
|
@ -424,14 +436,14 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
multi_callable = _unary_stream_multi_callable(self._channel) |
|
|
|
|
response_iterator = multi_callable( |
|
|
|
|
request, |
|
|
|
|
metadata=( |
|
|
|
|
('test', 'ConsumingSomeButNotAllStreamResponsesUnaryRequest'),)) |
|
|
|
|
metadata=(('test', |
|
|
|
|
'ConsumingSomeButNotAllStreamResponsesUnaryRequest'),)) |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH // 2): |
|
|
|
|
next(response_iterator) |
|
|
|
|
|
|
|
|
|
def testConsumingSomeButNotAllStreamResponsesStreamRequest(self): |
|
|
|
|
requests = tuple(b'\x67\x88' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x67\x88' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
request_iterator = iter(requests) |
|
|
|
|
|
|
|
|
|
multi_callable = _stream_stream_multi_callable(self._channel) |
|
|
|
@ -443,15 +455,15 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
next(response_iterator) |
|
|
|
|
|
|
|
|
|
def testConsumingTooManyStreamResponsesStreamRequest(self): |
|
|
|
|
requests = tuple(b'\x67\x88' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x67\x88' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
request_iterator = iter(requests) |
|
|
|
|
|
|
|
|
|
multi_callable = _stream_stream_multi_callable(self._channel) |
|
|
|
|
response_iterator = multi_callable( |
|
|
|
|
request_iterator, |
|
|
|
|
metadata=( |
|
|
|
|
('test', 'ConsumingTooManyStreamResponsesStreamRequest'),)) |
|
|
|
|
metadata=(('test', |
|
|
|
|
'ConsumingTooManyStreamResponsesStreamRequest'),)) |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH): |
|
|
|
|
next(response_iterator) |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH): |
|
|
|
@ -503,8 +515,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
self.assertIsNotNone(response_iterator.trailing_metadata()) |
|
|
|
|
|
|
|
|
|
def testCancelledStreamRequestUnaryResponse(self): |
|
|
|
|
requests = tuple(b'\x07\x08' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
request_iterator = iter(requests) |
|
|
|
|
|
|
|
|
|
multi_callable = _stream_unary_multi_callable(self._channel) |
|
|
|
@ -528,8 +540,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
self.assertIsNotNone(response_future.trailing_metadata()) |
|
|
|
|
|
|
|
|
|
def testCancelledStreamRequestStreamResponse(self): |
|
|
|
|
requests = tuple(b'\x07\x08' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
request_iterator = iter(requests) |
|
|
|
|
|
|
|
|
|
multi_callable = _stream_stream_multi_callable(self._channel) |
|
|
|
@ -555,8 +567,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
multi_callable.with_call( |
|
|
|
|
request, |
|
|
|
|
timeout=test_constants.SHORT_TIMEOUT, |
|
|
|
|
metadata=( |
|
|
|
|
('test', 'ExpiredUnaryRequestBlockingUnaryResponse'),)) |
|
|
|
|
metadata=(('test', |
|
|
|
|
'ExpiredUnaryRequestBlockingUnaryResponse'),)) |
|
|
|
|
|
|
|
|
|
self.assertIsInstance(exception_context.exception, grpc.Call) |
|
|
|
|
self.assertIsNotNone(exception_context.exception.initial_metadata()) |
|
|
|
@ -610,8 +622,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
response_iterator.code()) |
|
|
|
|
|
|
|
|
|
def testExpiredStreamRequestBlockingUnaryResponse(self): |
|
|
|
|
requests = tuple(b'\x07\x08' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
request_iterator = iter(requests) |
|
|
|
|
|
|
|
|
|
multi_callable = _stream_unary_multi_callable(self._channel) |
|
|
|
@ -620,8 +632,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
multi_callable( |
|
|
|
|
request_iterator, |
|
|
|
|
timeout=test_constants.SHORT_TIMEOUT, |
|
|
|
|
metadata=( |
|
|
|
|
('test', 'ExpiredStreamRequestBlockingUnaryResponse'),)) |
|
|
|
|
metadata=(('test', |
|
|
|
|
'ExpiredStreamRequestBlockingUnaryResponse'),)) |
|
|
|
|
|
|
|
|
|
self.assertIsInstance(exception_context.exception, grpc.RpcError) |
|
|
|
|
self.assertIsInstance(exception_context.exception, grpc.Call) |
|
|
|
@ -632,8 +644,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
self.assertIsNotNone(exception_context.exception.trailing_metadata()) |
|
|
|
|
|
|
|
|
|
def testExpiredStreamRequestFutureUnaryResponse(self): |
|
|
|
|
requests = tuple(b'\x07\x18' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x07\x18' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
request_iterator = iter(requests) |
|
|
|
|
callback = _Callback() |
|
|
|
|
|
|
|
|
@ -644,8 +656,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
timeout=test_constants.SHORT_TIMEOUT, |
|
|
|
|
metadata=(('test', 'ExpiredStreamRequestFutureUnaryResponse'),)) |
|
|
|
|
with self.assertRaises(grpc.FutureTimeoutError): |
|
|
|
|
response_future.result(timeout=test_constants.SHORT_TIMEOUT / |
|
|
|
|
2.0) |
|
|
|
|
response_future.result( |
|
|
|
|
timeout=test_constants.SHORT_TIMEOUT / 2.0) |
|
|
|
|
response_future.add_done_callback(callback) |
|
|
|
|
value_passed_to_callback = callback.value() |
|
|
|
|
|
|
|
|
@ -663,8 +675,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
self.assertIsNotNone(response_future.trailing_metadata()) |
|
|
|
|
|
|
|
|
|
def testExpiredStreamRequestStreamResponse(self): |
|
|
|
|
requests = tuple(b'\x67\x18' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x67\x18' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
request_iterator = iter(requests) |
|
|
|
|
|
|
|
|
|
multi_callable = _stream_stream_multi_callable(self._channel) |
|
|
|
@ -689,8 +701,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
with self.assertRaises(grpc.RpcError) as exception_context: |
|
|
|
|
multi_callable.with_call( |
|
|
|
|
request, |
|
|
|
|
metadata=( |
|
|
|
|
('test', 'FailedUnaryRequestBlockingUnaryResponse'),)) |
|
|
|
|
metadata=(('test', |
|
|
|
|
'FailedUnaryRequestBlockingUnaryResponse'),)) |
|
|
|
|
|
|
|
|
|
self.assertIs(grpc.StatusCode.UNKNOWN, |
|
|
|
|
exception_context.exception.code()) |
|
|
|
@ -734,8 +746,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
exception_context.exception.code()) |
|
|
|
|
|
|
|
|
|
def testFailedStreamRequestBlockingUnaryResponse(self): |
|
|
|
|
requests = tuple(b'\x47\x58' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x47\x58' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
request_iterator = iter(requests) |
|
|
|
|
|
|
|
|
|
multi_callable = _stream_unary_multi_callable(self._channel) |
|
|
|
@ -743,15 +755,15 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
with self.assertRaises(grpc.RpcError) as exception_context: |
|
|
|
|
multi_callable( |
|
|
|
|
request_iterator, |
|
|
|
|
metadata=( |
|
|
|
|
('test', 'FailedStreamRequestBlockingUnaryResponse'),)) |
|
|
|
|
metadata=(('test', |
|
|
|
|
'FailedStreamRequestBlockingUnaryResponse'),)) |
|
|
|
|
|
|
|
|
|
self.assertIs(grpc.StatusCode.UNKNOWN, |
|
|
|
|
exception_context.exception.code()) |
|
|
|
|
|
|
|
|
|
def testFailedStreamRequestFutureUnaryResponse(self): |
|
|
|
|
requests = tuple(b'\x07\x18' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x07\x18' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
request_iterator = iter(requests) |
|
|
|
|
callback = _Callback() |
|
|
|
|
|
|
|
|
@ -773,8 +785,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
self.assertIs(response_future, value_passed_to_callback) |
|
|
|
|
|
|
|
|
|
def testFailedStreamRequestStreamResponse(self): |
|
|
|
|
requests = tuple(b'\x67\x88' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x67\x88' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
request_iterator = iter(requests) |
|
|
|
|
|
|
|
|
|
multi_callable = _stream_stream_multi_callable(self._channel) |
|
|
|
@ -805,8 +817,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
request, metadata=(('test', 'IgnoredUnaryRequestStreamResponse'),)) |
|
|
|
|
|
|
|
|
|
def testIgnoredStreamRequestFutureUnaryResponse(self): |
|
|
|
|
requests = tuple(b'\x07\x18' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x07\x18' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
request_iterator = iter(requests) |
|
|
|
|
|
|
|
|
|
multi_callable = _stream_unary_multi_callable(self._channel) |
|
|
|
@ -815,8 +827,8 @@ class RPCTest(unittest.TestCase): |
|
|
|
|
metadata=(('test', 'IgnoredStreamRequestFutureUnaryResponse'),)) |
|
|
|
|
|
|
|
|
|
def testIgnoredStreamRequestStreamResponse(self): |
|
|
|
|
requests = tuple(b'\x67\x88' |
|
|
|
|
for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
requests = tuple( |
|
|
|
|
b'\x67\x88' for _ in range(test_constants.STREAM_LENGTH)) |
|
|
|
|
request_iterator = iter(requests) |
|
|
|
|
|
|
|
|
|
multi_callable = _stream_stream_multi_callable(self._channel) |
|
|
|
|