Disable cron trigger thread for API unit tests

* API unit tests activated cron trigger thread whereas all unit tests
  assume that it's not started. Tests  where it needs to be activated
  should do it explicitly and shut down it after completion.
  This was causing unpredictable results where we were assuming that
  there weren't any active cron trigger threads.
* Minor cosmetic changes

Change-Id: I7e30f80b29520e03f2e1673788c764aabe1e4a8b
Closes-Bug: #1564353
This commit is contained in:
Renat Akhmerov 2016-04-15 15:26:34 +07:00 committed by Lingxian Kong
parent d3ef00a122
commit 1586c3e1d9
5 changed files with 25 additions and 10 deletions

View File

@ -45,13 +45,15 @@ def get_pecan_config():
def setup_app(config=None):
if not config:
config = get_pecan_config()
m_config.set_config_defaults()
app_conf = dict(config.app)
db_api_v2.setup_db()
periodic.setup()
if not app_conf.pop('disable_cron_trigger_thread', False):
periodic.setup()
coordination.Service('api_group').register_membership()
@ -67,6 +69,4 @@ def setup_app(config=None):
# Create a CORS wrapper, and attach mistral-specific defaults that must be
# included in all CORS responses.
app = cors_middleware.CORS(app, cfg.CONF)
return app
return cors_middleware.CORS(app, cfg.CONF)

View File

@ -20,6 +20,7 @@ import pecan
import pecan.testing
from webtest import app as webtest_app
from mistral.services import periodic
from mistral.tests.unit import base
# Disable authentication for functional tests.
@ -38,7 +39,8 @@ class FunctionalTest(base.DbTestCase):
'root': pecan_opts.root,
'modules': pecan_opts.modules,
'debug': pecan_opts.debug,
'auth_enable': False
'auth_enable': False,
'disable_cron_trigger_thread': True
}
})
@ -48,6 +50,11 @@ class FunctionalTest(base.DbTestCase):
False,
group='pecan')
# Adding cron trigger thread clean up explicitly in case if
# new tests will provide an alternative configuration for pecan
# application.
self.addCleanup(periodic.stop_all_periodic_tasks)
# Make sure the api get the correct context.
self.patch_ctx = mock.patch('mistral.context.context_from_headers')
self.mock_ctx = self.patch_ctx.start()

View File

@ -66,12 +66,15 @@ class TestKeystoneMiddleware(base.FunctionalTest):
def setUp(self):
super(TestKeystoneMiddleware, self).setUp()
cfg.CONF.set_default('auth_enable', True, group='pecan')
self.app = pecan.testing.load_test_app({
'app': {
'root': cfg.CONF.pecan.root,
'modules': cfg.CONF.pecan.modules,
'debug': cfg.CONF.pecan.debug,
'auth_enable': cfg.CONF.pecan.auth_enable
'auth_enable': cfg.CONF.pecan.auth_enable,
'disable_cron_trigger_thread': True
}
})

View File

@ -20,12 +20,12 @@ from oslo_middleware import cors as cors_middleware
class TestCORSMiddleware(base.FunctionalTest):
'''Provide a basic smoke test to ensure CORS middleware is active.
"""Provide a basic smoke test to ensure CORS middleware is active.
The tests below provide minimal confirmation that the CORS middleware
is active, and may be configured. For comprehensive tests, please consult
the test suite in oslo_middleware.
'''
"""
def setUp(self):
# Make sure the CORS options are registered

View File

@ -288,9 +288,14 @@ class TriggerServiceV2Test(base.DbTestCase):
@mock.patch.object(rpc.EngineClient, 'start_workflow')
def test_single_execution_with_multiple_processes(self, start_wf_mock):
def stop_thread_groups():
[tg.stop() for tg in self.triggers]
print('Killing cron trigger threads...')
[tg.stop() for tg in self.trigger_threads]
self.triggers = [periodic.setup(), periodic.setup(), periodic.setup()]
self.trigger_threads = [
periodic.setup(),
periodic.setup(),
periodic.setup()
]
self.addCleanup(stop_thread_groups)
trigger_count = 5