def test_task_stream_n_rectangles(c, s, a, b): ts = TaskStream(s, n_rectangles=10) futures = c.map(slowinc, range(10), delay=0.001) yield wait(futures) ts.update() assert len(ts.source.data["start"]) == 10
def test_task_stream_second_plugin(c, s, a, b): ts = TaskStream(s, n_rectangles=10, clear_interval=10) ts.update() futures = c.map(inc, range(10)) yield wait(futures) ts.update() ts2 = TaskStream(s, n_rectangles=5, clear_interval=10) ts2.update()
async def test_lots_of_tasks(c, s, a, b): import toolz ts = TaskStream(s) ts.update() futures = c.map(toolz.identity, range(100)) await wait(futures) tsp = [p for p in s.plugins if "taskstream" in type(p).__name__.lower()][0] assert len(tsp.buffer) == 10 ts.update() assert len(ts.source.data["start"]) == 10 assert "identity" in str(ts.source.data) futures = c.map(lambda x: x, range(100), pure=False) await wait(futures) ts.update() assert "lambda" in str(ts.source.data)
def test_task_stream_clear_interval(c, s, a, b): ts = TaskStream(s, clear_interval=200) yield wait(c.map(inc, range(10))) ts.update() yield gen.sleep(0.010) yield wait(c.map(dec, range(10))) ts.update() assert len(set(map(len, ts.source.data.values()))) == 1 assert ts.source.data["name"].count("inc") == 10 assert ts.source.data["name"].count("dec") == 10 yield gen.sleep(0.300) yield wait(c.map(inc, range(10, 20))) ts.update() assert len(set(map(len, ts.source.data.values()))) == 1 assert ts.source.data["name"].count("inc") == 10 assert ts.source.data["name"].count("dec") == 0
def test_task_stream(c, s, a, b): ts = TaskStream(s) futures = c.map(slowinc, range(10), delay=0.001) yield wait(futures) ts.update() d = dict(ts.source.data) assert all(len(L) == 10 for L in d.values()) assert min(d["start"]) == 0 # zero based ts.update() d = dict(ts.source.data) assert all(len(L) == 10 for L in d.values()) total = c.submit(sum, futures) yield wait(total) ts.update() d = dict(ts.source.data) assert len(set(map(len, d.values()))) == 1