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
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
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
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
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
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
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) c.put('test the connection', timeout=1)
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
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) tx.listen(dirname, filename)