Esempio n. 1
0
def test_same_futures(c, s, a, b):
    q = Queue('x')
    future = yield c._scatter(123)

    for i in range(5):
        yield q._put(future)

    assert s.wants_what['queue-x'] == {future.key}

    for i in range(4):
        future2 = yield q._get()
        assert s.wants_what['queue-x'] == {future.key}
        yield gen.sleep(0.05)
        assert s.wants_what['queue-x'] == {future.key}

    yield q._get()

    start = time()
    while s.wants_what['queue-x']:
        yield gen.sleep(0.01)
        assert time() - start < 2
Esempio n. 2
0
def test_race(c, s, *workers):
    def f(i):
        with worker_client() as c:
            q = Queue('x', client=c)
            for _ in range(100):
                future = q.get()
                x = future.result()
                y = c.submit(inc, x)
                q.put(y)
                sleep(0.01)
            result = q.get().result()
            return result

    q = Queue('x', client=c)
    L = yield c._scatter(range(5))
    for future in L:
        yield q._put(future)

    futures = c.map(f, range(5))
    results = yield c._gather(futures)
    assert all(r > 80 for r in results)
    qsize = yield q._qsize()
    assert not qsize