def test_inbound_will_call_listen_on_tchannel(): tchannel = TChannel('yaboi') assert not tchannel.is_listening() inbound = TChannelInbound(tchannel) inbound.start(None) assert tchannel.is_listening()
def test_unexpected_error(error, msg): class Handler(object): def handle(self, request): raise error inbound = TChannelInbound(TChannel('%s-server' % __name__)) inbound.start(Handler()) client = TChannel('%s-client' % __name__) with pytest.raises(TChUnexpectedError) as e: yield client.raw( service='service', endpoint='procedure', hostport=inbound.hostport, timeout=10, # seconds ) e = e.value assert str(e) == msg
def test_bad_request_error(req, msg): # we need to mock yarpc.transport.tchannel._to_request to produce # faulty yarpc.transport.Request objects because its not possible to # send bad requests with the tchannel client library. from yarpc.transport.tchannel import inbound as tch_inbound_module allow(tch_inbound_module)._to_request.and_return(req) inbound = TChannelInbound(TChannel('%s-server' % __name__)) inbound.start(None) client = TChannel('%s-client' % __name__) with pytest.raises(TChBadRequestError) as e: yield client.raw( service='service', endpoint='procedure', hostport=inbound.hostport, timeout=10, # seconds ) e = e.value assert str(e) == msg