Skip to content

Commit 7280c5e

Browse files
committed
Support testing unary-stream calls that return a coroutine
Originally testing unary-stream calls assumed a `GrpcStreamBroadcaster` is used, which means a `Receiver` is returned synchronously. But not all unary-stream calls adopt this pattern, and some might be async, so returning a coroutine instead. With this commit we inspect the return value and if it is a coroutine, we await for it and assign the awaited value as the client result. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 3dcb244 commit 7280c5e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

tests/util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,10 @@ def create_response_wrapper(*_: Any, **__: Any) -> AsyncIterator[Any]:
10011001
client_result = client_method(
10021002
*test_case.client_args, **test_case.client_kwargs
10031003
)
1004+
if asyncio.iscoroutine(client_result):
1005+
_logger.debug("The client method is a coroutine, awaiting it...")
1006+
async with asyncio.timeout(60):
1007+
client_result = await client_result
10041008
_logger.debug("Client method result: %r", client_result)
10051009
except Exception as err: # pylint: disable=broad-exception-caught
10061010
_logger.debug("Client method raised an exception: %r", err)

0 commit comments

Comments
 (0)