From 5f584db8d55a6db76c4307b21cb658a2bacb0296 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Wed, 1 Apr 2015 10:57:32 +1300 Subject: [PATCH] Do sleep(0) for first task sleep This results in a functional test run which is up to 20% faster than the current sleep(1) Closes-Bug: #1439216 Change-Id: I1f594963dd164e44b8d9c601610a4036a0253ece --- heat/engine/scheduler.py | 11 ++++++----- heat/tests/test_scheduler.py | 10 +++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/heat/engine/scheduler.py b/heat/engine/scheduler.py index e3e375743..c676d0755 100644 --- a/heat/engine/scheduler.py +++ b/heat/engine/scheduler.py @@ -168,13 +168,14 @@ class TaskRunner(object): """ Start and run the task to completion. - The task will sleep for `wait_time` seconds between steps. To avoid - sleeping, pass `None` for `wait_time`. + The task will first sleep for zero seconds, then sleep for `wait_time` + seconds between steps. To avoid 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) + # ensure that zero second sleep is applied only if task + # has not completed. + if not self.done() and wait_time: + self._sleep(0) 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 88da32e1f..16a620a8b 100644 --- a/heat/tests/test_scheduler.py +++ b/heat/tests/test_scheduler.py @@ -45,7 +45,7 @@ class PollingTaskGroupTest(common.HeatTestCase): self.m.StubOutWithMock(t, 'do_step') self.m.StubOutWithMock(scheduler.TaskRunner, '_sleep') - scheduler.TaskRunner._sleep(1).AndReturn(None) + scheduler.TaskRunner._sleep(0).AndReturn(None) for t in tasks: t.do_step(1).AndReturn(None) @@ -221,7 +221,6 @@ class DependencyTaskGroupTest(common.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: @@ -453,7 +452,7 @@ class TaskTest(common.HeatTestCase): self.m.StubOutWithMock(scheduler.TaskRunner, '_sleep') task.do_step(1).AndReturn(None) - scheduler.TaskRunner._sleep(1).AndReturn(None) + scheduler.TaskRunner._sleep(0).AndReturn(None) task.do_step(2).AndReturn(None) scheduler.TaskRunner._sleep(1).AndReturn(None) task.do_step(3).AndReturn(None) @@ -469,7 +468,7 @@ class TaskTest(common.HeatTestCase): self.m.StubOutWithMock(scheduler.TaskRunner, '_sleep') task.do_step(1).AndReturn(None) - scheduler.TaskRunner._sleep(42).AndReturn(None) + scheduler.TaskRunner._sleep(0).AndReturn(None) task.do_step(2).AndReturn(None) scheduler.TaskRunner._sleep(42).AndReturn(None) task.do_step(3).AndReturn(None) @@ -516,6 +515,7 @@ class TaskTest(common.HeatTestCase): def test_sleep(self): sleep_time = 42 self.m.StubOutWithMock(eventlet, 'sleep') + eventlet.sleep(0).AndReturn(None) eventlet.sleep(sleep_time).MultipleTimes().AndReturn(None) self.m.ReplayAll() @@ -970,7 +970,7 @@ class WrapperTaskTest(common.HeatTestCase): self.m.StubOutWithMock(child_task, 'do_step') self.m.StubOutWithMock(scheduler.TaskRunner, '_sleep') - scheduler.TaskRunner._sleep(1).AndReturn(None) + scheduler.TaskRunner._sleep(0).AndReturn(None) for child_task in child_tasks: child_task.do_step(1).AndReturn(None) scheduler.TaskRunner._sleep(1).AndReturn(None)