Пример #1
0
def test_client_socket_open():
    client_socket = TSocket(host="localhost", port=12345)
    with pytest.raises(TTransportException) as e:
        client_socket.open()
    assert e.value.message == "Could not connect to ('localhost', 12345)"
    assert not client_socket.is_open()

    server_socket = TServerSocket(host="localhost", port=12345)
    server_socket.listen()

    client_socket.open()
    assert client_socket.is_open()

    server_socket.close()
    client_socket.close()
Пример #2
0
def test_server_socket_close():
    server_socket = TServerSocket(host="localhost", port=12345)
    server_socket.listen()

    client_socket = TSocket(host="localhost", port=12345, socket_timeout=100)
    client_socket.open()

    conn = server_socket.accept()
    server_socket.close()

    client_socket.write(b"Hello world")
    with pytest.raises(socket.timeout):
        client_socket.read(1024)

    conn.close()
    server_socket.close()
Пример #3
0
def test_client_socket_timeout():
    server_socket = TServerSocket(host="localhost", port=12345,
                                  client_timeout=100)
    server_socket.listen()

    client_socket = TSocket(host="localhost", port=12345,
                            connect_timeout=10, socket_timeout=100)
    client_socket.open()

    conn = server_socket.accept()

    assert client_socket.sock.gettimeout() == 100 / 1000
    assert conn.sock.gettimeout() == 100 / 1000
    assert server_socket.sock.gettimeout() is None

    conn.close()
    client_socket.close()
    server_socket.close()
Пример #4
0
def test_client_socket_close():
    server_socket = TServerSocket(host="localhost", port=12345)
    server_socket.listen()

    client_socket = TSocket(host="localhost", port=12345)
    client_socket.open()

    conn = server_socket.accept()
    client_socket.close()
    assert not client_socket.is_open()

    with pytest.raises(TTransportException) as e:
        conn.read(1024)
    assert "TSocket read 0 bytes" in e.value.message

    conn.write(b"world")

    conn.close()
    server_socket.close()