Merge "Fix unstable DB migration tests"

This commit is contained in:
Jenkins 2016-03-11 13:55:38 +00:00 committed by Gerrit Code Review
commit 162ce803d6
2 changed files with 31 additions and 0 deletions

View File

@ -26,6 +26,7 @@ from sqlalchemy.sql import text
from manila.db.migrations.alembic import migration
from manila.tests.db.migrations.alembic import migrations_data_checks
from manila.tests import utils as test_utils
LOG = log.getLogger('manila.tests.test_migrations')
@ -138,6 +139,13 @@ class ManilaMigrationsCheckers(test_migrations.WalkVersionsMixin,
'exception': e})
raise
# NOTE(vponomaryov): set 5 minutes timeout for case of running it on
# very slow nodes/VMs. Note, that this test becomes slower with each
# addition of new DB migration. On fast nodes it can take about 5-10 secs
# having Mitaka set of migrations.
# 'pymysql' works much slower on slow nodes than 'psycopg2'. And such
# timeout mostly required for testing of 'mysql' backend.
@test_utils.set_timeout(300)
def test_walk_versions(self):
"""Walks all version scripts for each tested database.
@ -163,6 +171,7 @@ class TestManilaMigrationsMySQL(ManilaMigrationsCheckers,
test_base.MySQLOpportunisticTestCase):
"""Run migration tests on MySQL backend."""
@test_utils.set_timeout(300)
def test_mysql_innodb(self):
"""Test that table creation on mysql only builds InnoDB tables."""
with mock.patch('manila.db.sqlalchemy.api.get_engine',

View File

@ -14,9 +14,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import fixtures
import os
from oslo_config import cfg
import six
from manila import context
from manila import utils
@ -35,6 +37,26 @@ def is_manila_installed():
return False
def set_timeout(timeout):
"""Timeout decorator for unit test methods.
Use this decorator for tests that are expected to pass in very specific
amount of time, not common for all other tests.
It can have either big or small value.
"""
def _decorator(f):
@six.wraps(f)
def _wrapper(self, *args, **kwargs):
self.useFixture(fixtures.Timeout(timeout, gentle=True))
return f(self, *args, **kwargs)
return _wrapper
return _decorator
class create_temp_config_with_opts(object):
"""Creates temporary config file with provided opts and values.