def test_upload_file(c, s, a, b): assert not os.path.exists(os.path.join(a.local_dir, 'foobar.py')) assert not os.path.exists(os.path.join(b.local_dir, 'foobar.py')) assert a.local_dir != b.local_dir aa = rpc(a.address) bb = rpc(b.address) yield [aa.upload_file(filename='foobar.py', data=b'x = 123'), bb.upload_file(filename='foobar.py', data='x = 123')] assert os.path.exists(os.path.join(a.local_dir, 'foobar.py')) assert os.path.exists(os.path.join(b.local_dir, 'foobar.py')) def g(): import foobar return foobar.x future = c.submit(g, workers=a.address) result = yield future assert result == 123 yield a._close() yield b._close() aa.close_rpc() bb.close_rpc() assert not os.path.exists(os.path.join(a.local_dir, 'foobar.py'))
def test_upload_file(c, s, a, b): assert not os.path.exists(os.path.join(a.local_dir, "foobar.py")) assert not os.path.exists(os.path.join(b.local_dir, "foobar.py")) assert a.local_dir != b.local_dir aa = rpc(a.address) bb = rpc(b.address) yield [ aa.upload_file(filename="foobar.py", data=b"x = 123"), bb.upload_file(filename="foobar.py", data="x = 123"), ] assert os.path.exists(os.path.join(a.local_dir, "foobar.py")) assert os.path.exists(os.path.join(b.local_dir, "foobar.py")) def g(): import foobar return foobar.x future = c.submit(g, workers=a.address) result = yield future assert result == 123 yield a._close() yield b._close() aa.close_rpc() bb.close_rpc() assert not os.path.exists(os.path.join(a.local_dir, "foobar.py"))
def test_resources(c, s): assert not s.worker_resources assert not s.resources a = Worker(s.ip, s.port, loop=s.loop, resources={'GPU': 2}) b = Worker(s.ip, s.port, loop=s.loop, resources={'GPU': 1, 'DB': 1}) yield [a._start(), b._start()] assert s.resources == { 'GPU': { a.address: 2, b.address: 1 }, 'DB': { b.address: 1 } } assert s.worker_resources == { a.address: { 'GPU': 2 }, b.address: { 'GPU': 1, 'DB': 1 } } yield b._close() assert s.resources == {'GPU': {a.address: 2}, 'DB': {}} assert s.worker_resources == {a.address: {'GPU': 2}} yield a._close()
def test_global_workers(s, a, b): from distributed.worker import _global_workers n = len(_global_workers) w = _global_workers[-1]() assert w is a or w is b yield a._close() yield b._close() assert len(_global_workers) == n - 2
def test_resources(c, s): assert not s.worker_resources assert not s.resources a = Worker(s.ip, s.port, loop=s.loop, resources={"GPU": 2}) b = Worker(s.ip, s.port, loop=s.loop, resources={"GPU": 1, "DB": 1}) yield [a, b] assert s.resources == {"GPU": {a.address: 2, b.address: 1}, "DB": {b.address: 1}} assert s.worker_resources == {a.address: {"GPU": 2}, b.address: {"GPU": 1, "DB": 1}} yield b._close() assert s.resources == {"GPU": {a.address: 2}, "DB": {}} assert s.worker_resources == {a.address: {"GPU": 2}} yield a._close()
def test_resources(c, s): assert not s.worker_resources assert not s.resources a = Worker(s.ip, s.port, loop=s.loop, resources={'GPU': 2}) b = Worker(s.ip, s.port, loop=s.loop, resources={'GPU': 1, 'DB': 1}) yield [a._start(), b._start()] assert s.resources == {'GPU': {a.address: 2, b.address: 1}, 'DB': {b.address: 1}} assert s.worker_resources == {a.address: {'GPU': 2}, b.address: {'GPU': 1, 'DB': 1}} yield b._close() assert s.resources == {'GPU': {a.address: 2}, 'DB': {}} assert s.worker_resources == {a.address: {'GPU': 2}} yield a._close()
def test_upload_pyz(c, s, a, b): pyzname = 'mytest.pyz' local_file = __file__.replace('test_worker.py', pyzname) assert not os.path.exists(os.path.join(a.local_dir, pyzname)) assert not os.path.exists(os.path.join(b.local_dir, pyzname)) assert a.local_dir != b.local_dir yield c.upload_file(filename=local_file) assert os.path.exists(os.path.join(a.local_dir, pyzname)) assert os.path.exists(os.path.join(b.local_dir, pyzname)) def g(x): from mytest import mytest return mytest.inc(x) future = c.submit(g, 10, workers=a.address) result = yield future assert result == 10 + 1 yield a._close() yield b._close() assert not os.path.exists(os.path.join(a.local_dir, pyzname))
def test_upload_egg(c, s, a, b): eggname = 'testegg-1.0.0-py3.4.egg' local_file = __file__.replace('test_worker.py', eggname) assert not os.path.exists(os.path.join(a.local_dir, eggname)) assert not os.path.exists(os.path.join(b.local_dir, eggname)) assert a.local_dir != b.local_dir yield c.upload_file(filename=local_file) assert os.path.exists(os.path.join(a.local_dir, eggname)) assert os.path.exists(os.path.join(b.local_dir, eggname)) def g(x): import testegg return testegg.inc(x) future = c.submit(g, 10, workers=a.address) result = yield future assert result == 10 + 1 yield a._close() yield b._close() assert not os.path.exists(os.path.join(a.local_dir, eggname))