diff options
author | Mehdi Abaakouk <mehdi.abaakouk@enovance.com> | 2015-01-07 15:49:54 +0100 |
---|---|---|
committer | Edward Hope-Morley <edward.hope-morley@canonical.com> | 2015-04-16 17:13:32 +0100 |
commit | 106dd46101f536359df984394b5994f911df4912 (patch) | |
tree | a455bd0f1f9dd8c2e1a4150f718080cbc6f64fd6 | |
parent | b58180210145e1c804ec496576d6bb2caabc68ef (diff) | |
download | oslo-messaging-106dd46101f536359df984394b5994f911df4912.tar.gz |
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
(cherry picked from commit 44132d4344902f98007e6e58ea3bee56c701b400)
Change-Id: I7f4cb3075f776c63aa7dc497173677f92b68c16d
-rw-r--r-- | oslo/messaging/_drivers/common.py | 4 | ||||
-rw-r--r-- | tests/test_utils.py | 15 |
2 files changed, 17 insertions, 2 deletions
diff --git a/oslo/messaging/_drivers/common.py b/oslo/messaging/_drivers/common.py index 4e314b9..49fd712 100644 --- a/oslo/messaging/_drivers/common.py +++ b/oslo/messaging/_drivers/common.py @@ -521,13 +521,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) diff --git a/tests/test_utils.py b/tests/test_utils.py index 1321009..38ee1d0 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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) |