Ejemplo n.º 1
0
def channel_fixture(loop, port):
    services = [DummyService()]
    services = ServerReflection.extend(services)

    server = Server(services, loop=loop)
    loop.run_until_complete(server.start(port=port))

    channel = Channel(port=port, loop=loop)
    try:
        yield channel
    finally:
        channel.close()
        server.close()
        loop.run_until_complete(server.wait_closed())
Ejemplo n.º 2
0
async def test_concurrent_connect(loop):
    count = 5
    reqs = [DummyRequest(value='ping') for _ in range(count)]
    reps = [DummyReply(value='pong') for _ in range(count)]

    channel = Channel()
    stub = DummyServiceStub(channel)
    async with ChannelFor([DummyService()]) as _channel:
        with patch.object(loop, 'create_connection') as po:
            po.side_effect = _create_connection_gen(_channel._protocol)
            tasks = [loop.create_task(stub.UnaryUnary(req)) for req in reqs]
            replies = await asyncio.gather(*tasks)
    assert replies == reps
    po.assert_called_once_with(ANY, '127.0.0.1', 50051, ssl=None)
Ejemplo n.º 3
0
async def test():
    async with ChannelFor([DummyService()]) as channel:
        stub = DummyServiceStub(channel)
        reply = await stub.UnaryUnary(DummyRequest(value='ping'))
        assert reply == DummyReply(value='pong')
Ejemplo n.º 4
0
def stub_fixture(loop):
    with channel_for([DummyService()], loop=loop) as channel:
        yield DummyServiceStub(channel)