Skip to content

Instantly share code, notes, and snippets.

@pfreixes
Last active May 3, 2019 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfreixes/110dbdd88e3b0e1e450da9c6fc97496c to your computer and use it in GitHub Desktop.
Save pfreixes/110dbdd88e3b0e1e450da9c6fc97496c to your computer and use it in GitHub Desktop.
Test experimental gRPC using Native Asyncio
import asyncio
import pytest
import subprocess
import time
from grpc_asyncio import grpc_init_asyncio
from grpc_asyncio import create_channel
from tests.acceptance.fixtures import echo_pb2
class TestClient:
@pytest.mark.asyncio
async def test_unary_call(self, server):
grpc_init_asyncio()
channel = await create_channel("127.0.0.1", 3333)
response = await channel.unary_call(
b'/echo.Echo/Hi',
echo_pb2.EchoRequest(message="Hi Grpc Asyncio").SerializeToString()
)
assert echo_pb2.EchoReply.FromString(response).message == "Hi Grpc Asyncio"
@pfreixes
Copy link
Author

pfreixes commented May 3, 2019

DYLD_LIBRARY_PATH=`pwd`/vendor/grpc/libs/opt pytest -sv tests/acceptance
============================================================================================================================= test session starts ==============================================================================================================================
platform darwin -- Python 3.7.2, pytest-4.2.0, py-1.7.0, pluggy-0.8.1 -- /Users/paufreixes/.virtualenvs/grpc-asyncio/bin/python3.7
cachedir: .pytest_cache
rootdir: /Users/paufreixes/pfreixes/grpc-asyncio, inifile:
plugins: asyncio-0.10.0
collected 1 item

tests/acceptance/test_client.py::TestClient::test_unary_call init_loop called
TODO
grpc_init_asyncio called ...
<Timer 4496240456 deadline=5.0 active=1> created
socket_resolve_async called
<Resolver 4496240536> created
<Resolver 4496240536> resolving b'127.0.0.1':b'3333'
<Timer 4496358200 deadline=3.5 active=1> created
<Resolver 4496240536> resolved [(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('127.0.0.1', 3333)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('127.0.0.1', 3333))]
<Socket 4496203448 connected=False> created
<Timer 4496358440 deadline=20.0 active=1> created
<Socket 4496203448 connected=False> connecting
<Socket 4496203448 connected=True> connected
<Timer 4496358440 deadline=20.0 active=1> stop called
<Timer 4496358440 deadline=20.0 active=0> timer canceled
<Timer 4496358440 deadline=19.999 active=1> created
<Timer 4496358440 deadline=19.999 active=1> stop called
<Timer 4496358440 deadline=19.999 active=0> timer canceled
<Socket 4496203448 connected=True> sent 99 bytes
<Socket 4496203448 connected=True> reading
<Socket 4496203448 connected=True> sent 303 bytes
<Socket 4496203448 connected=True> read 63 bytes
<Socket 4496203448 connected=True> reading
<Socket 4496203448 connected=True> sent 26 bytes
<Socket 4496203448 connected=True> read 26 bytes
<Socket 4496203448 connected=True> reading
<Timer 4496358520 deadline=0.1 active=1> created
<Socket 4496203448 connected=True> read 199 bytes
<Socket 4496203448 connected=True> reading
<Timer 4496358200 deadline=3.5 active=1> stop called
<Timer 4496358200 deadline=3.5 active=0> timer canceled
watcher_call_functor_run called
PASSED```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment