Invert the conductor stop() returned result
Instead of returning whether the conductor is still dispatching return whether the stop was successful or whether it was not. This matches better with the expected semantics of the stop routine. Change-Id: Iccdca017e174adbd8eb3c093c6d0ea0c570792f5
This commit is contained in:
committed by
Joshua Harlow
parent
a53777bd2b
commit
059023417e
@@ -67,20 +67,22 @@ class SingleThreadedConductor(base.Conductor):
|
|||||||
|
|
||||||
@lock_utils.locked
|
@lock_utils.locked
|
||||||
def stop(self, timeout=None):
|
def stop(self, timeout=None):
|
||||||
"""Stops dispatching and returns whether the dispatcher loop is active
|
"""Requests the conductor to stop dispatching and returns whether the
|
||||||
or whether it has ceased. If a timeout is provided the dispatcher
|
stop request was successfully completed. If the dispatching is still
|
||||||
loop may not have ceased by the timeout reached (the request to cease
|
occurring then False is returned otherwise True will be returned to
|
||||||
will be honored in the future).
|
signal that the conductor is no longer dispatching job requests.
|
||||||
|
|
||||||
|
NOTE(harlowja): If a timeout is provided the dispatcher loop may
|
||||||
|
not have ceased by the timeout reached (the request to cease will
|
||||||
|
be honored in the future) and False will be returned indicating this.
|
||||||
"""
|
"""
|
||||||
self._wait_timeout.interrupt()
|
self._wait_timeout.interrupt()
|
||||||
self._dead.wait(timeout)
|
self._dead.wait(timeout)
|
||||||
return self.dispatching
|
return self._dead.is_set()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def dispatching(self):
|
def dispatching(self):
|
||||||
if self._dead.is_set():
|
return not self._dead.is_set()
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _dispatch_job(self, job):
|
def _dispatch_job(self, job):
|
||||||
LOG.info("Dispatching job: %s", job)
|
LOG.info("Dispatching job: %s", job)
|
||||||
|
|||||||
@@ -88,7 +88,8 @@ class SingleThreadedConductorTest(test_utils.EngineTestBase, test.TestCase):
|
|||||||
with close_many(components.conductor, components.client):
|
with close_many(components.conductor, components.client):
|
||||||
t = make_thread(components.conductor)
|
t = make_thread(components.conductor)
|
||||||
t.start()
|
t.start()
|
||||||
self.assertFalse(components.conductor.stop(0.5))
|
self.assertTrue(components.conductor.stop(0.5))
|
||||||
|
self.assertFalse(components.conductor.dispatching)
|
||||||
t.join()
|
t.join()
|
||||||
|
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
@@ -111,7 +112,7 @@ class SingleThreadedConductorTest(test_utils.EngineTestBase, test.TestCase):
|
|||||||
details={'flow_uuid': fd.uuid})
|
details={'flow_uuid': fd.uuid})
|
||||||
consumed_event.wait(1.0)
|
consumed_event.wait(1.0)
|
||||||
self.assertTrue(consumed_event.is_set())
|
self.assertTrue(consumed_event.is_set())
|
||||||
components.conductor.stop(1.0)
|
self.assertTrue(components.conductor.stop(1.0))
|
||||||
self.assertFalse(components.conductor.dispatching)
|
self.assertFalse(components.conductor.dispatching)
|
||||||
|
|
||||||
persistence = components.persistence
|
persistence = components.persistence
|
||||||
@@ -142,7 +143,7 @@ class SingleThreadedConductorTest(test_utils.EngineTestBase, test.TestCase):
|
|||||||
details={'flow_uuid': fd.uuid})
|
details={'flow_uuid': fd.uuid})
|
||||||
consumed_event.wait(1.0)
|
consumed_event.wait(1.0)
|
||||||
self.assertTrue(consumed_event.is_set())
|
self.assertTrue(consumed_event.is_set())
|
||||||
components.conductor.stop(1.0)
|
self.assertTrue(components.conductor.stop(1.0))
|
||||||
self.assertFalse(components.conductor.dispatching)
|
self.assertFalse(components.conductor.dispatching)
|
||||||
|
|
||||||
persistence = components.persistence
|
persistence = components.persistence
|
||||||
|
|||||||
Reference in New Issue
Block a user