Merge "Add new test decorator skip_if_timeout"

This commit is contained in:
Zuul 2019-02-20 05:59:48 +00:00 committed by Gerrit Code Review
commit 9ad70979dd
2 changed files with 31 additions and 8 deletions

View File

@ -39,6 +39,7 @@ from oslo_utils import fileutils
from oslo_utils import strutils
from oslotest import base
import six
from sqlalchemy import exc as sqlalchemy_exc
import testtools
from neutron._i18n import _
@ -109,6 +110,28 @@ def unstable_test(reason):
return decor
def skip_if_timeout(reason):
def decor(f):
@functools.wraps(f)
def inner(self, *args, **kwargs):
try:
return f(self, *args, **kwargs)
except fixtures.TimeoutException:
msg = ("Timeout raised for test %s, skipping it "
"because of: %s") % (self.id(), reason)
raise self.skipTest(msg)
except sqlalchemy_exc.InterfaceError:
# In case of db tests very often TimeoutException is reason of
# some sqlalchemy InterfaceError exception and that is final
# raised exception which needs to be handled
msg = ("DB connection broken in test %s. It is very likely "
"that this happend because of test timeout. "
"Skipping test because of: %s") % (self.id(), reason)
raise self.skipTest(msg)
return inner
return decor
def set_timeout(timeout):
"""Timeout decorator for test methods.

View File

@ -361,7 +361,7 @@ class TestModelsMigrationsMysql(testlib_api.MySQLTestCaseMixin,
testlib_api.SqlTestCaseLight,
functional_base.BaseLoggingTestCase):
@test_base.unstable_test("bug 1687027")
@test_base.skip_if_timeout("bug 1687027")
def test_check_mysql_engine(self):
engine = self.get_engine()
cfg.CONF.set_override('connection', engine.url, group='database')
@ -380,29 +380,29 @@ class TestModelsMigrationsMysql(testlib_api.MySQLTestCaseMixin,
table != 'alembic_version']
self.assertEqual(0, len(res), "%s non InnoDB tables created" % res)
@test_base.unstable_test("bug 1687027")
@test_base.skip_if_timeout("bug 1687027")
def test_upgrade_expand_branch(self):
super(TestModelsMigrationsMysql, self).test_upgrade_expand_branch()
@test_base.unstable_test("bug 1687027")
@test_base.skip_if_timeout("bug 1687027")
def test_upgrade_contract_branch(self):
super(TestModelsMigrationsMysql, self).test_upgrade_contract_branch()
@test_base.unstable_test("bug 1687027")
@test_base.skip_if_timeout("bug 1687027")
def test_branches(self):
super(TestModelsMigrationsMysql, self).test_branches()
@test_base.unstable_test("bug 1687027")
@test_base.skip_if_timeout("bug 1687027")
def test_has_offline_migrations_pending_contract_scripts(self):
super(TestModelsMigrationsMysql,
self).test_has_offline_migrations_pending_contract_scripts()
@test_base.unstable_test("bug 1687027")
@test_base.skip_if_timeout("bug 1687027")
def test_has_offline_migrations_all_heads_upgraded(self):
super(TestModelsMigrationsMysql,
self).test_has_offline_migrations_all_heads_upgraded()
@test_base.unstable_test("bug 1687027")
@test_base.skip_if_timeout("bug 1687027")
def test_models_sync(self):
super(TestModelsMigrationsMysql, self).test_models_sync()
@ -625,7 +625,7 @@ class TestWalkMigrationsMysql(testlib_api.MySQLTestCaseMixin,
# on slow nodes than 'psycopg2' and because of that this increased
# timeout is required only when for testing with 'mysql' backend.
@test_base.set_timeout(600)
@test_base.unstable_test("bug 1687027")
@test_base.skip_if_timeout("bug 1687027")
def test_walk_versions(self):
super(TestWalkMigrationsMysql, self).test_walk_versions()