diff --git a/oslo_messaging/_drivers/common.py b/oslo_messaging/_drivers/common.py index 9b35c5dd9..d46400f47 100644 --- a/oslo_messaging/_drivers/common.py +++ b/oslo_messaging/_drivers/common.py @@ -347,6 +347,9 @@ class DecayingTimer(object): def start(self): self._watch.start() + def restart(self): + self._watch.restart() + def check_return(self, timeout_callback=None, *args, **kwargs): maximum = kwargs.pop('maximum', None) left = self._watch.leftover(return_none=True) diff --git a/oslo_messaging/tests/test_utils.py b/oslo_messaging/tests/test_utils.py index 908c25fbf..05ca1c261 100644 --- a/oslo_messaging/tests/test_utils.py +++ b/oslo_messaging/tests/test_utils.py @@ -97,3 +97,17 @@ class TimerTestCase(test_utils.BaseTestCase): remaining = t.check_return(callback, 1, a='b') self.assertEqual(0, remaining) callback.assert_called_once_with(1, a='b') + + @mock.patch('oslo_utils.timeutils.now') + def test_reset(self, now): + now.return_value = 0 + t = common.DecayingTimer(3) + t.start() + + now.return_value = 1 + remaining = t.check_return() + self.assertEqual(2, remaining) + + t.restart() + remaining = t.check_return() + self.assertEqual(3, remaining)