Esempio n. 1
0
def test_base_server():

    # server
    server = BaseServer(HOST, PORT)
    server.register_handle_function("CmdHello", hello)

    holder = {'hello': ""}
    def sayHello():
        holder['hello'] = "world"

    server.register_start_function(sayHello)
    def server_thread():
        server.run()

    t = threading.Thread(target = server_thread)
    t.start()

    sleep(4)
    # client
    try:
        ret = client.send_message((HOST, PORT), CmdHello("world"))
        assert ret == "hello world"

        client.sendonly_message((HOST, PORT), CmdHello("world"))

    finally:
        server.shutdown()

    assert holder["hello"] == "world"
Esempio n. 2
0
def test_base_server():

    # server
    server = BaseServer(HOST, PORT)
    server.register_handle_function("CmdHello", hello)

    holder = {'hello': ""}

    def sayHello():
        holder['hello'] = "world"

    server.register_start_function(sayHello)

    def server_thread():
        server.run()

    t = threading.Thread(target=server_thread)
    t.start()

    sleep(4)
    # client
    try:
        ret = client.send_message((HOST, PORT), CmdHello("world"))
        assert ret == "hello world"

        client.sendonly_message((HOST, PORT), CmdHello("world"))

    finally:
        server.shutdown()

    assert holder["hello"] == "world"