Merge "test cleanup: Use oslotest's Timeout fixture"

This commit is contained in:
Zuul 2019-11-22 23:17:22 +00:00 committed by Gerrit Code Review
commit ab6aee61dd
4 changed files with 8 additions and 60 deletions

View File

@ -48,6 +48,7 @@ from oslo_utils import timeutils
from oslo_versionedobjects import fixture as ovo_fixture
from oslotest import mock_fixture
from oslotest import moxstubout
from oslotest import timeout
import six
from six.moves import builtins
import testtools
@ -178,9 +179,9 @@ class TestCase(testtools.TestCase):
def setUp(self):
"""Run before each test method to initialize test environment."""
super(TestCase, self).setUp()
self.useFixture(nova_fixtures.Timeout(
os.environ.get('OS_TEST_TIMEOUT', 0),
self.TIMEOUT_SCALING_FACTOR))
# The Timeout fixture picks up env.OS_TEST_TIMEOUT, defaulting to 0.
self.useFixture(timeout.Timeout(
scaling_factor=self.TIMEOUT_SCALING_FACTOR))
# How many of which service we've started. {$service-name: $count}
self._service_fixture_count = collections.defaultdict(int)

View File

@ -232,35 +232,6 @@ class OutputStreamCapture(fixtures.Fixture):
return self.out._details["stdout"].as_text()
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 class level TIMEOUT_SCALING_FACTOR also exists, which allows
extremely long tests to specify they need more time.
"""
def __init__(self, timeout, scaling=1):
super(Timeout, self).__init__()
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))
class DatabasePoisonFixture(fixtures.Fixture):
def setUp(self):
super(DatabasePoisonFixture, self).setUp()

View File

@ -42,6 +42,7 @@ from oslo_db.sqlalchemy import enginefacade
from oslo_db.sqlalchemy import test_fixtures
from oslo_db.sqlalchemy import test_migrations
from oslo_db.sqlalchemy import utils as oslodbutils
from oslotest import timeout
import sqlalchemy
from sqlalchemy.engine import reflection
import sqlalchemy.exc
@ -96,13 +97,9 @@ class NovaMigrationsCheckers(test_migrations.ModelsMigrationsSync,
self.useFixture(nova_fixtures.StandardLogging())
super(NovaMigrationsCheckers, self).setUp()
# NOTE(rpodolyaka): we need to repeat the functionality of the base
# test case a bit here as this gets overridden by oslotest base test
# case and nova base test case cleanup must be the last one (as it
# deletes attributes of test case instances)
self.useFixture(nova_fixtures.Timeout(
os.environ.get('OS_TEST_TIMEOUT', 0),
self.TIMEOUT_SCALING_FACTOR))
# The Timeout fixture picks up env.OS_TEST_TIMEOUT, defaulting to 0.
self.useFixture(timeout.Timeout(
scaling_factor=self.TIMEOUT_SCALING_FACTOR))
self.engine = enginefacade.writer.get_engine()
def assertColumnExists(self, engine, table_name, column):

View File

@ -146,27 +146,6 @@ class TestLogging(testtools.TestCase):
self.assertIn("at debug", stdlog.logger.output)
class TestTimeout(testtools.TestCase):
"""Tests for our timeout fixture.
Testing the actual timeout mechanism is beyond the scope of this
test, because it's a pretty clear pass through to fixtures'
timeout fixture, which tested in their tree.
"""
def test_scaling(self):
# a bad scaling factor
self.assertRaises(ValueError, fixtures.Timeout, 1, 0.5)
# various things that should work.
timeout = fixtures.Timeout(10)
self.assertEqual(10, timeout.test_timeout)
timeout = fixtures.Timeout("10")
self.assertEqual(10, timeout.test_timeout)
timeout = fixtures.Timeout("10", 2)
self.assertEqual(20, timeout.test_timeout)
class TestOSAPIFixture(testtools.TestCase):
@mock.patch('nova.objects.Service.get_by_host_and_binary')
@mock.patch('nova.objects.Service.create')