Ejemplo n.º 1
0
async def test_map_n():
    todo = range(2, 11)
    async with AioPool(size=3) as pool:
        futures = pool.map_n(wrk, todo, cb)

    results = [getres.flat(f) for f in futures]
    assert 2 * sum(todo) == sum(results)
Ejemplo n.º 2
0
async def loadtest_spawn_n(tasks, pool_size, duration):
    futures = []
    async with AioPool(size=pool_size) as pool:
        for i in range(tasks):
            fut = await pool.spawn_n(aio.sleep(duration))
            futures.append(fut)

    return [getres.flat(f) for f in futures]
Ejemplo n.º 3
0
async def test_spawn_n():
    todo = range(5)
    futures = []
    async with AioPool(size=2) as pool:
        for i in todo:
            ctx = (pool, i)
            fut = pool.spawn_n(wrk(i), cb, ctx)
            futures.append(fut)

    results = [getres.flat(f) for f in futures]
    assert all(isinstance(e, ZeroDivisionError) for e in results[:2])
    assert sum(results[2:]) == 2 * (sum(todo) - 0 - 1)