Fix metadata tests

pull/20753/head
Richard Belleville 5 years ago
parent 5f5e9e2695
commit dd7b04c088
  1. 14
      src/python/grpcio_tests/tests/unit/_metadata_code_details_test.py
  2. 3
      src/python/grpcio_tests/tests/unit/_metadata_test.py

@ -255,8 +255,8 @@ class MetadataCodeDetailsTest(unittest.TestCase):
response_iterator_call = self._unary_stream(
_SERIALIZED_REQUEST, metadata=_CLIENT_METADATA)
received_initial_metadata = response_iterator_call.initial_metadata()
list(response_iterator_call)
received_initial_metadata = response_iterator_call.initial_metadata()
self.assertTrue(
test_common.metadata_transmitted(
@ -347,13 +347,17 @@ class MetadataCodeDetailsTest(unittest.TestCase):
self._servicer.set_details(_DETAILS)
self._servicer.set_abort_call()
response_iterator_call = self._unary_stream(
_SERIALIZED_REQUEST, metadata=_CLIENT_METADATA)
received_initial_metadata = \
response_iterator_call.initial_metadata()
# NOTE: In the single-threaded case, we cannot grab the initial_metadata
# without running the RPC first (or concurrently, in another
# thread).
with self.assertRaises(grpc.RpcError):
self.assertEqual(len(list(response_iterator_call)), 0)
received_initial_metadata = \
response_iterator_call.initial_metadata()
self.assertTrue(
test_common.metadata_transmitted(
_CLIENT_METADATA,
@ -454,9 +458,9 @@ class MetadataCodeDetailsTest(unittest.TestCase):
response_iterator_call = self._unary_stream(
_SERIALIZED_REQUEST, metadata=_CLIENT_METADATA)
received_initial_metadata = response_iterator_call.initial_metadata()
with self.assertRaises(grpc.RpcError):
list(response_iterator_call)
received_initial_metadata = response_iterator_call.initial_metadata()
self.assertTrue(
test_common.metadata_transmitted(
@ -547,9 +551,9 @@ class MetadataCodeDetailsTest(unittest.TestCase):
response_iterator_call = self._unary_stream(
_SERIALIZED_REQUEST, metadata=_CLIENT_METADATA)
received_initial_metadata = response_iterator_call.initial_metadata()
with self.assertRaises(grpc.RpcError):
list(response_iterator_call)
received_initial_metadata = response_iterator_call.initial_metadata()
self.assertTrue(
test_common.metadata_transmitted(

@ -202,6 +202,9 @@ class MetadataTest(unittest.TestCase):
def testUnaryStream(self):
multi_callable = self._channel.unary_stream(_UNARY_STREAM)
call = multi_callable(_REQUEST, metadata=_INVOCATION_METADATA)
# NOTE(gnossen): In the single-threaded case, we must consume at least
# one message before the initial metadata will show up.
next(call)
self.assertTrue(
test_common.metadata_transmitted(_EXPECTED_INITIAL_METADATA,
call.initial_metadata()))

Loading…
Cancel
Save