diff --git a/heat/engine/scheduler.py b/heat/engine/scheduler.py index e98474f88..9fbeb15e5 100644 --- a/heat/engine/scheduler.py +++ b/heat/engine/scheduler.py @@ -139,6 +139,9 @@ class TaskRunner(object): sleeping, pass `None` for `wait_time`. """ self.start(timeout=timeout) + # ensure that wait is applied only if task has not completed. + if not self.done(): + self._sleep(wait_time) self.run_to_completion(wait_time=wait_time) def start(self, timeout=None): diff --git a/heat/tests/test_scheduler.py b/heat/tests/test_scheduler.py index 8733238fb..cf83a3e89 100644 --- a/heat/tests/test_scheduler.py +++ b/heat/tests/test_scheduler.py @@ -14,7 +14,6 @@ import contextlib import eventlet -import mox from heat.engine import dependencies from heat.engine import scheduler @@ -46,13 +45,14 @@ class PollingTaskGroupTest(HeatTestCase): self.m.StubOutWithMock(t, 'do_step') self.m.StubOutWithMock(scheduler.TaskRunner, '_sleep') + scheduler.TaskRunner._sleep(1).AndReturn(None) for t in tasks: t.do_step(1).AndReturn(None) for t in tasks: - scheduler.TaskRunner._sleep(mox.IsA(int)).AndReturn(None) + scheduler.TaskRunner._sleep(1).AndReturn(None) t.do_step(2).AndReturn(None) - scheduler.TaskRunner._sleep(mox.IsA(int)).AndReturn(None) + scheduler.TaskRunner._sleep(1).AndReturn(None) t.do_step(3).AndReturn(None) self.m.ReplayAll() @@ -219,6 +219,7 @@ class DependencyTaskGroupTest(HeatTestCase): self.m.StubOutWithMock(scheduler.TaskRunner, '_sleep') with self._dep_test(('second', 'first')): scheduler.TaskRunner._sleep(None).AndReturn(None) + scheduler.TaskRunner._sleep(None).AndReturn(None) def test_single_node(self): with self._dep_test(('only', None)) as dummy: @@ -416,6 +417,7 @@ class TaskTest(HeatTestCase): task.do_step(2).AndReturn(None) scheduler.TaskRunner._sleep(1).AndReturn(None) task.do_step(3).AndReturn(None) + scheduler.TaskRunner._sleep(1).AndReturn(None) self.m.ReplayAll() @@ -431,6 +433,7 @@ class TaskTest(HeatTestCase): task.do_step(2).AndReturn(None) scheduler.TaskRunner._sleep(42).AndReturn(None) task.do_step(3).AndReturn(None) + scheduler.TaskRunner._sleep(42).AndReturn(None) self.m.ReplayAll() @@ -732,13 +735,14 @@ class WrapperTaskTest(HeatTestCase): self.m.StubOutWithMock(child_task, 'do_step') self.m.StubOutWithMock(scheduler.TaskRunner, '_sleep') + scheduler.TaskRunner._sleep(1).AndReturn(None) for child_task in child_tasks: child_task.do_step(1).AndReturn(None) - scheduler.TaskRunner._sleep(mox.IsA(int)).AndReturn(None) + scheduler.TaskRunner._sleep(1).AndReturn(None) child_task.do_step(2).AndReturn(None) - scheduler.TaskRunner._sleep(mox.IsA(int)).AndReturn(None) + scheduler.TaskRunner._sleep(1).AndReturn(None) child_task.do_step(3).AndReturn(None) - scheduler.TaskRunner._sleep(mox.IsA(int)).AndReturn(None) + scheduler.TaskRunner._sleep(1).AndReturn(None) self.m.ReplayAll()