Ejemplo n.º 1
0
def t6(pretty, HOME):
    sock, port = find_free_port()
    sock.shutdown(
        socket.SHUT_RDWR)  # close the socket since it can't be passed
    sock.close()  # to ADB (which would have been very nice).

    config = {'port': port, 'persist': True, 'demote': False, 'logging': False}

    def concurrent(home, config):
        srv = AdbServer(home, config)
        srv.run()

    p = Process(target=concurrent, args=(HOME.path, config))
    p.start()

    seen = []
    for i in range(5):
        # find the current server
        pid = find_one_server_process(port, 4)
        if pid in seen:
            print('FAIL %s: pid %d was seen before: %s' % (pretty, pid, seen))
            p.terminate()
            p.join()
            return False
        seen.append(pid)

        # kill the current server. expect the next step in the loop to find a
        # new one in its place
        AdbServer.kill_all_servers(port)

    p.terminate()
    p.join()

    return True
Ejemplo n.º 2
0
def t5(pretty, HOME):
    sock, port = find_free_port()
    sock.shutdown(
        socket.SHUT_RDWR)  # close the socket since it can't be passed
    sock.close()  # to ADB (which would have been very nice).

    config = {
        'port': port,
        'persist': False,
        'demote': False,
        'logging': False
    }

    def concurrent(home, config):
        srv = AdbServer(home, config)
        srv.run()

    p = Process(target=concurrent, args=(HOME.path, config))
    p.start()

    try:
        find_one_server_process(port, 2)
    except Exception, e:
        print('FAIL %s: %s' % (pretty, e))
        p.terminate()
        p.join()
        return False
Ejemplo n.º 3
0
def t7(factory):
    pretty = '%s t7' % __file__
    print(pretty)

    handover = factory.make_master('master')
    avail = handover.list_available()

    def oob_client(address):
        r = RemoteBroker(address, home=factory.HOME.path)
        h, w = r.get_resources({'type': 'handset'}, {'type': 'workspace'})
        w.run('sleep 2')  # right, extremely busy, but it prevents other action

    p = Process(target=oob_client, args=(handover.address, ))
    p.start()

    # make sure the oob client has gotten its resources
    ok = False
    for i in range(10):
        if len(handover.list_available()) != len(avail):
            ok = True
            break
        time.sleep(0.1)
    if not ok:
        print('FAIL %s: catastrophic' % pretty)
        p.terminate()
        p.join()
        return False

    adoption, config, fdtx_path = handover.begin_handover()
    takeover = factory.make_takeover('master', adoption, config, fdtx_path)
    handover.end_handover(1)

    # now wait for the client to die, so that its session dies, so that
    # the takeover detects this, so that the associated resouces can be reclaimed,
    # so that the takeover's availability is the same as when we started
    ok = False
    for i in range(10):
        if len(takeover.list_available()) == len(avail):
            ok = True
            break
        time.sleep(0.3)
    if not ok:
        print('FAIL %s: super busy session not tracked correctly' % pretty)

    p.terminate()
    p.join()

    return ok
Ejemplo n.º 4
0
def t6(factory):
    pretty = '%s t6' % __file__
    print(pretty)

    handover = factory.make_master('master')
    avail = handover.list_available()

    def oob_client(address):
        r = RemoteBroker(address, home=factory.HOME.path)
        h, w = r.get_resources({'type': 'handset'}, {'type': 'workspace'})
        w.run('sleep 3')  # right, extremely busy, but it prevents other action
        while True:
            time.sleep(1)  # don't let client die and loose all resources

    p = Process(target=oob_client, args=(handover.address, ))
    p.start()

    # make sure the oob client has gotten its resources
    ok = False
    for i in range(10):
        if len(handover.list_available()) != len(avail):
            ok = True
            break
        time.sleep(0.3)
    if not ok:
        print('FAIL %s: catastrophic' % pretty)

    adoption, config, fdtx_path = handover.begin_handover()
    takeover = factory.make_takeover('master', adoption, config, fdtx_path)
    handover.end_handover(1)

    result = True
    if len(takeover.list_available()) == len(avail):
        print('FAIL %s: wrong avail: %s' % (pretty, avail))
        result = False

    p.terminate()
    p.join()

    return result
