|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import asyncio |
| 4 | + |
3 | 5 | import pytest |
4 | 6 |
|
5 | 7 | np = pytest.importorskip("numpy") |
@@ -41,6 +43,34 @@ def assert_equal(a, b): |
41 | 43 | assert a == b |
42 | 44 |
|
43 | 45 |
|
| 46 | +@gen_cluster(client=True) |
| 47 | +async def test_persist(c, s, a, b): |
| 48 | + df = pd.DataFrame({"x": range(10), "y": range(10, 20)}) |
| 49 | + ddf = dd.from_pandas(df, npartitions=2) |
| 50 | + df2 = pd.DataFrame({"x": range(20, 30), "y": range(30, 40)}) |
| 51 | + ddf2 = dd.from_pandas(df2, npartitions=2) |
| 52 | + |
| 53 | + ddfp = await c.persist(ddf) |
| 54 | + assert s.tasks |
| 55 | + assert sum(ts.state == "memory" for ts in s.tasks.values()) == 2 |
| 56 | + assert_equal(await c.compute(ddfp), await c.compute(ddf)) |
| 57 | + del ddfp |
| 58 | + |
| 59 | + while not sum(ts.state == "memory" for ts in s.tasks.values()) == 0: |
| 60 | + await asyncio.sleep(0.01) |
| 61 | + |
| 62 | + ddfp1, ddfp2 = c.persist((ddf, ddf2)) |
| 63 | + await wait((ddfp1, ddfp2)) |
| 64 | + assert s.tasks |
| 65 | + assert sum(ts.state == "memory" for ts in s.tasks.values()) == 4 |
| 66 | + |
| 67 | + assert_equal(await c.compute(ddfp1), await c.compute(ddf)) |
| 68 | + assert_equal(await c.compute(ddfp2), await c.compute(ddf2)) |
| 69 | + del ddfp1, ddfp2 |
| 70 | + while not sum(ts.state == "memory" for ts in s.tasks.values()) == 0: |
| 71 | + await asyncio.sleep(0.01) |
| 72 | + |
| 73 | + |
44 | 74 | @ignore_single_machine_warning |
45 | 75 | @gen_cluster(client=True) |
46 | 76 | async def test_dataframes(c, s, a, b): |
|
0 commit comments