From 1de87a9b369a5b191bb26b9a20636c0159473d20 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Wed, 22 Jun 2016 20:40:46 +0200 Subject: [PATCH] Always call TaskRunner._sleep() In the patch 5f584db8d55a6db76c4307b21cb658a2bacb0296, we avoid calling TaskRunner._sleep() after the first step if the wait_time is 0 or None. This is wrong in the case of a wait_time of 0 - since this is distinct from None, and should result in us calling eventlet.sleep(0). It's also inconsistent in the case of wait_time=None, since for the rest of the steps we call self._sleep(None) (and no actual sleep occurs). This patch ensures we always call self._sleep(), passing 0 or None as appropriate. It also enhances the change in d66d57f187c7d8623526e9f928ae76d2cca9ecf9 to ensure that we never yield from DependencyTaskGroup after all tasks are completed, which could happen if that last batch of tasks to be started all completed in a single step. This both saves changing the unit test to accomodate the new _sleep(None) call and avoids an unnecessary eventlet.sleep(0) call in real usage. Change-Id: I301930fcba170e36d2d902c8d693ca722476cd18 --- heat/engine/scheduler.py | 7 ++++--- heat/tests/test_stack_update.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/heat/engine/scheduler.py b/heat/engine/scheduler.py index 477e758757..3ccc292b9f 100644 --- a/heat/engine/scheduler.py +++ b/heat/engine/scheduler.py @@ -177,8 +177,8 @@ class TaskRunner(object): self.start(timeout=timeout) # ensure that zero second sleep is applied only if task # has not completed. - if not self.done() and wait_time: - self._sleep(0) + if not self.done(): + self._sleep(0 if wait_time is not None else None) self.run_to_completion(wait_time=wait_time) def start(self, timeout=None): @@ -431,7 +431,8 @@ class DependencyTaskGroup(object): if not r: del self._graph[k] - yield + if self._graph: + yield for k, r in self._running(): if r.step(): diff --git a/heat/tests/test_stack_update.py b/heat/tests/test_stack_update.py index 2b2d3e86a2..139d3ba3a5 100644 --- a/heat/tests/test_stack_update.py +++ b/heat/tests/test_stack_update.py @@ -854,7 +854,7 @@ class StackUpdateTest(common.HeatTestCase): tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'AResource': {'Type': 'GenericResourceType'}, - 'BResource': {'Type': 'GenericResourceType'}}} + 'BResource': {'Type': 'MultiStepResourceType'}}} updated_stack = stack.Stack(self.ctx, 'updated_stack', template.Template(tmpl2), disable_rollback=disable_rollback)