Ejemplo n.º 5
0
            if msg != 'test the connection':
                print('FAIL %s: wrong message: %s' % (pretty, msg))
                return False
        except Exception, e:
            traceback.print_exc()
            print('FAIL %s: get() failed: %s' % (pretty, e))
            return False

    # bind socket to port but don't start listening
    sock, port = find_free_port(listen=False)
    pinger = Process(target=ping, args=(port, sock))
    pinger.start()

    result = test(port)

    pinger.terminate()
    pinger.join()

    return result


# check that connection attempts succeed if someone accepts soon enough
def t04():
    pretty = '%s t4' % __file__
    print(pretty)

    def ping(port, sock):
        listener = BlockingConnection(('', port), socket=sock)
        time.sleep(2)
        listener.listen()
        c = listener.accept(timeout=1)
Ejemplo n.º 6
0
def t8(factory):
    pretty = '%s t8' % __file__
    print(pretty)

    original = factory.make_master('master')
    avail = original.list_available()

    def oob_client(address):
        r = RemoteBroker(address, home=factory.HOME.path)
        h, w = r.get_resources({'type': 'handset'}, {'type': 'workspace'})
        while True:
            time.sleep(1)

    p = Process(target=oob_client, args=(original.address, ))
    p.start()

    # make sure the oob client has gotten its resources
    ok = False
    for i in range(10):
        if len(original.list_available()) != len(avail):
            ok = True
            break
        time.sleep(0.1)
    if not ok:
        print('FAIL %s: catastrophic' % pretty)
        p.terminate()
        p.join()
        return False

    # do two handovers in a row
    adoption, config, fdtx_path = original.begin_handover()
    interim = factory.make_takeover('master', adoption, config, fdtx_path)
    original.end_handover(1)

    adoption, config, fdtx_path = interim.begin_handover()
    final = factory.make_takeover('master', adoption, config, fdtx_path)
    interim.end_handover(1)

    # check that all brokers have the same availability
    a1 = original.list_available()
    a2 = interim.list_available()
    a3 = final.list_available()
    if len(a1) != len(a2) != len(a3):
        print('FAIL %s: a handover failed somewhere: %s != %s != %s' %
              (pretty, a1, a2, a3))
        p.terminate()
        p.join()
        return False

    # kill the client so that the brokers reclaim the equipment
    p.terminate()
    p.join()

    ok = False
    for i in range(10):
        a3 = final.list_available()
        if len(a3) == len(avail):
            ok = True
            break
    if not ok:
        print('FAIL %s: wrong availability: %d %d %d %d' %
              (pretty, len(a1), len(a2), len(a3), len(avail)))
        return False

    # check that the original and interim brokers have terminated now that they
    # don't have any sessions with allocations
    try:
        original.ping()  # ping
    except Exit, e:
        pass  # good
Ejemplo n.º 7
0
            traceback.print_exc()
            print('FAIL: srv failed')

    sock_path = os.path.join(w.path, 'fdtx.sock')

    p = Process(target=srv, args=(sock_path, so_path))
    p.start()

    tx = FdTx(so_path)
    ok = True
    try:
        tx.connect(sock_path, 2)
    except Exception, e:
        print('FAIL %s: connect failed: %s' % (pretty, str(e)))
        ok = False
    p.terminate()
    p.join()

    return ok

# like t4 but with the delay after the call to .listen(). also send something
@smoke
@setup
def t4(w, so_path):
    pretty = '%s t4' % __file__
    print(pretty)

    def srv(sock_path, file_path, so_path=None):
        try:
            tx = FdTx(so_path)
            dirname, filename = os.path.split(sock_path)