Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

fix(test): stop integration suites after setup teardown failure

pulse-triage[bot]7b096f82bb92
diff --git a/tests/integration/scripts/run-tests-cleanup.test.mjs b/tests/integration/scripts/run-tests-cleanup.test.mjs
index 9720e22eb0..30947185ec 100644
--- a/tests/integration/scripts/run-tests-cleanup.test.mjs
+++ b/tests/integration/scripts/run-tests-cleanup.test.mjs
@@ -51,3 +51,39 @@ exit 0`,
});
}
}
+
+for (const failure of ['startup', 'health', 'entitlement', 'port-command', 'port-binding']) {
+ test(`${failure} failure with failed teardown stops before the next suite`, () => {
+ const dir = mkdtempSync(path.join(tmpdir(), 'pulse-cleanup-early-test-'));
+ try {
+ const stubs = {
+ docker: `if [ "$1" = compose ]; then
+ case " $* " in
+ *" up -d "*) echo start >> '${dir}/starts'; exit ${failure === 'startup' ? 19 : 0} ;;
+ *" down -v "*) exit 17 ;;
+ *" port "*) echo ${failure === 'port-binding' ? 'invalid' : '127.0.0.1:17655'}; exit ${failure === 'port-command' ? 24 : 0} ;;
+ esac
+fi
+if [ "$1 $2" = 'inspect -f' ]; then echo ${failure === 'health' ? 'false' : 'true'}; fi
+exit 0`,
+ curl: 'exit 0',
+ node: `if [ "$1" = -e ]; then printf '%s' 0123456789abcdef0123456789abcdef; exit 0; fi
+exit ${failure === 'entitlement' ? 23 : 0}`,
+ npx: 'exit 0',
+ go: 'exit 0',
+ };
+ for (const [name, body] of Object.entries(stubs)) {
+ writeFileSync(path.join(dir, name), `#!/bin/bash\n${body}\n`, { mode: 0o755 });
+ }
+ const result = spawnSync('bash', [runner, 'all'], {
+ env: { ...process.env, PATH: `${dir}:${process.env.PATH}` },
+ encoding: 'utf8',
+ });
+ assert.equal(result.status, 1, result.stdout + result.stderr);
+ assert.equal(readFileSync(path.join(dir, 'starts'), 'utf8'), 'start\n',
+ 'failed setup teardown must not let another suite inherit dirty state');
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+ });
+}
diff --git a/tests/integration/scripts/run-tests.sh b/tests/integration/scripts/run-tests.sh
index fff67dc8f0..f834c0cb42 100755
--- a/tests/integration/scripts/run-tests.sh
+++ b/tests/integration/scripts/run-tests.sh
@@ -70,6 +70,16 @@ trap 'exit 130' INT
trap 'exit 143' TERM
trap 'exit 129' HUP
+teardown_suite() {
+ # run_suite is called in an || list, where Bash disables errexit.
+ # Stop the entire run if teardown fails: later suites must not inherit
+ # containers or volumes from a previous scenario.
+ if ! compose down -v; then
+ echo -e "${RED}❌ Failed to clean up test environment; stopping run${NC}"
+ exit 1
+ fi
+}
+
# Function to run suite with specific mock config
run_suite() {
local name="$1"
@@ -102,24 +112,24 @@ run_suite() {
if ! compose up -d; then
echo -e "${RED}❌ Failed to start docker services${NC}"
compose logs
- compose down -v
+ teardown_suite
return 1
fi
# Resolve Docker-allocated ports only after successful startup. A failed
# bind must never fall back to probing a different worktree's listener.
local binding
- binding="$(compose port pulse-test 7655)" || return 1
- [[ "$binding" =~ :([0-9]+)$ ]] || return 1
+ binding="$(compose port pulse-test 7655)" || { teardown_suite; return 1; }
+ [[ "$binding" =~ :([0-9]+)$ ]] || { teardown_suite; return 1; }
export PULSE_BASE_URL="http://127.0.0.1:${BASH_REMATCH[1]}"
local pulse_base_url="$PULSE_BASE_URL"
local health_url="$pulse_base_url/api/health"
- binding="$(compose port pulse-test 7656)" || return 1
- [[ "$binding" =~ :([0-9]+)$ ]] || return 1
+ binding="$(compose port pulse-test 7656)" || { teardown_suite; return 1; }
+ [[ "$binding" =~ :([0-9]+)$ ]] || { teardown_suite; return 1; }
export PULSE_E2E_AGENT_PORT="${BASH_REMATCH[1]}"
export PULSE_AGENT_BASE_URL="http://127.0.0.1:${BASH_REMATCH[1]}"
- binding="$(compose port mock-github 8080)" || return 1
- [[ "$binding" =~ :([0-9]+)$ ]] || return 1
+ binding="$(compose port mock-github 8080)" || { teardown_suite; return 1; }
+ [[ "$binding" =~ :([0-9]+)$ ]] || { teardown_suite; return 1; }
export MOCK_GITHUB_URL="http://127.0.0.1:${BASH_REMATCH[1]}"
# Wait for services
@@ -140,14 +150,14 @@ run_suite() {
echo -e "${RED}❌ Services failed to start${NC}"
compose ps
compose logs
- compose down -v
+ teardown_suite
return 1
fi
if ! node ./scripts/apply-entitlement-profile.mjs; then
echo -e "${RED}❌ Failed to apply entitlement bootstrap${NC}"
compose logs
- compose down -v
+ teardown_suite
return 1
fi
@@ -209,13 +219,7 @@ run_suite() {
# Cleanup
echo "Cleaning up..."
- # run_suite is called in an || list, where Bash disables errexit.
- # Stop the entire run if teardown fails: later suites must not inherit
- # containers or volumes from a previous scenario.
- if ! compose down -v; then
- echo -e "${RED}❌ Failed to clean up test environment; stopping run${NC}"
- exit 1
- fi
+ teardown_suite
return $TEST_RESULT
}