def f():

        results = yield All([inc(i) for i in range(10)])
        assert results == list(range(1, 11))

        start = time()
        for tasks in [[throws(), slow()], [slow(), throws()]]:
            try:
                yield All(tasks)
                assert False
            except ZeroDivisionError:
                pass
            end = time()
            assert end - start < 10
def test_stress_creation_and_deletion(c, s):
    # Assertions are handled by the validate mechanism in the scheduler
    s.allowed_failures = 100000
    da = pytest.importorskip('dask.array')

    x = da.random.random(size=(2000, 2000), chunks=(100, 100))
    y = (x + 1).T + (x * 2) - x.mean(axis=1)

    z = c.persist(y)

    @gen.coroutine
    def create_and_destroy_worker(delay):
        start = time()
        while time() < start + 5:
            n = Nanny(s.address, ncores=2, loop=s.loop)
            n.start(0)

            yield gen.sleep(delay)

            yield n._close()
            print("Killed nanny")

    yield gen.with_timeout(timedelta(minutes=1),
                           All([create_and_destroy_worker(0.1 * i) for i in
                                range(20)]))
Esempio n. 3
0
def test_stress():
    with echo_server() as e:
        comm = yield connect(e.address)
        L = []

        @gen.coroutine
        def send():
            b = BatchedSend(interval=3)
            b.start(comm)
            for i in range(0, 10000, 2):
                b.send(i)
                b.send(i + 1)
                yield gen.sleep(0.00001 * random.randint(1, 10))

        @gen.coroutine
        def recv():
            while True:
                result = yield gen.with_timeout(timedelta(seconds=1),
                                                comm.read())
                L.extend(result)
                if result[-1] == 9999:
                    break

        yield All([send(), recv()])

        assert L == list(range(0, 10000, 1))
        comm.close()
Esempio n. 4
0
def test_stress():
    with echo_server() as e:
        client = TCPClient()
        stream = yield client.connect('127.0.0.1', e.port)
        L = []

        @gen.coroutine
        def send():
            b = BatchedSend(interval=3)
            b.start(stream)
            for i in range(0, 10000, 2):
                b.send(i)
                b.send(i + 1)
                yield gen.sleep(0.00001 * random.randint(1, 10))

        @gen.coroutine
        def recv():
            while True:
                result = yield gen.with_timeout(timedelta(seconds=1),
                                                read(stream))
                print(result)
                L.extend(result)
                if result[-1] == 9999:
                    break

        yield All([send(), recv()])

        assert L == list(range(0, 10000, 1))
        stream.close()
Esempio n. 5
0
 def f():
     scheduler = rpc(nannies[0].scheduler.address)
     if nanny:
         yield gen.with_timeout(timedelta(seconds=2),
                 All([scheduler.unregister(address=n.worker_address, close=True)
                      for n in nannies if n.process and n.worker_address]),
                 io_loop=loop2)
Esempio n. 6
0
 def f():
     if nanny:
         w = nannies[0]
         with w.rpc(w.scheduler.address) as scheduler:
             yield gen.with_timeout(timeout=timedelta(seconds=2),
                                    future=All([
                                        scheduler.unregister(
                                            address=n.worker_address,
                                            close=True) for n in nannies
                                        if n.process and n.worker_address
                                    ]),
                                    io_loop=loop2)
Esempio n. 7
0
def test_all_exceptions_logging():
    @gen.coroutine
    def throws():
        raise Exception('foo1234')

    with captured_logger('') as sio:
        try:
            yield All([throws() for _ in range(5)], quiet_exceptions=Exception)
        except Exception:
            pass

        import gc
        gc.collect()
        yield gen.sleep(0.1)

    assert 'foo1234' not in sio.getvalue()
Esempio n. 8
0
async def test_stress_creation_and_deletion(c, s):
    # Assertions are handled by the validate mechanism in the scheduler
    s.allowed_failures = 100000
    da = pytest.importorskip("dask.array")

    x = da.random.random(size=(2000, 2000), chunks=(100, 100))
    y = (x + 1).T + (x * 2) - x.mean(axis=1)

    z = c.persist(y)

    async def create_and_destroy_worker(delay):
        start = time()
        while time() < start + 5:
            n = await Nanny(s.address, nthreads=2, loop=s.loop)
            await asyncio.sleep(delay)
            await n.close()
            print("Killed nanny")

    await asyncio.wait_for(
        All([create_and_destroy_worker(0.1 * i) for i in range(20)]), 60)