Ejemplo n.º 1
0
def client(io_loop):
    client = TChannel('client')
    # The client listens for incoming connections so that the server doesn't
    # treat is as an ephemeral client. This is needed to exercise the p2p use
    # case.
    client.listen()
    try:
        yield client
    finally:
        client.close()
Ejemplo n.º 2
0
def server(io_loop):
    server = TChannel('server')

    @server.json.register('hello')
    def hello(request):
        return 'world'

    server.listen()
    try:
        yield server
    finally:
        server.close()
Ejemplo n.º 3
0
def test_close_stops_listening():
    server = TChannel(name='server')
    server.listen()

    host = server.host
    port = server.port

    # Can connect
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((host, port))
    sock.close()

    server.close()

    # Can't connect
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    with pytest.raises(socket.error):
        sock.connect((host, port))
Ejemplo n.º 4
0
def test_close_stops_listening():
    server = TChannel(name='server')
    server.listen()

    host = server.host
    port = server.port

    # Can connect
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((host, port))
    sock.close()

    server.close()

    # Can't connect
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    with pytest.raises(socket.error):
        sock.connect((host, port))