def test_service_hosts(): pytest.importorskip("bokeh") from distributed.bokeh.scheduler import BokehScheduler port = 0 for url, expected in [ ("tcp://0.0.0.0", ("::", "0.0.0.0")), ("tcp://127.0.0.1", "127.0.0.1"), ("tcp://127.0.0.1:38275", "127.0.0.1"), ]: services = {("bokeh", port): BokehScheduler} s = Scheduler(services=services) yield s.start(url) sock = first(s.services["bokeh"].server._http._sockets.values()) if isinstance(expected, tuple): assert sock.getsockname()[0] in expected else: assert sock.getsockname()[0] == expected yield s.close() port = ("127.0.0.1", 0) for url in ["tcp://0.0.0.0", "tcp://127.0.0.1", "tcp://127.0.0.1:38275"]: services = {("bokeh", port): BokehScheduler} s = Scheduler(services=services) yield s.start(url) sock = first(s.services["bokeh"].server._http._sockets.values()) assert sock.getsockname()[0] == "127.0.0.1" yield s.close()
def test_persist_taskstate(): s = Scheduler(validate=True, persist_file='persist_test') s.start(0) assert s.persist_scheduler s.update_graph(tasks={ 'x': dumps_task((inc, 1)), 'y': dumps_task((inc, 'x')), 'z': dumps_task((inc, 2)) }, keys=['y'], dependencies={ 'y': 'x', 'x': [], 'z': [] }, client='client') taskstates = s.tasks s.close() s.stop() del s s = Scheduler(validate=True, persist_file='persist_test') s.start(0) assert ([taskstates.keys()] == [s.tasks.keys()] and [x.state for x in taskstates.values() ] == [x.state for x in s.tasks.values()]) s.close() for f in glob.glob("persist_test*"): os.remove(f)
def test_service_hosts(): pytest.importorskip('bokeh') from distributed.bokeh.scheduler import BokehScheduler port = 0 for url, expected in [('tcp://0.0.0.0', ('::', '0.0.0.0')), ('tcp://127.0.0.1', '127.0.0.1'), ('tcp://127.0.0.1:38275', '127.0.0.1')]: services = {('bokeh', port): BokehScheduler} s = Scheduler(services=services) yield s.start(url) sock = first(s.services['bokeh'].server._http._sockets.values()) if isinstance(expected, tuple): assert sock.getsockname()[0] in expected else: assert sock.getsockname()[0] == expected yield s.close() port = ('127.0.0.1', 0) for url in ['tcp://0.0.0.0', 'tcp://127.0.0.1', 'tcp://127.0.0.1:38275']: services = {('bokeh', port): BokehScheduler} s = Scheduler(services=services) yield s.start(url) sock = first(s.services['bokeh'].server._http._sockets.values()) assert sock.getsockname()[0] == '127.0.0.1' yield s.close()
def test_launch_without_blocked_services(): from distributed.http import HTTPScheduler s = Scheduler(services={('http', 3849): HTTPScheduler}) s.start(0) s2 = Scheduler(services={('http', 3849): HTTPScheduler}) s2.start(0) assert not s2.services yield [s.close(), s2.close()]
def test_scheduler_as_center(): s = Scheduler() s.listen(0) done = s.start() a = Worker('127.0.0.1', s.port, ip='127.0.0.1', ncores=1) a.data.update({'x': 1, 'y': 2}) b = Worker('127.0.0.1', s.port, ip='127.0.0.1', ncores=2) b.data.update({'y': 2, 'z': 3}) c = Worker('127.0.0.1', s.port, ip='127.0.0.1', ncores=3) yield [w._start() for w in [a, b, c]] assert s.ncores == {w.address: w.ncores for w in [a, b, c]} assert s.who_has == { 'x': {a.address}, 'y': {a.address, b.address}, 'z': {b.address} } s.update_graph(dsk={'a': (inc, 1)}, keys=['a']) while not s.who_has['a']: yield gen.sleep(0.01) assert 'a' in a.data or 'a' in b.data or 'a' in c.data yield [w._close() for w in [a, b, c]] assert s.ncores == {} assert s.who_has == {} yield s.close()
def test_scheduler_as_center(): s = Scheduler() done = s.start(0) a = Worker('127.0.0.1', s.port, ip='127.0.0.1', ncores=1) a.data.update({'x': 1, 'y': 2}) b = Worker('127.0.0.1', s.port, ip='127.0.0.1', ncores=2) b.data.update({'y': 2, 'z': 3}) c = Worker('127.0.0.1', s.port, ip='127.0.0.1', ncores=3) yield [w._start(0) for w in [a, b, c]] assert s.ncores == {w.address: w.ncores for w in [a, b, c]} assert s.who_has == { 'x': {a.address}, 'y': {a.address, b.address}, 'z': {b.address} } s.update_graph(tasks={'a': dumps_task((inc, 1))}, keys=['a'], dependencies={'a': []}) start = time() while not s.who_has['a']: assert time() - start < 5 yield gen.sleep(0.01) assert 'a' in a.data or 'a' in b.data or 'a' in c.data with ignoring(StreamClosedError): yield [w._close() for w in [a, b, c]] assert s.ncores == {} assert s.who_has == {} yield s.close()
def test_scheduler_as_center(): s = Scheduler() s.listen(0) done = s.start() a = Worker('127.0.0.1', s.port, ip='127.0.0.1', ncores=1) a.data.update({'x': 1, 'y': 2}) b = Worker('127.0.0.1', s.port, ip='127.0.0.1', ncores=2) b.data.update({'y': 2, 'z': 3}) c = Worker('127.0.0.1', s.port, ip='127.0.0.1', ncores=3) yield [w._start() for w in [a, b, c]] assert s.ncores == {w.address: w.ncores for w in [a, b, c]} assert s.who_has == {'x': {a.address}, 'y': {a.address, b.address}, 'z': {b.address}} s.update_graph(dsk={'a': (inc, 1)}, keys=['a']) while not s.who_has['a']: yield gen.sleep(0.01) assert 'a' in a.data or 'a' in b.data or 'a' in c.data yield [w._close() for w in [a, b, c]] assert s.ncores == {} assert s.who_has == {} yield s.close()
def test_scheduler_as_center(): s = Scheduler(validate=True) done = s.start(0) a = Worker(s.address, ncores=1) a.data.update({'x': 1, 'y': 2}) b = Worker(s.address, ncores=2) b.data.update({'y': 2, 'z': 3}) c = Worker(s.address, ncores=3) yield [w._start(0) for w in [a, b, c]] assert s.ncores == {w.address: w.ncores for w in [a, b, c]} assert not s.who_has s.update_graph(tasks={'a': dumps_task((inc, 1))}, keys=['a'], dependencies={'a': []}) start = time() while not 'a' in s.who_has: assert time() - start < 5 yield gen.sleep(0.01) assert 'a' in a.data or 'a' in b.data or 'a' in c.data yield [w._close() for w in [a, b, c]] assert s.ncores == {} assert s.who_has == {} yield s.close()
def test_coerce_address(): with dask.config.set({'distributed.comm.timeouts.connect': '100ms'}): s = Scheduler(validate=True) s.start(0) print("scheduler:", s.address, s.listen_address) a = Worker(s.ip, s.port, name='alice') b = Worker(s.ip, s.port, name=123) c = Worker('127.0.0.1', s.port, name='charlie') yield [a._start(), b._start(), c._start()] assert s.coerce_address('127.0.0.1:8000') == 'tcp://127.0.0.1:8000' assert s.coerce_address('[::1]:8000') == 'tcp://[::1]:8000' assert s.coerce_address('tcp://127.0.0.1:8000') == 'tcp://127.0.0.1:8000' assert s.coerce_address('tcp://[::1]:8000') == 'tcp://[::1]:8000' assert s.coerce_address('localhost:8000') in ('tcp://127.0.0.1:8000', 'tcp://[::1]:8000') assert s.coerce_address(u'localhost:8000') in ('tcp://127.0.0.1:8000', 'tcp://[::1]:8000') assert s.coerce_address(a.address) == a.address # Aliases assert s.coerce_address('alice') == a.address assert s.coerce_address(123) == b.address assert s.coerce_address('charlie') == c.address assert s.coerce_hostname('127.0.0.1') == '127.0.0.1' assert s.coerce_hostname('alice') == a.ip assert s.coerce_hostname(123) == b.ip assert s.coerce_hostname('charlie') == c.ip assert s.coerce_hostname('jimmy') == 'jimmy' assert s.coerce_address('zzzt:8000', resolve=False) == 'tcp://zzzt:8000' yield s.close() yield [w._close() for w in [a, b, c]]
def test_coerce_address(): s = Scheduler(validate=True) s.start(0) print("scheduler:", s.address, s.listen_address) a = Worker(s.ip, s.port, name='alice') b = Worker(s.ip, s.port, name=123) c = Worker('127.0.0.1', s.port, name='charlie') yield [a._start(), b._start(), c._start()] assert s.coerce_address('127.0.0.1:8000') == 'tcp://127.0.0.1:8000' assert s.coerce_address('[::1]:8000') == 'tcp://[::1]:8000' assert s.coerce_address('tcp://127.0.0.1:8000') == 'tcp://127.0.0.1:8000' assert s.coerce_address('tcp://[::1]:8000') == 'tcp://[::1]:8000' assert s.coerce_address('localhost:8000') in ('tcp://127.0.0.1:8000', 'tcp://[::1]:8000') assert s.coerce_address(u'localhost:8000') in ('tcp://127.0.0.1:8000', 'tcp://[::1]:8000') assert s.coerce_address(a.address) == a.address # Aliases assert s.coerce_address('alice') == a.address assert s.coerce_address(123) == b.address assert s.coerce_address('charlie') == c.address assert s.coerce_hostname('127.0.0.1') == '127.0.0.1' assert s.coerce_hostname('alice') == a.ip assert s.coerce_hostname(123) == b.ip assert s.coerce_hostname('charlie') == c.ip assert s.coerce_hostname('jimmy') == 'jimmy' assert s.coerce_address('zzzt:8000', resolve=False) == 'tcp://zzzt:8000' yield s.close() yield [w._close() for w in [a, b, c]]
def test_scheduler_as_center(): s = Scheduler() done = s.start(0) a = Worker('127.0.0.1', s.port, ip='127.0.0.1', ncores=1) a.data.update({'x': 1, 'y': 2}) b = Worker('127.0.0.1', s.port, ip='127.0.0.1', ncores=2) b.data.update({'y': 2, 'z': 3}) c = Worker('127.0.0.1', s.port, ip='127.0.0.1', ncores=3) yield [w._start(0) for w in [a, b, c]] assert s.ncores == {w.address: w.ncores for w in [a, b, c]} assert s.who_has == {'x': {a.address}, 'y': {a.address, b.address}, 'z': {b.address}} s.update_graph(tasks={'a': dumps_task((inc, 1))}, keys=['a'], dependencies={'a': []}) start = time() while not s.who_has['a']: assert time() - start < 5 yield gen.sleep(0.01) assert 'a' in a.data or 'a' in b.data or 'a' in c.data with ignoring(StreamClosedError): yield [w._close() for w in [a, b, c]] assert s.ncores == {} assert s.who_has == {} yield s.close()
def test_service_hosts_match_scheduler(): from distributed.http.scheduler import HTTPScheduler services = {('http', 0): HTTPScheduler} s = Scheduler(services=services) yield s.start('tcp://0.0.0.0') sock = first(s.services['http']._sockets.values()) assert sock.getsockname()[0] in ('::', '0.0.0.0') yield s.close() for host in ['tcp://127.0.0.2', 'tcp://127.0.0.2:38275']: s = Scheduler(services=services) yield s.start(host) sock = first(s.services['http']._sockets.values()) assert sock.getsockname()[0] == '127.0.0.2' yield s.close()
def test_service_hosts_match_scheduler(): pytest.importorskip('bokeh') from distributed.bokeh.scheduler import BokehScheduler services = {('bokeh', 0): BokehScheduler} s = Scheduler(services=services) yield s.start('tcp://0.0.0.0') sock = first(s.services['bokeh'].server._http._sockets.values()) assert sock.getsockname()[0] in ('::', '0.0.0.0') yield s.close() for host in ['tcp://127.0.0.2', 'tcp://127.0.0.2:38275']: s = Scheduler(services=services) yield s.start(host) sock = first(s.services['bokeh'].server._http._sockets.values()) assert sock.getsockname()[0] == '127.0.0.2' yield s.close()
def test_scheduler_file(): with tmpfile() as fn: s = Scheduler(scheduler_file=fn) s.start(0) with open(fn) as f: data = json.load(f) assert data['address'] == s.address c = yield Client(scheduler_file=fn, loop=s.loop, asynchronous=True) yield s.close()
def test_scheduler_file(): with tmpfile() as fn: s = Scheduler(scheduler_file=fn) s.start(0) with open(fn) as f: data = json.load(f) assert data['address'] == s.address c = Client(scheduler_file=fn, loop=s.loop, start=False) yield c._start() yield s.close()
def test_file_descriptors_dont_leak(loop): psutil = pytest.importorskip('psutil') proc = psutil.Process() before = proc.num_fds() s = Scheduler() s.start(0) w = Worker(s.ip, s.port) @gen.coroutine def f(): yield w._start(0) yield w._close() loop.run_sync(f) during = proc.num_fds() s.stop() s.close() start = time() while proc.num_fds() > before: loop.run_sync(lambda: gen.sleep(0.01)) assert time() < start + 5
def test_worker_name(): s = Scheduler(validate=True) s.start(0) w = yield Worker(s.ip, s.port, name="alice") assert s.workers[w.address].name == "alice" assert s.aliases["alice"] == w.address with pytest.raises(ValueError): w2 = yield Worker(s.ip, s.port, name="alice") yield w2._close() yield s.close() yield w._close()
def test_worker_name(): s = Scheduler(validate=True) s.start(0) w = Worker(s.ip, s.port, name='alice') yield w._start() assert s.worker_info[w.address]['name'] == 'alice' assert s.aliases['alice'] == w.address with pytest.raises(ValueError): w = Worker(s.ip, s.port, name='alice') yield w._start() yield s.close() yield w._close()
def test_worker_name(): s = Scheduler() s.start(0) w = Worker(s.ip, s.port, name='alice') yield w._start() assert s.worker_info[w.address]['name'] == 'alice' assert s.aliases['alice'] == w.address with pytest.raises(ValueError): w = Worker(s.ip, s.port, name='alice') yield w._start() yield s.close() yield w._close()
def test_worker_name(): s = Scheduler(validate=True) s.start(0) w = Worker(s.ip, s.port, name='alice') yield w._start() assert s.workers[w.address].name == 'alice' assert s.aliases['alice'] == w.address with pytest.raises(ValueError): w2 = Worker(s.ip, s.port, name='alice') yield w2._start() yield w2._close() yield s.close() yield w._close()
def test_service_hosts(): pytest.importorskip('bokeh') from distributed.bokeh.scheduler import BokehScheduler for port in [0, ('127.0.0.3', 0)]: for url, expected in [('tcp://0.0.0.0', ('::', '0.0.0.0')), ('tcp://127.0.0.2', '127.0.0.2'), ('tcp://127.0.0.2:38275', '127.0.0.2')]: services = {('bokeh', port): BokehScheduler} s = Scheduler(services=services) yield s.start(url) sock = first(s.services['bokeh'].server._http._sockets.values()) if isinstance(port, tuple): # host explicitly overridden assert sock.getsockname()[0] == port[0] elif isinstance(expected, tuple): assert sock.getsockname()[0] in expected else: assert sock.getsockname()[0] == expected yield s.close()
def test_coerce_address(): with dask.config.set({"distributed.comm.timeouts.connect": "100ms"}): s = Scheduler(validate=True) s.start(0) print("scheduler:", s.address, s.listen_address) a = Worker(s.ip, s.port, name="alice") b = Worker(s.ip, s.port, name=123) c = Worker("127.0.0.1", s.port, name="charlie") yield [a, b, c] assert s.coerce_address("127.0.0.1:8000") == "tcp://127.0.0.1:8000" assert s.coerce_address("[::1]:8000") == "tcp://[::1]:8000" assert s.coerce_address( "tcp://127.0.0.1:8000") == "tcp://127.0.0.1:8000" assert s.coerce_address("tcp://[::1]:8000") == "tcp://[::1]:8000" assert s.coerce_address("localhost:8000") in ( "tcp://127.0.0.1:8000", "tcp://[::1]:8000", ) assert s.coerce_address(u"localhost:8000") in ( "tcp://127.0.0.1:8000", "tcp://[::1]:8000", ) assert s.coerce_address(a.address) == a.address # Aliases assert s.coerce_address("alice") == a.address assert s.coerce_address(123) == b.address assert s.coerce_address("charlie") == c.address assert s.coerce_hostname("127.0.0.1") == "127.0.0.1" assert s.coerce_hostname("alice") == a.ip assert s.coerce_hostname(123) == b.ip assert s.coerce_hostname("charlie") == c.ip assert s.coerce_hostname("jimmy") == "jimmy" assert s.coerce_address("zzzt:8000", resolve=False) == "tcp://zzzt:8000" yield s.close() yield [w._close() for w in [a, b, c]]
def test_coerce_address(): s = Scheduler() s.start(0) a = Worker(s.ip, s.port, name='alice') b = Worker(s.ip, s.port, name=123) c = Worker(s.ip, s.port, name='charlie', ip='127.0.0.2') yield [a._start(), b._start(), c._start()] assert s.coerce_address(b'127.0.0.1') == '127.0.0.1' assert s.coerce_address(('127.0.0.1', 8000)) == '127.0.0.1:8000' assert s.coerce_address(['127.0.0.1', 8000]) == '127.0.0.1:8000' assert s.coerce_address([b'127.0.0.1', 8000]) == '127.0.0.1:8000' assert s.coerce_address(('127.0.0.1', '8000')) == '127.0.0.1:8000' assert s.coerce_address(b'localhost') == '127.0.0.1' assert s.coerce_address('localhost') == '127.0.0.1' assert s.coerce_address(u'localhost') == '127.0.0.1' assert s.coerce_address('localhost:8000') == '127.0.0.1:8000' assert s.coerce_address(a.address) == a.address assert s.coerce_address(a.address_tuple) == a.address assert s.coerce_address(123) == b.address assert s.coerce_address('charlie') == c.address yield s.close() yield [w._close() for w in [a, b, c]]
def test_coerce_address(): s = Scheduler(validate=True) s.start(0) a = Worker(s.ip, s.port, name='alice') b = Worker(s.ip, s.port, name=123) c = Worker(s.ip, s.port, name='charlie', ip='127.0.0.2') yield [a._start(), b._start(), c._start()] assert s.coerce_address(b'127.0.0.1') == '127.0.0.1' assert s.coerce_address(('127.0.0.1', 8000)) == '127.0.0.1:8000' assert s.coerce_address(['127.0.0.1', 8000]) == '127.0.0.1:8000' assert s.coerce_address([b'127.0.0.1', 8000]) == '127.0.0.1:8000' assert s.coerce_address(('127.0.0.1', '8000')) == '127.0.0.1:8000' assert s.coerce_address(b'localhost') == '127.0.0.1' assert s.coerce_address('localhost') == '127.0.0.1' assert s.coerce_address(u'localhost') == '127.0.0.1' assert s.coerce_address('localhost:8000') == '127.0.0.1:8000' assert s.coerce_address(a.address) == a.address assert s.coerce_address(a.address_tuple) == a.address assert s.coerce_address(123) == b.address assert s.coerce_address('charlie') == c.address yield s.close() yield [w._close() for w in [a, b, c]]