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
This commit is contained in:
Steve Baker 2015-04-01 10:57:32 +13:00
parent 1eae9e6019
commit 5f584db8d5
2 changed files with 11 additions and 10 deletions

View File

@ -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):

View File

@ -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)