From bfe9e6f91e08cf42a6b5cbf3735f07b62f9866a3 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Fri, 8 Apr 2022 21:41:29 +0200 Subject: [PATCH] feat: schelule multiple task --- bopytex/scheduler.py | 2 +- test/test_scheduler.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/bopytex/scheduler.py b/bopytex/scheduler.py index 3b39bd3..db141c0 100644 --- a/bopytex/scheduler.py +++ b/bopytex/scheduler.py @@ -24,7 +24,7 @@ class Scheduler: return ans def __next__(self): - task = self._tasks.pop() + task = self._tasks.pop(0) ans = self.dispatch(task) self._done.append(ans) return ans diff --git a/test/test_scheduler.py b/test/test_scheduler.py index ce7b1c6..183a878 100644 --- a/test/test_scheduler.py +++ b/test/test_scheduler.py @@ -36,3 +36,26 @@ def test_schedule_one_task_with_args(): assert result == "one done" assert scheduler.tasks == [] assert scheduler.done == ["one done"] + + +def test_schedule_multiple_tasks(): + actions = {"DO": lambda deps, args: f"{args['task']} done"} + scheduler = Scheduler(actions) + t1 = Task(action="DO", args={"task": "one"}, deps=[]) + t2 = Task(action="DO", args={"task": "two"}, deps=[]) + t3 = Task(action="DO", args={"task": "three"}, deps=[]) + scheduler.append([t1, t2, t3]) + result = scheduler.__next__() + assert result == "one done" + assert scheduler.tasks == [t2, t3] + assert scheduler.done == ["one done"] + + result = scheduler.__next__() + assert result == "two done" + assert scheduler.tasks == [t3] + assert scheduler.done == ["one done", "two done"] + + result = scheduler.__next__() + assert result == "three done" + assert scheduler.tasks == [] + assert scheduler.done == ["one done", "two done", "three done"]