With the events of eventlet removal, Watcher will need to be adapted to support both modes, eventlet and threading, for a couple of releases before removing all eventlet code. This patch adds methods and classes that allow decision engine modules to create futurist thread pools instead of green thread pools, based on a environment variable that can be enabled by service. It moves continuous audit handler instance to decison engine service, so it can be started together with the main decision engine service. Adds an environment variable that allows the user to disable eventlet monkey patching and to use oslo.service threading backend. Change-Id: I8a8be0a7cebdc44005fd77ec960543828c7da318 Signed-off-by: Douglas Viroel <viroel@gmail.com>
61 lines
2.2 KiB
Python
61 lines
2.2 KiB
Python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
from unittest import mock
|
|
|
|
from apscheduler.schedulers import background
|
|
|
|
from watcher.common import scheduling
|
|
from watcher import eventlet as eventlet_helper
|
|
from watcher.tests import base
|
|
|
|
|
|
class TestSchedulerMonkeyPatching(base.BaseTestCase):
|
|
|
|
def setUp(self):
|
|
super().setUp()
|
|
self.started = False
|
|
self.test_scheduler = scheduling.BackgroundSchedulerService()
|
|
self.addCleanup(self._cleanup_scheduler)
|
|
|
|
def _cleanup_scheduler(self):
|
|
if self.started:
|
|
self.test_scheduler.shutdown()
|
|
self.started = False
|
|
|
|
def _start_scheduler(self):
|
|
self.test_scheduler.start()
|
|
self.started = True
|
|
|
|
@mock.patch.object(scheduling.BackgroundSchedulerService, 'start')
|
|
def test_scheduler_start(self, mock_start):
|
|
self.test_scheduler.start()
|
|
mock_start.assert_called_once_with()
|
|
|
|
@mock.patch.object(scheduling.BackgroundSchedulerService, 'shutdown')
|
|
def test_scheduler_stop(self, mock_shutdown):
|
|
self._start_scheduler()
|
|
self.test_scheduler.stop()
|
|
mock_shutdown.assert_called_once_with()
|
|
|
|
@mock.patch.object(scheduling.BackgroundSchedulerService, '_main_loop')
|
|
def test_scheduler_main_loop(self, mock_main_loop):
|
|
self._start_scheduler()
|
|
mock_main_loop.assert_called_once_with()
|
|
|
|
@mock.patch.object(background.BackgroundScheduler, '_main_loop')
|
|
@mock.patch.object(eventlet_helper, 'patch')
|
|
def test_main_loop_is_monkey_patched(
|
|
self, mock_eventlet_patch, mock_main_loop):
|
|
self.test_scheduler._main_loop()
|
|
mock_eventlet_patch.assert_called_once_with()
|
|
mock_main_loop.assert_called_once_with()
|