def _broken_stream(): class BrokenChannel: def __connect__(self): raise IOError('Intentionally broken connection') request = Request('POST', 'http', '/foo/bar', authority='test.com') return Stream(BrokenChannel(), request, SavoysRequest, SavoysReply)
def _broken_stream(): class BrokenChannel: def __connect__(self): raise IOError('Intentionally broken connection') request = Request('POST', 'http', '/foo/bar', content_type=CONTENT_TYPE) return Stream(BrokenChannel(), request, SavoysRequest, SavoysReply)
def _stub(loop): protocol = H2Protocol(Handler(), H2Configuration(header_encoding='utf-8'), loop=loop) channel = ChannelStub(protocol) request = Request('POST', 'http', '/foo/bar', authority='test.com') stream = Stream(channel, request, SavoysRequest, SavoysReply) server = ServerStub(protocol) return Stub(stream, server, channel)
def _stream(stub): stream_mock = Mock() stream_mock.processor.create_stream.return_value = stub class Channel: async def __connect__(self): return stream_mock request = Request('POST', 'http', '/foo/bar', content_type=CONTENT_TYPE) return Stream(Channel(), request, SavoysRequest, SavoysReply)
async def test_connection_error(): class BrokenChannel: def __connect__(self): raise IOError('Intentionally broken connection') stream = Stream(BrokenChannel(), '/foo/bar', MultiDict(), Cardinality.UNARY_UNARY, DummyRequest, DummyReply, codec=ProtoCodec(), dispatch=_DispatchChannelEvents()) with pytest.raises(IOError) as err: async with stream: await stream.send_request() err.match('Intentionally broken connection')
async def test_connection_error(): request = Request('POST', 'http', '/foo/bar', content_type='application/grpc+proto', authority='test.com') class BrokenChannel: def __connect__(self): raise IOError('Intentionally broken connection') stream = Stream(BrokenChannel(), request, ProtoCodec(), DummyRequest, DummyReply) with pytest.raises(IOError) as err: async with stream: await stream.send_request() err.match('Intentionally broken connection')
async def worker2(): s2 = Stream(stub.channel, request, SavoysRequest, SavoysReply) async with s2: await s2.send_message(SavoysRequest(kyler='bhatta'), end=True) assert await s2.recv_message() == SavoysReply(benito='giselle')