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:
Ihar Hrachyshka 2017-02-23 03:46:59 +00:00
parent a457949bf7
commit dfd4951889
2 changed files with 6 additions and 41 deletions

View File

@ -29,7 +29,6 @@ import time
import uuid
import weakref
import debtcollector
from debtcollector import removals
import eventlet
from eventlet.green import subprocess
@ -58,20 +57,8 @@ SYNCHRONIZED_PREFIX = 'neutron-'
synchronized = lockutils.synchronized_with_prefix(SYNCHRONIZED_PREFIX)
class WaitTimeout(Exception, eventlet.TimeoutError):
"""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)
class WaitTimeout(Exception):
"""Default exception coming from wait_until_true() function."""
@ -669,18 +656,10 @@ def wait_until_true(predicate, timeout=60, sleep=1, exception=None):
while not predicate():
except eventlet.TimeoutError:
if exception is None:
"Raising eventlet.TimeoutError by default has been deprecated",
message="wait_until_true() now raises WaitTimeout error by "
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
if exception is not None:
#pylint: disable=raising-bad-type
raise exception
raise WaitTimeout("Timed out after %d seconds" % timeout)
class _AuthenticBase(object):

View File

@ -12,8 +12,6 @@
import testtools
import eventlet
from neutron.common import utils
from neutron.tests import base
@ -25,15 +23,3 @@ class TestWaitUntilTrue(base.BaseTestCase):
def test_wait_until_true_predicate_fails(self):
with testtools.ExpectedException(utils.WaitTimeout):
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.
utils.wait_until_true(lambda: False, 2)
except eventlet.TimeoutError:
except Exception:
self.fail('wait_until_true() does not raise eventlet.TimeoutError '
'compatible exception by default.')