diff --git a/manila/tests/db/migrations/alembic/test_migration.py b/manila/tests/db/migrations/alembic/test_migration.py index f45a0ed233..9eae6b47a5 100644 --- a/manila/tests/db/migrations/alembic/test_migration.py +++ b/manila/tests/db/migrations/alembic/test_migration.py @@ -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', diff --git a/manila/tests/utils.py b/manila/tests/utils.py index dfd6398c21..83e0ca9507 100644 --- a/manila/tests/utils.py +++ b/manila/tests/utils.py @@ -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.