Revert "Move wait_until_true to neutron-lib"
This reverts commit afa7aed0d8e67c6bef536a3a2b592929f831e490. Imports eventlet. Missing release note. Change-Id: I3fdec8a0990c11a69256db4f5eaa231114a44df1
This commit is contained in:
parent
afa7aed0d8
commit
dcff4ba6e4
@ -14,8 +14,6 @@
|
||||
import collections
|
||||
import re
|
||||
|
||||
import eventlet
|
||||
import mock
|
||||
import six
|
||||
import testtools
|
||||
|
||||
@ -224,25 +222,3 @@ class TestSafeSortKey(base.BaseTestCase):
|
||||
data2 = self._create_dict_from_list(list2)
|
||||
self.assertEqual(helpers.safe_sort_key(data1),
|
||||
helpers.safe_sort_key(data2))
|
||||
|
||||
|
||||
class TestWaitUntilTrue(base.BaseTestCase):
|
||||
def test_wait_until_true_predicate_succeeds(self):
|
||||
helpers.wait_until_true(lambda: True)
|
||||
|
||||
def test_wait_until_true_predicate_fails(self):
|
||||
with testtools.ExpectedException(eventlet.timeout.Timeout):
|
||||
helpers.wait_until_true(lambda: False, 2)
|
||||
|
||||
def test_wait_until_true_predicate_fails_long_sleep(self):
|
||||
predicate = mock.Mock(return_value=False)
|
||||
with testtools.ExpectedException(eventlet.timeout.Timeout):
|
||||
helpers.wait_until_true(predicate, 7, 3)
|
||||
self.assertEqual(3, predicate.call_count)
|
||||
|
||||
def test_wait_until_true_predicate_fails_custom_exception(self):
|
||||
class PrivateTimeoutException(Exception):
|
||||
pass
|
||||
with testtools.ExpectedException(PrivateTimeoutException):
|
||||
helpers.wait_until_true(lambda: False, 2,
|
||||
exception=PrivateTimeoutException)
|
||||
|
@ -15,7 +15,6 @@ import collections
|
||||
import decimal
|
||||
import random
|
||||
|
||||
import eventlet
|
||||
import six
|
||||
|
||||
from neutron_lib._i18n import _
|
||||
@ -177,18 +176,3 @@ def safe_decode_utf8(s):
|
||||
if six.PY3 and isinstance(s, bytes):
|
||||
return s.decode('utf-8', 'surrogateescape')
|
||||
return s
|
||||
|
||||
|
||||
def wait_until_true(predicate, timeout=60, sleep=1, exception=None):
|
||||
"""Wait until callable predicate is evaluated as True
|
||||
|
||||
:param predicate: Callable deciding whether waiting should continue.
|
||||
Best practice is to instantiate predicate with functools.partial()
|
||||
:param timeout: Timeout in seconds how long should function wait.
|
||||
:param sleep: Polling interval for results in seconds.
|
||||
:param exception: Exception class for eventlet.Timeout.
|
||||
(see doc for eventlet.Timeout for more information)
|
||||
"""
|
||||
with eventlet.timeout.Timeout(timeout, exception):
|
||||
while not predicate():
|
||||
eventlet.sleep(sleep)
|
||||
|
Loading…
x
Reference in New Issue
Block a user