diff --git a/tests/integration/test_charm_runner.py b/tests/integration/test_charm_runner.py index d2ed7b5459..f5dd3b9853 100644 --- a/tests/integration/test_charm_runner.py +++ b/tests/integration/test_charm_runner.py @@ -22,6 +22,7 @@ get_job_logs, wait_for, wait_for_runner_ready, + wait_for_status, ) from tests.integration.helpers.openstack import OpenStackInstanceHelper @@ -141,7 +142,7 @@ def test_flush_runner_and_resource_config( dispatch_input={"runner": app, "minutes": "5"}, wait=False, ) - wait_for(lambda: workflow.update() or workflow.status == "in_progress") + wait_for_status(workflow, "in_progress") result = juju.run(unit_name, "flush-runners") assert result.status == "completed" @@ -216,21 +217,36 @@ def test_otel_collector_endpoint_pre_job_installs_config( ) wait_for_runner_ready(juju, app) - dispatch_workflow( + # Dispatch the long-running wait workflow (instead of a quick one) so the runner stays + # busy while we inspect it. An ephemeral runner's VM is torn down on job completion, which + # races the inspection below; keeping the job in progress guarantees the VM is still alive. + workflow = dispatch_workflow( app_name=app, branch=test_github_branch, github_repository=github_repository, conclusion="success", - workflow_id_or_name=DISPATCH_TEST_WORKFLOW_FILENAME, - dispatch_input={"runner": app}, + workflow_id_or_name=DISPATCH_WAIT_TEST_WORKFLOW_FILENAME, + dispatch_input={"runner": app, "minutes": "5"}, + wait=False, ) + wait_for_status(workflow, "in_progress") - exit_code, stdout, stderr = instance_helper.run_in_instance( - unit_name=f"{app}/0", - command="sudo cat /etc/otelcol/config.d/github.yaml", - ) + def _read_otel_config() -> str: + """Read the otel config written by the pre-job script, retrying until it exists. + + The pre-job hook may not have finished writing the file the moment the job is reported + in progress, so callers poll on a truthy (non-empty) return value. + + Returns: + The otel config file content, or an empty string if not yet written. + """ + exit_code, stdout, _ = instance_helper.run_in_instance( + unit_name=f"{app}/0", + command="sudo cat /etc/otelcol/config.d/github.yaml", + ) + return stdout if exit_code == 0 and stdout else "" + + config = wait_for(_read_otel_config, timeout=120, check_interval=10) - assert exit_code == 0, stderr - assert stdout is not None - assert "exporters:" in stdout - assert f"endpoint: {endpoint}" in stdout + assert "exporters:" in config + assert f"endpoint: {endpoint}" in config