def test_send_to_disconnected_then_connect(send_to_disconnected_then_connect,
                                           looper):
    alpha, beta, beta_msg_handler = send_to_disconnected_then_connect
    check_all_received(looper,
                       frm=alpha,
                       to_msg_handler=beta_msg_handler,
                       num_msg=NUM_MSGS)
    assert len(alpha._stashed_to_disconnected[beta.name]) == 0
Exemple #2
0
def test_connect_and_send_after_reconnect(looper, tdir, tconf, generated_keys, round):
    # create stacks
    alpha, alpha_motor, alpha_msg_handler = create_stack("Alpha", looper, tdir, tconf)
    beta, beta_motor, beta_msg_handler = create_stack("Beta", looper, tdir, tconf)

    # connect Alpha to Beta
    connectStack(alpha, beta)

    # reconnect Alpha
    alpha.reconnectRemoteWithName(beta.name)

    total = send(looper, alpha, beta)

    # connect Beta to Alpha
    connectStack(beta, alpha)

    # check connected
    looper.run(eventually(
        checkStacksConnected, [alpha, beta], timeout=CONNECT_TIMEOUT))

    total += send(looper, alpha, beta)
    check_all_received(looper, frm=alpha, to_msg_handler=beta_msg_handler, num_msg=total)
Exemple #3
0
def test_reconnect_multiple_time_with_random_waits(looper, tdir, tconf, generated_keys):
    # create stacks
    alpha, alpha_motor, alpha_msg_handler = create_stack("Alpha", looper, tdir, tconf)
    beta, beta_motor, beta_msg_handler = create_stack("Beta", looper, tdir, tconf)

    # connect both
    connectStack(alpha, beta)
    connectStack(beta, alpha)

    total = send(looper, alpha, beta)
    check_all_received(looper, frm=alpha, to_msg_handler=beta_msg_handler, num_msg=total)

    for i in range(10):
        beta.stop()

        total += send(looper, alpha, beta)

        looper.runFor(random.Random().randint(1, 10))

        beta.start()
        connectStack(beta, alpha)

        check_all_received(looper, frm=alpha, to_msg_handler=beta_msg_handler, num_msg=total)
Exemple #4
0
def test_reconnect_for_long_time(looper, tdir, tconf, generated_keys):
    # create stacks
    alpha, alpha_motor, alpha_msg_handler = create_stack("Alpha", looper, tdir, tconf)
    beta, beta_motor, beta_msg_handler = create_stack("Beta", looper, tdir, tconf)

    # connect both
    connectStack(alpha, beta)
    connectStack(beta, alpha)
    looper.run(eventually(
        checkStacksConnected, [alpha, beta], timeout=CONNECT_TIMEOUT))

    total = send(looper, alpha, beta)
    check_all_received(looper, frm=alpha, to_msg_handler=beta_msg_handler, num_msg=total)

    for i in range(10):
        # 1. stop Beta
        beta.stop()
        beta_motor.stop()
        looper.run(eventually(
            checkStackDisonnected, beta, [alpha], timeout=CONNECT_TIMEOUT))
        looper.run(eventually(
            checkStackDisonnected, alpha, [beta], timeout=CONNECT_TIMEOUT))

        # 2. wait for some time
        looper.runFor(15)

        # 3. start Beta again
        beta.start()
        connectStack(beta, alpha)

        # 4. check that they are connected
        looper.run(eventually(
            checkStacksConnected, [alpha, beta], timeout=CONNECT_TIMEOUT))

        total += send(looper, alpha, beta)
        check_all_received(looper, frm=alpha, to_msg_handler=beta_msg_handler, num_msg=total)
Exemple #5
0
def test_reconnect_and_send_multi(looper, tdir, tconf, generated_keys):
    # create stacks
    alpha, alpha_motor, alpha_msg_handler = create_stack("Alpha", looper, tdir, tconf)
    beta, beta_motor, beta_msg_handler = create_stack("Beta", looper, tdir, tconf)

    # connect Alpha to Beta
    connectStack(alpha, beta)
    # connect Beta to Alpha
    connectStack(beta, alpha)

    # check connected
    looper.run(eventually(
        checkStacksConnected, [alpha, beta], timeout=CONNECT_TIMEOUT))

    total_from_alpha = 0
    total_from_alpha += send(looper, alpha, beta)
    check_all_received(looper, frm=alpha, to_msg_handler=beta_msg_handler, num_msg=total_from_alpha)

    total_from_beta = 0
    total_from_beta += send(looper, beta, alpha)
    check_all_received(looper, frm=beta, to_msg_handler=alpha_msg_handler, num_msg=total_from_beta)

    for i in range(10):
        # reconnect Alpha
        alpha.stop()

        total_from_beta += send(looper, beta, alpha)

        alpha.start()
        connectStack(alpha, beta)
        looper.run(eventually(
            checkStacksConnected, [alpha, beta], timeout=CONNECT_TIMEOUT))

        total_from_beta += send(looper, beta, alpha)
        check_all_received(looper, frm=beta, to_msg_handler=alpha_msg_handler, num_msg=total_from_beta)
        total_from_alpha += send(looper, alpha, beta)
        check_all_received(looper, frm=alpha, to_msg_handler=beta_msg_handler, num_msg=total_from_alpha)

        # reconnect Beta
        beta.stop()

        total_from_alpha += send(looper, alpha, beta)

        beta.start()
        connectStack(beta, alpha)
        looper.run(eventually(
            checkStacksConnected, [alpha, beta], timeout=CONNECT_TIMEOUT))

        total_from_alpha += send(looper, alpha, beta)
        check_all_received(looper, frm=alpha, to_msg_handler=beta_msg_handler, num_msg=total_from_alpha)

        total_from_beta += send(looper, beta, alpha)
        check_all_received(looper, frm=beta, to_msg_handler=alpha_msg_handler, num_msg=total_from_beta)

        # reconnect Alpha and then Beta
        alpha.stop()
        alpha.start()
        connectStack(alpha, beta)
        beta.stop()
        beta.start()
        connectStack(beta, alpha)
        looper.run(eventually(
            checkStacksConnected, [alpha, beta], timeout=CONNECT_TIMEOUT))

        total_from_alpha += send(looper, alpha, beta)
        check_all_received(looper, frm=alpha, to_msg_handler=beta_msg_handler, num_msg=total_from_alpha)
        total_from_beta += send(looper, beta, alpha)
        check_all_received(looper, frm=beta, to_msg_handler=alpha_msg_handler, num_msg=total_from_beta)

        # reconnect Beta and then Alpha
        beta.stop()
        beta.start()
        connectStack(beta, alpha)
        alpha.stop()
        alpha.start()
        connectStack(alpha, beta)
        looper.run(eventually(
            checkStacksConnected, [alpha, beta], timeout=CONNECT_TIMEOUT))

        total_from_alpha += send(looper, alpha, beta)
        check_all_received(looper, frm=alpha, to_msg_handler=beta_msg_handler, num_msg=total_from_alpha)
        total_from_beta += send(looper, beta, alpha)
        check_all_received(looper, frm=beta, to_msg_handler=alpha_msg_handler, num_msg=total_from_beta)