summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-01-24 12:00:08 +0000
committerGerrit Code Review <review@openstack.org>2017-01-24 12:00:08 +0000
commit6f3869d136376a0e2f8d1730e1d9de31e94e43e3 (patch)
tree9344da8f078372590f73ded573c074d8d4dbac7e
parent6226aa1101583bb2e2b89196863b6f7ad47320c1 (diff)
parent7c0b05f0d84e48c68805ab2bd86db1eb11301d98 (diff)
downloadneutron-6f3869d136376a0e2f8d1730e1d9de31e94e43e3.tar.gz
Merge "Allow more time for DB migration tests" into stable/mitaka8.4.0
-rw-r--r--.testr.conf6
-rw-r--r--neutron/tests/base.py31
-rw-r--r--neutron/tests/functional/db/test_migrations.py7
3 files changed, 43 insertions, 1 deletions
diff --git a/.testr.conf b/.testr.conf
index c180b0319f..d96d48ed29 100644
--- a/.testr.conf
+++ b/.testr.conf
@@ -1,4 +1,8 @@
[DEFAULT]
-test_command=OS_STDOUT_CAPTURE=1 OS_STDERR_CAPTURE=1 OS_LOG_CAPTURE=1 ${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./neutron/tests/unit} $LISTOPT $IDOPTION
+test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
+ OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
+ OS_LOG_CAPTURE=${OS_LOG_CAPTURE:-1} \
+ OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-160} \
+ ${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./neutron/tests/unit} $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list
diff --git a/neutron/tests/base.py b/neutron/tests/base.py
index a303ed2479..4161eef793 100644
--- a/neutron/tests/base.py
+++ b/neutron/tests/base.py
@@ -424,3 +424,34 @@ class PluginFixture(fixtures.Fixture):
if plugin() and not isinstance(plugin(), mock.Base):
raise AssertionError(
'The plugin for this test was not deallocated.')
+
+
+class Timeout(fixtures.Fixture):
+ """Setup per test timeouts.
+
+ In order to avoid test deadlocks we support setting up a test
+ timeout parameter read from the environment. In almost all
+ cases where the timeout is reached this means a deadlock.
+
+ A scaling factor allows extremely long tests to specify they
+ need more time.
+ """
+
+ def __init__(self, timeout=None, scaling=1):
+ super(Timeout, self).__init__()
+ if timeout is None:
+ timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
+ try:
+ self.test_timeout = int(timeout)
+ except ValueError:
+ # If timeout value is invalid do not set a timeout.
+ self.test_timeout = 0
+ if scaling >= 1:
+ self.test_timeout *= scaling
+ else:
+ raise ValueError('scaling value must be >= 1')
+
+ def setUp(self):
+ super(Timeout, self).setUp()
+ if self.test_timeout > 0:
+ self.useFixture(fixtures.Timeout(self.test_timeout, gentle=True))
diff --git a/neutron/tests/functional/db/test_migrations.py b/neutron/tests/functional/db/test_migrations.py
index 214abe283b..77e98e6a1b 100644
--- a/neutron/tests/functional/db/test_migrations.py
+++ b/neutron/tests/functional/db/test_migrations.py
@@ -27,6 +27,7 @@ import neutron.db.migration as migration_help
from neutron.db.migration.alembic_migrations import external
from neutron.db.migration import cli as migration
from neutron.db.migration.models import head as head_models
+from neutron.tests import base as ntest_base
from neutron.tests.common import base
cfg.CONF.import_opt('core_plugin', 'neutron.common.config')
@@ -99,6 +100,8 @@ class _TestModelsMigrations(test_migrations.ModelsMigrationsSync):
- wrong value.
'''
+ TIMEOUT_SCALING_FACTOR = 4
+
def setUp(self):
super(_TestModelsMigrations, self).setUp()
self.cfg = self.useFixture(config_fixture.Config())
@@ -106,6 +109,10 @@ class _TestModelsMigrations(test_migrations.ModelsMigrationsSync):
self.alembic_config = migration.get_neutron_config()
self.alembic_config.neutron_config = cfg.CONF
+ # Migration tests can take a long time
+ self.useFixture(
+ ntest_base.Timeout(scaling=self.TIMEOUT_SCALING_FACTOR))
+
def db_sync(self, engine):
cfg.CONF.set_override('connection', engine.url, group='database')
migration.do_alembic_command(self.alembic_config, 'upgrade', 'heads')