From ad0b6691e2a85d4b36978d02953dca2c289a82e6 Mon Sep 17 00:00:00 2001 From: whoami-rajat Date: Wed, 6 Feb 2019 21:32:30 +0530 Subject: [PATCH] Extend timeout for database migration tests Database migration tests (specifically test_walk_versions and test_mysql_innodb) are failing due to multiple reasons from oslo.db side mentioned in the code comments. Increasing the timeout will allow the tests to execute successfully on slower nodes. This solution is adopted from manila [1] and also implemented in neutron [2] for the same and hopefully they're not facing the issue currently. [1] https://review.openstack.org/#/c/291397/ [2] https://review.openstack.org/#/c/610003/ Change-Id: I31bdcfc12e3b8b54d5b5a6664f88df3b7dcd4fc0 --- cinder/tests/unit/db/test_migrations.py | 6 ++++++ cinder/tests/unit/utils.py | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/cinder/tests/unit/db/test_migrations.py b/cinder/tests/unit/db/test_migrations.py index 1568a174438..d006d47b291 100644 --- a/cinder/tests/unit/db/test_migrations.py +++ b/cinder/tests/unit/db/test_migrations.py @@ -34,6 +34,7 @@ from sqlalchemy.engine import reflection from cinder.db import migration import cinder.db.sqlalchemy.migrate_repo +from cinder.tests.unit import utils as test_utils class MigrationsMixin(test_migrations.WalkVersionsMixin): @@ -348,6 +349,10 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin): self.assertIn('destination_project_id', volume_transfer.c) self.assertIn('accepted', volume_transfer.c) + # NOTE: this test becomes slower with each addition of new DB migration. + # '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): self.walk_versions(False, False) self.assert_each_foreign_key_is_part_of_an_index() @@ -371,6 +376,7 @@ class TestMysqlMigrations(test_fixtures.OpportunisticDBTestMixin, FIXTURE = test_fixtures.MySQLOpportunisticFixture BOOL_TYPE = sqlalchemy.dialects.mysql.TINYINT + @test_utils.set_timeout(300) def test_mysql_innodb(self): """Test that table creation on mysql only builds InnoDB tables.""" # add this to the global lists to make reset work with it, it's removed diff --git a/cinder/tests/unit/utils.py b/cinder/tests/unit/utils.py index 1938a134567..4b849e77c29 100644 --- a/cinder/tests/unit/utils.py +++ b/cinder/tests/unit/utils.py @@ -14,6 +14,7 @@ # import datetime +import fixtures import socket import sys import uuid @@ -23,6 +24,7 @@ from oslo_config import cfg from oslo_service import loopingcall from oslo_utils import timeutils import oslo_versionedobjects +import six from cinder.common import constants from cinder import context @@ -534,3 +536,23 @@ def create_populated_cluster(ctxt, num_services, num_down_svcs=0, **values): for i in range(num_services) ] return cluster, svcs + + +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