Exemplo n.º 1
0
def t2(w, so_path):
    pretty = '%s t2' % __file__
    print(pretty)

    sock_path = os.path.join(w.path, 'fdtx.sock')
    file_paths = [
        os.path.join(w.path, 'file1.txt'),
        os.path.join(w.path, 'file2.txt'),
        os.path.join(w.path, 'file3.txt')
    ]

    p1 = Process(target=accepter, args=(sock_path, file_paths, so_path))
    p2 = Process(target=connecter, args=(sock_path, 'star cream', 3, so_path))
    p1.start()
    time.sleep(0.1)
    p2.start()
    p1.join()
    p2.join()

    for path in file_paths:
        with open(path) as f:
            contents = f.read()
            if contents != 'star cream':
                print('FAIL %s: wrong reception: %s' % (pretty, contents))
                return False

    return True
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
0
    def start(self):
        if self.get_pid():
            raise Exception('pid file %s exist' % self.pid_path)

        Process.start(self, daemonize=True, synchronize=True)
        self.set_pid(self.pid)
        return self.get_pid()
Exemplo n.º 5
0
    def restart(self):
        if not self.get_pid():
            raise Exception('pid file %s does not exist' % self.pid_path)

        old_pid = self.get_pid()
        self.target = self.rerun # override the default target=self.run
        Process.start(self, daemonize=True, synchronize=True)
        self.set_pid(self.pid)
        return self.get_pid()
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
0
def t1(w, so_path):
    pretty = '%s t1' % __file__
    print(pretty)

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

    p1 = Process(target=accepter, args=(sock_path, [file_path], so_path))
    p2 = Process(target=connecter, args=(sock_path, 'star cream', 1, so_path))
    p1.start()
    time.sleep(0.1)
    p2.start()
    p1.join()
    p2.join()

    with open(file_path) as f:
        contents = f.read()
        if contents != 'star cream':
            print('FAIL %s: wrong reception: %s' % (pretty, contents))
            return False

    return True
Exemplo n.º 9
0
def t06(pretty, factory):
    def killer(pid):
        for i in range(150):
            os.kill(pid, signal.SIGUSR1)
            time.sleep(0.05)

    ctrl = factory.make_control(home=factory.HOME.path, authkey='')
    proc = Process(target=killer, args=(ctrl.get_pid(),))
    proc.start()

    # connect and authenticate
    conn = BlockingConnection(('',ctrl.port))
    conn.connect()
    conn.put(make_digest(conn.get(), ''))
    finish_challenge(conn.get())

    # feed messages slowly to the controller, check that it doesn't crash
    ok = True
    for i in range(15):
        blob = RemoteControl.make_rpc_blob('upper', None, 'a'*5000)
        conn.write(Connection.make_header(blob))
        #print '<',i
        for char in blob:
            conn.write(char)
            time.sleep(0.00002)
        #print '>',i
        try:
            msg = conn.get(timeout=1)
        except Exception, e:
            print('FAIL %s: control crashed in step %d: %s' % (pretty, i, e))
            ok = False
            break
        try:
            msg = json.loads(msg)
        except Exception, e:
            print('FAIL %s: could not decode response %d: %s' & (pretty, i, e))
            ok = False
            break
Exemplo n.º 10
0
            return False

        try:
            msg = c.get(timeout=1)
            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):
Exemplo n.º 11
0
 def start(self, daemonize=False, synchronize=False):
     Process.start(self, daemonize, synchronize)
     if self.socket:
         self.socket.close()  # do not leave open in parent process
Exemplo n.º 12
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
Exemplo n.º 13
0
    def srv(sock_path, so_path=None):
        try:
            tx = FdTx(so_path)
            dirname, filename = os.path.split(sock_path)
            time.sleep(0.5) # make sure a bunch of early connects fail
            tx.listen(dirname, filename)
            tx.accept()
        except Exception, e:
            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
Exemplo n.º 14
0
 def make_client(self, fn, *argv):
     p = Process(target=fn, args=argv)
     p.start()
     self.processes.append(p)
     return p