From 37c6e3179f96c6cd22b357030eee7a4218f3becd Mon Sep 17 00:00:00 2001 From: Valeriy Ponomaryov Date: Thu, 10 Mar 2016 21:56:31 +0200 Subject: [PATCH] Fix unstable DB migration tests Unit test 'test_walk_versions' in 'manila.tests.db.migrations.alembic.test_migration' module takes abnormally very long time sometimes. In common cases it takes about 5-10 seconds in CI for Mitaka set of DB migrations. In CI runs when this test fails, 'postgres' variant takes about 47 seconds and mysql reaches common test timeout of 60 seconds. Note, that this test becomes slower with each addition of new DB migration. Also, 'pymysql' works much slower on slow nodes than 'psycopg2'. So, add new test decorator that sets individual test timeout. And make it be 5 minutes for mentioned test. In worst case of Mitaka DB migrations set it can take about 2 minutes, but make it bigger to have a margin for future releases. Change-Id: I233f96f29fe62231c2e7013b74c06396dd923f27 Closes-Bug: #1501272 --- .../db/migrations/alembic/test_migration.py | 9 ++++++++ manila/tests/utils.py | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/manila/tests/db/migrations/alembic/test_migration.py b/manila/tests/db/migrations/alembic/test_migration.py index f45a0ed2..9eae6b47 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 dfd6398c..83e0ca95 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.