Skip to content
Merged

v2 #23

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion test/chaos/chaos-fault-injection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,25 @@ exit 0
`,
);

// Stateful curl stub: succeeds once (for startup liveness), then returns 503.
// This lets start_node_app pass its liveness check while making recovery
// liveness probes fail fast so the supervisor exits with the correct exit code.
await writeExecutable(
path.join(binDir, 'curl'),
`#!/usr/bin/env bash
COUNTER_FILE="\${ENTRYPOINT_TEST_LOG%.log}.curl-count"
count=\$(( \$(cat "\$COUNTER_FILE" 2>/dev/null || echo 0) + 1 ))
printf '%s' "\$count" > "\$COUNTER_FILE"
MAX_SUCCESS="\${FAKE_CURL_SUCCESS_COUNT:-1}"
if [ "\$count" -le "\$MAX_SUCCESS" ]; then
printf '{"status":"ok"}\\n200\\n'
else
printf '{"status":"starting"}\\n503\\n'
fi
exit 0
`,
);

const child = spawn('/bin/bash', [entrypointPath], {
cwd: repoRoot,
env: {
Expand All @@ -870,6 +889,9 @@ exit 0
NGINX_SHUTDOWN_TIMEOUT_SECONDS: '1',
DB_CONNECT_RETRY_DELAY_SECONDS: '1',
MIGRATION_RETRY_DELAY_SECONDS: '1',
// Keep recovery liveness probes fast so tests complete within 10 s.
HEALTH_RECOVERY_MAX_ATTEMPTS: '3',
HEALTH_RECOVERY_DELAY_SECONDS: '0',
...envOverrides,
},
stdio: ['ignore', 'pipe', 'pipe'],
Expand Down Expand Up @@ -1518,7 +1540,7 @@ describe('chaos and fault-injection validation', () => {
const harness = await createEntrypointHarness({
FAKE_NGINX_MODE: 'crash',
FAKE_NGINX_EXIT_CODE: '23',
FAKE_NGINX_CRASH_DELAY_SECONDS: '1',
FAKE_NGINX_CRASH_DELAY_SECONDS: '3',
});

try {
Expand Down
25 changes: 23 additions & 2 deletions test/unit/entrypoint-recovery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,24 @@ exit 0
`,
);

// Stateful curl stub: succeeds once (startup liveness), then returns 503 so
// recovery liveness probes fail fast and the supervisor exits promptly.
await writeExecutable(
path.join(binDir, 'curl'),
`#!/usr/bin/env bash
COUNTER_FILE="\${ENTRYPOINT_TEST_LOG%.log}.curl-count"
count=\$(( \$(cat "\$COUNTER_FILE" 2>/dev/null || echo 0) + 1 ))
printf '%s' "\$count" > "\$COUNTER_FILE"
MAX_SUCCESS="\${FAKE_CURL_SUCCESS_COUNT:-1}"
if [ "\$count" -le "\$MAX_SUCCESS" ]; then
printf '{"status":"ok"}\\n200\\n'
else
printf '{"status":"starting"}\\n503\\n'
fi
exit 0
`,
);

const child = spawn('/bin/bash', [entrypointPath], {
cwd: repoRoot,
env: {
Expand All @@ -213,6 +231,9 @@ exit 0
MIGRATION_RETRY_DELAY_SECONDS: '1',
NGINX_RUNTIME_DIR: nginxRuntimeDir,
NGINX_BUNDLED_SOURCE_DIR: nginxSourceDir,
// Keep recovery liveness probes fast so tests complete within 10 s.
HEALTH_RECOVERY_MAX_ATTEMPTS: '3',
HEALTH_RECOVERY_DELAY_SECONDS: '0',
...envOverrides,
},
stdio: ['ignore', 'pipe', 'pipe'],
Expand Down Expand Up @@ -258,7 +279,7 @@ describe('entrypoint recovery behavior', () => {
const harness = await createHarness({
FAKE_NGINX_MODE: 'crash',
FAKE_NGINX_EXIT_CODE: '23',
FAKE_NGINX_CRASH_DELAY_SECONDS: '2',
FAKE_NGINX_CRASH_DELAY_SECONDS: '3',
});

try {
Expand Down Expand Up @@ -317,7 +338,7 @@ describe('entrypoint recovery behavior', () => {
assert.doesNotMatch(compose, /network_mode:\s+host/);

assert.match(swarm, /condition:\s+any/);
assert.match(swarm, /stop_grace_period:\s+45s/);
assert.match(swarm, /stop_grace_period:\s+60s/);
assert.doesNotMatch(swarm, /max_attempts:/);
});
});
Expand Down
Loading