Example #1
0
def test_connections_break(remote_module, p4run):
    """
    Tests that connections break when the pool changes. Exists to avoid false positives.

    Same as `l4_loadbalancer/keep_connections_test.py:test_old_versions`,
    but uses the unversioned thing and expects it to fail."""
    lb, client, server1, server2 = yield all_results([
        LoadBalancerUnversioned.get_initialised('s1', topology_db_file=p4run.topo_path),
        remote_module('myutils.client', host='h3'),
        remote_module('myutils.server', 8001, host='h1'),
        remote_module('myutils.server', 8001, host='h2'),
    ])
    yield sleep(0.5)
    server1_ip, server2_ip = [p4run.topo.get_host_ip(h) for h in ('h1', 'h2')]

    pool_handle = yield lb.add_pool('10.0.0.1', 8000)
    print(' --------- create a pool with server1 ---------')
    yield lb.add_dip(pool_handle, server1_ip, 8001)
    yield client.callRemote('start_echo_clients', '10.0.0.1', 8000, count=5)
    yield sleep(0.5)  # make sure the clients have connected
    print(' --------- break it: change the pool ---------')
    yield lb.rm_dip(pool_handle, server1_ip, 8001)
    yield lb.add_dip(pool_handle, server2_ip, 8001)
    yield sleep(0.5)  # give time to notice the breakage

    with pytest.raises(pb.RemoteError) as excinfo:
        # this should throw a ConnectionLost, because we broke the connections
        yield client.callRemote('close_all_connections')
    assert 'ConnectionLost' in str(excinfo)
 def run(module, *m_args, **p_kwargs):
     sock_name = sock(module, next(sock_counter))
     process(python_m(module, sock_name, *m_args), **p_kwargs)
     yield sleep(2)
     conn = pb.PBClientFactory()
     reactor.connectUNIX(sock_name, conn)
     obj = yield conn.getRootObject()
     remotes.append(obj)
     defer.returnValue(obj)
Example #3
0
 def client1():
     """Client 1 will send bursts of short connections (2s)."""
     print('client1 running')
     yield clients[1].callRemote('start_echo_clients',
                                 '10.0.0.1',
                                 8000,
                                 count=20)
     yield sleep(2)
     yield clients[1].callRemote('close_all_connections')
Example #4
0
 def client0():
     """Client 0 will send long-running requests: closes after 10 seconds."""
     print('client0 running')
     yield clients[0].callRemote('start_echo_clients',
                                 '10.0.0.1',
                                 8000,
                                 count=4)
     yield sleep(10)
     yield clients[0].callRemote('close_all_connections')
def test_rollover_active_conns(remote_module, p4run):
    lb, client1, client2, server1, server2 = yield all_results([
        LoadBalancer.get_initialised('s1', topology_db_file=p4run.topo_path),
        remote_module('myutils.client', host='h3'),
        remote_module('myutils.client', host='h4'),
        remote_module('myutils.server', 8001, host='h1'),
        remote_module('myutils.server', 8001, host='h2'),
    ])
    server1_ip, server2_ip = [p4run.topo.get_host_ip(h) for h in ('h1', 'h2')]

    pool_handle = yield lb.add_pool('10.0.0.1', 8000)

    for i in range(5):
        print(' --------- v1: server1 ---------')
        yield lb.add_dip(pool_handle, server1_ip, 8001)
        yield lb.commit()
        yield client1.callRemote('start_echo_clients',
                                 '10.0.0.1',
                                 8000,
                                 count=5)
        yield sleep(0.5)  # make sure the clients have connected
        print(' --------- v2: server2 ---------')
        yield lb.rm_dip(pool_handle, server1_ip, 8001)
        yield lb.add_dip(pool_handle, server2_ip, 8001)
        # roll over the version => eat old pending tables
        for i in range(5):
            yield lb.commit()
        yield client2.callRemote('start_echo_clients',
                                 '10.0.0.1',
                                 8000,
                                 count=3)
        yield sleep(0.5)  # give it time to notice the breakage, if any

        # this would throw if something bad happened to the connections
        yield client1.callRemote('close_all_connections')
        yield client2.callRemote('close_all_connections')

        yield check_conn_count(server1, 5)
        yield check_conn_count(server2, 3)

        yield lb.rm_dip(pool_handle, server2_ip,
                        8001)  # clean up before next iteration
def test_echo_client(remote_module):
    client, server = yield all_results([
        remote_module('myutils.client', host=None),
        remote_module('myutils.server', 8000, host=None),
    ])
    yield client.callRemote('start_echo_clients', 'localhost', 8000, count=5)
    yield sleep(0.5)  # make sure the clients have connected
    yield client.callRemote('close_all_connections')

    nconns1 = yield server.callRemote('get_conn_count')
    assert nconns1 == 5
Example #7
0
def remote_module(mname, *m_args, **p_kwargs):
    """Run a PB-using module in a separate process and give back its root object.

    param mname: module name
    param *m_args: CLI args, will be added after `python -m mname`
    param *p_kwargs: will be passed to the process executor
    """
    sock_name = sock(mname, next(_sock_counter))
    process(python_m(mname, sock_name, *m_args), **p_kwargs)
    yield sleep(2)  # wait for it to bind
    conn = pb.PBClientFactory()
    from twisted.internet import reactor
    reactor.connectUNIX(sock_name, conn)
    obj = yield conn.getRootObject()
    defer.returnValue(obj)