-
-
Notifications
You must be signed in to change notification settings - Fork 747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make unit tests use redis #6245
Changes from all commits
913fd97
913b5f0
7f50e44
4ca0722
c91491d
668a90e
f05f081
e647d56
914b0d8
009f643
6750d68
70fa0ba
3944b78
7d1b1f4
869818c
847907f
c35d446
223c7a6
78c3248
774f45b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
from st2common.transport.publishers import CUDPublisher | ||
from st2common.bootstrap import runnersregistrar as runners_registrar | ||
from st2tests import ExecutionDbTestCase | ||
from st2tests import config as tests_config | ||
from st2tests.fixtures.generic.fixture import PACK_NAME as PACK | ||
from st2tests.fixturesloader import FixturesLoader | ||
from st2tests.mocks.runners import runner | ||
|
@@ -36,6 +37,8 @@ | |
from st2tests.policies.concurrency import FakeConcurrencyApplicator | ||
from st2tests.policies.mock_exception import RaiseExceptionApplicator | ||
|
||
# This needs to run before creating FakeConcurrencyApplicator below. | ||
tests_config.parse_args() | ||
Comment on lines
+40
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests were inadvertently using the NoOpDriver because of the import-time creation of I found this by putting some |
||
|
||
TEST_FIXTURES = { | ||
"actions": ["action1.yaml"], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,12 +20,14 @@ | |
import mock | ||
import os | ||
from oslo_config import cfg | ||
from tooz.drivers.redis import RedisDriver | ||
import tempfile | ||
|
||
# This import must be early for import-time side-effects. | ||
from st2tests.base import DbTestCase | ||
|
||
import st2actions.worker as actions_worker | ||
import st2tests.config as tests_config | ||
from st2common.constants import action as action_constants | ||
from st2common.models.db.liveaction import LiveActionDB | ||
from st2common.models.system.common import ResourceReference | ||
|
@@ -66,6 +68,35 @@ def setUpClass(cls): | |
) | ||
WorkerTestCase.local_action_db = models["actions"]["local.yaml"] | ||
|
||
@staticmethod | ||
def reset_config( | ||
graceful_shutdown=True, # default is True (st2common.config) | ||
exit_still_active_check=None, # default is 300 (st2common.config) | ||
still_active_check_interval=None, # default is 2 (st2common.config) | ||
service_registry=None, # default is False (st2common.config) | ||
): | ||
tests_config.reset() | ||
tests_config.parse_args() | ||
Comment on lines
+78
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since these tests need to control the config, changing values in each test, it makes more sense to setup the In a future refactor, this would be a good function to turn into a pytest fixture, after we've got pytest running everything. |
||
cfg.CONF.set_override( | ||
name="graceful_shutdown", override=graceful_shutdown, group="actionrunner" | ||
) | ||
if exit_still_active_check is not None: | ||
cfg.CONF.set_override( | ||
name="exit_still_active_check", | ||
override=exit_still_active_check, | ||
group="actionrunner", | ||
) | ||
if still_active_check_interval is not None: | ||
cfg.CONF.set_override( | ||
name="still_active_check_interval", | ||
override=still_active_check_interval, | ||
group="actionrunner", | ||
) | ||
if service_registry is not None: | ||
cfg.CONF.set_override( | ||
name="service_registry", override=service_registry, group="coordination" | ||
) | ||
|
||
def _get_liveaction_model(self, action_db, params): | ||
status = action_constants.LIVEACTION_STATUS_REQUESTED | ||
start_timestamp = date_utils.get_datetime_utc_now() | ||
|
@@ -116,9 +147,8 @@ def test_non_utf8_action_result_string(self): | |
) | ||
|
||
def test_worker_shutdown(self): | ||
cfg.CONF.set_override( | ||
name="graceful_shutdown", override=False, group="actionrunner" | ||
) | ||
self.reset_config(graceful_shutdown=False) | ||
|
||
action_worker = actions_worker.get_worker() | ||
temp_file = None | ||
|
||
|
@@ -169,14 +199,19 @@ def test_worker_shutdown(self): | |
runner_thread.wait() | ||
|
||
@mock.patch.object( | ||
coordination.NoOpDriver, | ||
RedisDriver, | ||
"get_members", | ||
mock.MagicMock(return_value=coordination.NoOpAsyncResult("member-1")), | ||
mock.MagicMock( | ||
return_value=coordination.NoOpAsyncResult(("member-1", "member-2")) | ||
), | ||
) | ||
def test_worker_graceful_shutdown_with_multiple_runners(self): | ||
cfg.CONF.set_override( | ||
name="graceful_shutdown", override=True, group="actionrunner" | ||
self.reset_config( | ||
exit_still_active_check=10, | ||
still_active_check_interval=1, | ||
service_registry=True, | ||
) | ||
|
||
action_worker = actions_worker.get_worker() | ||
temp_file = None | ||
|
||
|
@@ -234,9 +269,12 @@ def test_worker_graceful_shutdown_with_multiple_runners(self): | |
shutdown_thread.kill() | ||
|
||
def test_worker_graceful_shutdown_with_single_runner(self): | ||
cfg.CONF.set_override( | ||
name="graceful_shutdown", override=True, group="actionrunner" | ||
self.reset_config( | ||
exit_still_active_check=10, | ||
still_active_check_interval=1, | ||
service_registry=True, | ||
) | ||
|
||
action_worker = actions_worker.get_worker() | ||
temp_file = None | ||
|
||
|
@@ -296,17 +334,13 @@ def test_worker_graceful_shutdown_with_single_runner(self): | |
shutdown_thread.kill() | ||
|
||
@mock.patch.object( | ||
coordination.NoOpDriver, | ||
RedisDriver, | ||
"get_members", | ||
mock.MagicMock(return_value=coordination.NoOpAsyncResult("member-1")), | ||
mock.MagicMock(return_value=coordination.NoOpAsyncResult(("member-1",))), | ||
) | ||
def test_worker_graceful_shutdown_exit_timeout(self): | ||
cfg.CONF.set_override( | ||
name="graceful_shutdown", override=True, group="actionrunner" | ||
) | ||
cfg.CONF.set_override( | ||
name="exit_still_active_check", override=5, group="actionrunner" | ||
) | ||
self.reset_config(exit_still_active_check=5) | ||
|
||
action_worker = actions_worker.get_worker() | ||
temp_file = None | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need one redis container, either started here or in
services
above. Theservices
approach is a bit nicer because we know that redis is up and responding (thanks to the health check that GHA waits for before continuing), whereas this just makes ssure the container (not redis in the container) is running.This was also the cause of the conflicts where
redis
was already in use. Getting rid of this allows us to use the simpleredis
name for the service container instead ofredis-server
.