diff options
| author | Michael Still <mikal@stillhq.com> | 2013-01-12 17:36:56 +1100 |
|---|---|---|
| committer | Michael Still <mikal@stillhq.com> | 2013-01-14 07:53:47 +1100 |
| commit | d0c5fe6be4d6b00c5947f4b2a37ca9f496941e8b (patch) | |
| tree | ebd31550b026f845bb333a087ccf1e11180040b7 | |
| parent | 59333ce9f3b012ad63a004d16534ad19e998d9a8 (diff) | |
Fix logic error in periodic task wait code.
I was calculating the time to wait for the next run of a periodic
task incorrectly.
Resolves bug 1098819.
Change-Id: Ida60b69014aa06229111e58024e35268262f18fb
| -rw-r--r-- | nova/manager.py | 5 | ||||
| -rw-r--r-- | nova/tests/test_periodic_tasks.py | 14 |
2 files changed, 17 insertions, 2 deletions
diff --git a/nova/manager.py b/nova/manager.py index cb15b776e..7df63f719 100644 --- a/nova/manager.py +++ b/nova/manager.py @@ -215,8 +215,9 @@ class Manager(base.Base): if self._periodic_spacing[task_name] is None: wait = 0 else: - wait = time.time() - (self._periodic_last_run[task_name] + - self._periodic_spacing[task_name]) + due = (self._periodic_last_run[task_name] + + self._periodic_spacing[task_name]) + wait = max(0, due - time.time()) if wait > 0.2: if wait < idle_for: idle_for = wait diff --git a/nova/tests/test_periodic_tasks.py b/nova/tests/test_periodic_tasks.py index 5804ea49b..39669967f 100644 --- a/nova/tests/test_periodic_tasks.py +++ b/nova/tests/test_periodic_tasks.py @@ -17,6 +17,7 @@ import fixtures +import time from nova import manager from nova import test @@ -76,6 +77,19 @@ class Manager(test.TestCase): idle = m.periodic_tasks(None) self.assertAlmostEqual(60, idle, 1) + def test_periodic_tasks_idle_calculation(self): + class Manager(manager.Manager): + @manager.periodic_task(spacing=10) + def bar(self): + return 'bar' + + m = Manager() + m.periodic_tasks(None) + time.sleep(0.1) + idle = m.periodic_tasks(None) + self.assertTrue(idle > 9.7) + self.assertTrue(idle < 9.9) + def test_periodic_tasks_disabled(self): class Manager(manager.Manager): @manager.periodic_task(spacing=-1) |
