Beispiel #1
0
def test_ping_pong():
    peer1, peer2 = create_peers()

    f1 = asyncio.Task(standards.initial_handshake(peer1, VERSION_MSG))
    f2 = asyncio.Task(standards.initial_handshake(peer2, VERSION_MSG_2))

    asyncio.get_event_loop().run_until_complete(asyncio.wait([f1, f2]))

    standards.install_ping_manager(peer1, heartbeat_rate=0.5, missing_pong_disconnect_timeout=110.1)
    standards.install_pong_manager(peer2)

    asyncio.get_event_loop().run_until_complete(asyncio.sleep(0.6))
    assert peer1.writ_data[-26:] == peer2.writ_data[-26:]
Beispiel #2
0
def test_ping_pong():
    peer1, peer2 = create_peers()

    f1 = asyncio.Task(standards.initial_handshake(peer1, VERSION_MSG))
    f2 = asyncio.Task(standards.initial_handshake(peer2, VERSION_MSG_2))

    asyncio.get_event_loop().run_until_complete(asyncio.wait([f1, f2]))

    standards.install_ping_manager(peer1,
                                   heartbeat_rate=0.5,
                                   missing_pong_disconnect_timeout=110.1)
    standards.install_pong_manager(peer2)

    asyncio.get_event_loop().run_until_complete(asyncio.sleep(0.6))
    assert peer1.writ_data[-26:] == peer2.writ_data[-26:]
Beispiel #3
0
def test_missing_pong_disconnect():
    peer1, peer2 = create_peers()

    f1 = asyncio.Task(standards.initial_handshake(peer1, VERSION_MSG))
    f2 = asyncio.Task(standards.initial_handshake(peer2, VERSION_MSG_2))

    asyncio.get_event_loop().run_until_complete(asyncio.wait([f1, f2]))

    standards.install_ping_manager(peer1, heartbeat_rate=0.5, missing_pong_disconnect_timeout=0.01)

    asyncio.get_event_loop().run_until_complete(asyncio.sleep(0.6))

    next_message = peer1.new_get_next_message_f()

    ## make sure peer1 is disconnected
    got_eof = False
    try:
        asyncio.get_event_loop().run_until_complete(asyncio.wait_for(next_message(), timeout=0.2))
    except EOFError:
        got_eof = True
    assert got_eof
Beispiel #4
0
def test_missing_pong_disconnect():
    peer1, peer2 = create_peers()

    f1 = asyncio.Task(standards.initial_handshake(peer1, VERSION_MSG))
    f2 = asyncio.Task(standards.initial_handshake(peer2, VERSION_MSG_2))

    asyncio.get_event_loop().run_until_complete(asyncio.wait([f1, f2]))

    standards.install_ping_manager(peer1,
                                   heartbeat_rate=0.5,
                                   missing_pong_disconnect_timeout=0.01)

    asyncio.get_event_loop().run_until_complete(asyncio.sleep(0.6))

    next_message = peer1.new_get_next_message_f()

    ## make sure peer1 is disconnected
    got_eof = False
    try:
        asyncio.get_event_loop().run_until_complete(
            asyncio.wait_for(next_message(), timeout=0.2))
    except EOFError:
        got_eof = True
    assert got_eof