Exemple #1
0
def test_unexpected_error(error, msg):
    class Handler(object):
        def handle(self, request):
            raise error

    inbound = HTTPInbound()
    inbound.start(Handler())

    client = AsyncHTTPClient()
    req = HTTPRequest(
        url='http://localhost:%s' % inbound.port,
        method='POST',
        headers={
            headers.CALLER: 'caller',
            headers.SERVICE: 'service',
            headers.PROCEDURE: 'procedure',
            headers.ENCODING: 'json',
            headers.TTL: '10000',
        },
        body='',
    )

    with pytest.raises(HTTPError) as e:
        yield client.fetch(req)

    e = e.value
    assert e.code >= 500 and e.code < 600
    assert e.response.body == msg
Exemple #2
0
def test_bad_request_error(req, msg):
    inbound = HTTPInbound()
    inbound.start(None)

    client = AsyncHTTPClient()

    req.url = 'http://localhost:%s' % inbound.port
    req.method = 'POST'
    req.body = ''

    with pytest.raises(HTTPError) as e:
        yield client.fetch(req)

    e = e.value
    assert e.code >= 400 and e.code <= 500
    assert e.response.body == msg
Exemple #3
0
def test_reuse_port():
    # start inbound with SO_REUSEPORT on
    one = HTTPInbound(port=0, reuse_port=True)
    one.start(None)

    # the next one has SO_REUSEPORT on, so it can share port
    three = HTTPInbound(port=one.port, reuse_port=True)
    three.start(None)

    # the next one has SO_REUSEPORT off, so it should blow up
    with pytest.raises(socket.error):
        two = HTTPInbound(port=one.port, reuse_port=False)
        two.start(None)
Exemple #4
0
def test_inbound_headers(http_headers, rpc_headers, http_resp_headers):
    class Handler(object):
        def handle(self, request):
            assert rpc_headers == request.headers
            return Response(headers=rpc_headers, body=request.body)

    inbound = HTTPInbound()
    inbound.start(Handler())

    client = AsyncHTTPClient()
    req = HTTPRequest(
        url='http://localhost:%s' % inbound.port,
        method='POST',
        headers=http_headers,
        body='',
    )

    res = yield client.fetch(req)
    assert 200 == res.code
    for k, v in http_resp_headers.items():
        assert v == res.headers[k]