Untangle WaitTimeout class from eventlet.TimeoutError
This simplifies test code a bit. Previously, we introduced the WaitTimeout class to replace the eventlet.TimeoutError that inherited from BaseException and hence could interrupt normal test worker run. Now that we were initiating deprecation warning messages for a cycle when the user relied on eventlet.TimeoutError, we should be ok to remove the parent class from the list of inheritance for WaitTimeout. Change-Id: I6160cc1408f72a9f847a59702bc74b8e52a10497
This commit is contained in:
parent
a457949bf7
commit
dfd4951889
|
@ -29,7 +29,6 @@ import time
|
||||||
import uuid
|
import uuid
|
||||||
import weakref
|
import weakref
|
||||||
|
|
||||||
import debtcollector
|
|
||||||
from debtcollector import removals
|
from debtcollector import removals
|
||||||
import eventlet
|
import eventlet
|
||||||
from eventlet.green import subprocess
|
from eventlet.green import subprocess
|
||||||
|
@ -58,20 +57,8 @@ SYNCHRONIZED_PREFIX = 'neutron-'
|
||||||
synchronized = lockutils.synchronized_with_prefix(SYNCHRONIZED_PREFIX)
|
synchronized = lockutils.synchronized_with_prefix(SYNCHRONIZED_PREFIX)
|
||||||
|
|
||||||
|
|
||||||
class WaitTimeout(Exception, eventlet.TimeoutError):
|
class WaitTimeout(Exception):
|
||||||
"""Default exception coming from wait_until_true() function.
|
"""Default exception coming from wait_until_true() function."""
|
||||||
|
|
||||||
The reason is that eventlet.TimeoutError inherits from BaseException and
|
|
||||||
testtools.TestCase consumes only Exceptions. Which means in case
|
|
||||||
TimeoutError is raised, test runner stops and exits while it still has test
|
|
||||||
cases scheduled for execution.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return Exception.__str__(self)
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return Exception.__repr__(self)
|
|
||||||
|
|
||||||
|
|
||||||
@removals.remove(
|
@removals.remove(
|
||||||
|
@ -669,18 +656,10 @@ def wait_until_true(predicate, timeout=60, sleep=1, exception=None):
|
||||||
while not predicate():
|
while not predicate():
|
||||||
eventlet.sleep(sleep)
|
eventlet.sleep(sleep)
|
||||||
except eventlet.TimeoutError:
|
except eventlet.TimeoutError:
|
||||||
if exception is None:
|
if exception is not None:
|
||||||
debtcollector.deprecate(
|
#pylint: disable=raising-bad-type
|
||||||
"Raising eventlet.TimeoutError by default has been deprecated",
|
raise exception
|
||||||
message="wait_until_true() now raises WaitTimeout error by "
|
raise WaitTimeout("Timed out after %d seconds" % timeout)
|
||||||
"default.",
|
|
||||||
version="Ocata",
|
|
||||||
removal_version="Pike")
|
|
||||||
exception = WaitTimeout("Timed out after %d seconds" % timeout)
|
|
||||||
#NOTE(jlibosva): In case None is passed exception is instantiated on
|
|
||||||
# the line above.
|
|
||||||
#pylint: disable=raising-bad-type
|
|
||||||
raise exception
|
|
||||||
|
|
||||||
|
|
||||||
class _AuthenticBase(object):
|
class _AuthenticBase(object):
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
|
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
import eventlet
|
|
||||||
|
|
||||||
from neutron.common import utils
|
from neutron.common import utils
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
|
|
||||||
|
@ -25,15 +23,3 @@ class TestWaitUntilTrue(base.BaseTestCase):
|
||||||
def test_wait_until_true_predicate_fails(self):
|
def test_wait_until_true_predicate_fails(self):
|
||||||
with testtools.ExpectedException(utils.WaitTimeout):
|
with testtools.ExpectedException(utils.WaitTimeout):
|
||||||
utils.wait_until_true(lambda: False, 2)
|
utils.wait_until_true(lambda: False, 2)
|
||||||
|
|
||||||
def test_wait_until_true_predicate_fails_compatibility_test(self):
|
|
||||||
"""This test makes sure that eventlet.TimeoutError can still be caught.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
utils.wait_until_true(lambda: False, 2)
|
|
||||||
except eventlet.TimeoutError:
|
|
||||||
return
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
self.fail('wait_until_true() does not raise eventlet.TimeoutError '
|
|
||||||
'compatible exception by default.')
|
|
||||||
|
|
Loading…
Reference in New Issue