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
This commit is contained in:
parent
59333ce9f3
commit
d0c5fe6be4
@ -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] +
|
||||
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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user