Beispiel #1
0
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_directory, pyzname))
    assert not os.path.exists(os.path.join(b.local_directory, pyzname))
    assert a.local_directory != b.local_directory

    yield c.upload_file(filename=local_file)

    assert os.path.exists(os.path.join(a.local_directory, pyzname))
    assert os.path.exists(os.path.join(b.local_directory, 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 c.close()
    yield s.close()
    yield a.close()
    yield b.close()
    assert not os.path.exists(os.path.join(a.local_directory, pyzname))
Beispiel #2
0
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_directory, eggname))
    assert not os.path.exists(os.path.join(b.local_directory, eggname))
    assert a.local_directory != b.local_directory

    yield c.upload_file(filename=local_file)

    assert os.path.exists(os.path.join(a.local_directory, eggname))
    assert os.path.exists(os.path.join(b.local_directory, 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 c.close()
    yield s.close()
    yield a.close()
    yield b.close()
    assert not os.path.exists(os.path.join(a.local_directory, eggname))
Beispiel #3
0
def test_resources(c, s):
    assert not s.worker_resources
    assert not s.resources

    a = Worker(s.address, loop=s.loop, resources={"GPU": 2})
    b = Worker(s.address, 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()
Beispiel #4
0
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_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