Skip to content

Commit

Permalink
Add st2tests.config.coord_opts_as_env_vars for itests
Browse files Browse the repository at this point in the history
Integration tests need to start subprocesses that use the
same redis as the test. This matters when running under
pantsbuild, because pants runs several instances of pytest
in parallel. This PR prepares to add support, to disambiguate
test runs--similar to the database logic--using the env var:
ST2TESTS_PARALLEL_SLOT.
In any case, when an integration test runs production
code in a subprocess, the production code does not use--
and should not use--any ST2TESTS_* vars, meaning the
subprocess ends up using what is configured in the conf
file instead of the (planned) parallel-safe coordinator.

Thanks to a new-ish oslo_config feature, we can now
update config via env variables. So, make use of that
in integration tests to override the conf-file provided
values with test-provided values.
  • Loading branch information
cognifloyd committed Nov 9, 2024
1 parent 8a8db1b commit fd8e270
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions st2api/tests/integration/test_gunicorn_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_st2api_wsgi_entry_point(self):
env = os.environ.copy()
env["ST2_CONFIG_PATH"] = ST2_CONFIG_PATH
env.update(st2tests.config.db_opts_as_env_vars())
env.update(st2tests.config.coord_opts_as_env_vars())
process = subprocess.Popen(cmd, env=env, shell=True, preexec_fn=os.setsid)
try:
self.add_process(process=process)
Expand All @@ -63,6 +64,7 @@ def test_st2auth(self):
env = os.environ.copy()
env["ST2_CONFIG_PATH"] = ST2_CONFIG_PATH
env.update(st2tests.config.db_opts_as_env_vars())
env.update(st2tests.config.coord_opts_as_env_vars())
process = subprocess.Popen(cmd, env=env, shell=True, preexec_fn=os.setsid)
try:
self.add_process(process=process)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,5 @@ def test_register_recreate_virtualenvs(self):
def _run_command(cmd):
env = os.environ.copy()
env.update(st2tests.config.db_opts_as_env_vars())
env.update(st2tests.config.coord_opts_as_env_vars())
return run_command(cmd=cmd, env=env)
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ def _start_process(config_path, env=None):
cwd = os.path.abspath(cwd)
env = env or os.environ.copy()
env.update(st2tests.config.db_opts_as_env_vars())
env.update(st2tests.config.coord_opts_as_env_vars())
process = subprocess.Popen(
cmd,
env=env,
Expand Down
1 change: 1 addition & 0 deletions st2reactor/tests/integration/test_garbage_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def _start_garbage_collector(self):
subprocess = concurrency.get_subprocess_module()
env = os.environ.copy()
env.update(st2tests.config.db_opts_as_env_vars())
env.update(st2tests.config.coord_opts_as_env_vars())
process = subprocess.Popen(
CMD_INQUIRY,
stdout=subprocess.PIPE,
Expand Down
1 change: 1 addition & 0 deletions st2reactor/tests/integration/test_sensor_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def _start_sensor_container(self, cmd=DEFAULT_CMD):
subprocess = concurrency.get_subprocess_module()
env = os.environ.copy()
env.update(st2tests.config.db_opts_as_env_vars())
env.update(st2tests.config.coord_opts_as_env_vars())
print("Using command: %s" % (" ".join(cmd)))
process = subprocess.Popen(
cmd,
Expand Down
7 changes: 7 additions & 0 deletions st2tests/st2tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ def _override_coordinator_opts(noop=False):
CONF.set_override(name="lock_timeout", override=1, group="coordination")


def coord_opts_as_env_vars() -> Dict[str, str]:
env = {}
if CONF.coordination.url is not None:
env["ST2_COORDINATION__URL"] = CONF.coordination.url
return env


def _override_workflow_engine_opts():
cfg.CONF.set_override("retry_stop_max_msec", 200, group="workflow_engine")
cfg.CONF.set_override("retry_wait_fixed_msec", 100, group="workflow_engine")
Expand Down

0 comments on commit fd8e270

Please sign in to comment.