def cluster(**kwargs): loop = asyncio.new_event_loop() c = Center('127.0.0.1', 8100, loop=loop) a = Worker('127.0.0.1', 8101, c.ip, c.port, loop=loop, **kwargs) b = Worker('127.0.0.1', 8102, c.ip, c.port, loop=loop, **kwargs) kill_q = Queue() @asyncio.coroutine def stop(): while kill_q.empty(): yield from asyncio.sleep(0.01, loop=loop) kill_q.get() cor = asyncio.gather(c.go(), a.go(), b.go(), loop=loop) cor2 = asyncio.wait([stop(), cor], loop=loop, return_when=asyncio.FIRST_COMPLETED) thread, loop = spawn_loop(cor, loop) try: yield c, a, b finally: if a.status != 'closed': a.close() if b.status != 'closed': b.close() c.close() kill_q.put(b'')
def f(): w = Worker("127.0.0.1", 8007) try: yield gen.with_timeout(timedelta(seconds=3), w) except TimeoutError: pass else: assert False assert w.status not in ("closed", "running") yield w.close(timeout=0.1)
def f(): w = Worker("127.0.0.1", 8007) try: yield asyncio.wait_for(w, 3) except asyncio.TimeoutError: pass else: assert False assert w.status not in ("closed", "running") yield w.close(timeout=0.1)
def test_start_services(s): pytest.importorskip("bokeh") from distributed.dashboard import BokehWorker services = {("dashboard", ":1234"): BokehWorker} w = Worker(s.address, services=services) yield w._start() assert w.services["dashboard"].server.port == 1234 yield w.close()
def test_Executor(c, s): with ThreadPoolExecutor(2) as e: w = Worker(s.address, executor=e) assert w.executor is e w = yield w future = c.submit(inc, 1) result = yield future assert result == 2 assert e._threads # had to do some work yield w.close()
def test_service_hosts_match_worker(s): pytest.importorskip("bokeh") from distributed.dashboard import BokehWorker services = {("dashboard", ":0"): BokehWorker} w = Worker(s.address, services={("dashboard", ":0"): BokehWorker}) yield w._start("tcp://0.0.0.0") sock = first(w.services["dashboard"].server._http._sockets.values()) assert sock.getsockname()[0] in ("::", "0.0.0.0") yield w.close() w = Worker(s.address, services={("dashboard", ":0"): BokehWorker}) yield w._start("tcp://127.0.0.1") sock = first(w.services["dashboard"].server._http._sockets.values()) assert sock.getsockname()[0] in ("::", "0.0.0.0") yield w.close() w = Worker(s.address, services={("dashboard", 0): BokehWorker}) yield w._start("tcp://127.0.0.1") sock = first(w.services["dashboard"].server._http._sockets.values()) assert sock.getsockname()[0] == "127.0.0.1" yield w.close()