rabbit: fix timeout timer when duration is None
When the duration of the timeout timer used in the rabbit driver.is None and we want that the timer return a maximum of N secs it return None (infinite) instead of N. This change fixes that. Closes-bug: #1408370 Change-Id: I7f4cb3075f776c63aa7dc497173677f92b68c16d
This commit is contained in:
parent
f31f519e15
commit
44132d4344
@ -343,13 +343,13 @@ class DecayingTimer(object):
|
||||
return self
|
||||
|
||||
def check_return(self, timeout_callback, *args, **kwargs):
|
||||
maximum = kwargs.pop('maximum', None)
|
||||
if self._duration is None:
|
||||
return None
|
||||
return None if maximum is None else maximum
|
||||
if self._ends_at is None:
|
||||
raise RuntimeError("Can not check/return a timeout from a timer"
|
||||
" that has not been started")
|
||||
|
||||
maximum = kwargs.pop('maximum', None)
|
||||
left = self._ends_at - time.time()
|
||||
if left <= 0:
|
||||
timeout_callback(*args, **kwargs)
|
||||
|
@ -13,6 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo.messaging._drivers import common
|
||||
from oslo.messaging import _utils as utils
|
||||
from tests import utils as test_utils
|
||||
|
||||
@ -47,3 +48,17 @@ class VersionIsCompatibleTestCase(test_utils.BaseTestCase):
|
||||
|
||||
def test_version_is_compatible_no_rev_is_zero(self):
|
||||
self.assertTrue(utils.version_is_compatible('1.23.0', '1.23'))
|
||||
|
||||
|
||||
class TimerTestCase(test_utils.BaseTestCase):
|
||||
def test_duration_is_none(self):
|
||||
t = common.DecayingTimer()
|
||||
t.start()
|
||||
remaining = t.check_return(None)
|
||||
self.assertEqual(None, remaining)
|
||||
|
||||
def test_duration_is_none_and_maximun_set(self):
|
||||
t = common.DecayingTimer()
|
||||
t.start()
|
||||
remaining = t.check_return(None, maximum=2)
|
||||
self.assertEqual(2, remaining)
|
||||
|
Loading…
x
Reference in New Issue
Block a user