Merge pull request #22539 from lidizheng/aio-list-metadata

[Aio] Support all sequential metadata
pull/22560/head
Lidi Zheng 5 years ago committed by GitHub
commit 702cc0cf9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      src/python/grpcio/grpc/experimental/aio/_call.py
  2. 9
      src/python/grpcio_tests/tests_aio/unit/metadata_test.py

@ -14,10 +14,10 @@
"""Invocation-side implementation of gRPC Asyncio Python."""
import asyncio
from functools import partial
import logging
import enum
from typing import AsyncIterable, Awaitable, Dict, Optional
import logging
from functools import partial
from typing import AsyncIterable, Awaitable, Optional, Tuple
import grpc
from grpc import _common
@ -25,7 +25,8 @@ from grpc._cython import cygrpc
from . import _base_call
from ._typing import (DeserializingFunction, DoneCallbackType, MetadataType,
RequestType, ResponseType, SerializingFunction)
MetadatumType, RequestType, ResponseType,
SerializingFunction)
__all__ = 'AioRpcError', 'Call', 'UnaryUnaryCall', 'UnaryStreamCall'
@ -105,7 +106,7 @@ class AioRpcError(grpc.RpcError):
"""
return self._details
def initial_metadata(self) -> Optional[Dict]:
def initial_metadata(self) -> Optional[MetadataType]:
"""Accesses the initial metadata sent by the server.
Returns:
@ -113,7 +114,7 @@ class AioRpcError(grpc.RpcError):
"""
return self._initial_metadata
def trailing_metadata(self) -> Optional[Dict]:
def trailing_metadata(self) -> Optional[MetadataType]:
"""Accesses the trailing metadata sent by the server.
Returns:
@ -161,7 +162,7 @@ class Call:
_loop: asyncio.AbstractEventLoop
_code: grpc.StatusCode
_cython_call: cygrpc._AioCall
_metadata: MetadataType
_metadata: Tuple[MetadatumType]
_request_serializer: SerializingFunction
_response_deserializer: DeserializingFunction
@ -171,7 +172,7 @@ class Call:
loop: asyncio.AbstractEventLoop) -> None:
self._loop = loop
self._cython_call = cython_call
self._metadata = metadata
self._metadata = tuple(metadata)
self._request_serializer = request_serializer
self._response_deserializer = response_deserializer

@ -210,14 +210,21 @@ class TestMetadata(AioTestBase):
self.assertEqual(_RESPONSE, await call)
self.assertEqual(grpc.StatusCode.OK, await call.code())
async def test_from_client_to_server_with_list(self):
multicallable = self._client.unary_unary(_TEST_CLIENT_TO_SERVER)
call = multicallable(
_REQUEST, metadata=list(_INITIAL_METADATA_FROM_CLIENT_TO_SERVER))
self.assertEqual(_RESPONSE, await call)
self.assertEqual(grpc.StatusCode.OK, await call.code())
@unittest.skipIf(platform.system() == 'Windows',
'https://github.com/grpc/grpc/issues/21943')
async def test_invalid_metadata(self):
multicallable = self._client.unary_unary(_TEST_CLIENT_TO_SERVER)
for exception_type, metadata in _INVALID_METADATA_TEST_CASES:
with self.subTest(metadata=metadata):
call = multicallable(_REQUEST, metadata=metadata)
with self.assertRaises(exception_type):
call = multicallable(_REQUEST, metadata=metadata)
await call
async def test_generic_handler(self):

Loading…
Cancel
Save