test: handle docker exiting with a signal (#21512)

This commit is contained in:
Meghan Denny
2025-07-30 22:11:17 -08:00
committed by Jarred Sumner
parent 5f010c65d8
commit 8e4b5d51b3
2 changed files with 15 additions and 4 deletions

View File

@@ -883,28 +883,36 @@ export async function describeWithContainer(
let containerId: string;
{
const envs = Object.entries(env).map(([k, v]) => `-e${k}=${v}`);
const { exitCode, stdout, stderr } = Bun.spawnSync({
const { exitCode, stdout, stderr, signalCode } = Bun.spawnSync({
cmd: [docker, "run", "--rm", "-dPit", ...envs, image, ...args],
stdout: "pipe",
stderr: "pipe",
});
if (exitCode !== 0) {
process.stderr.write(stderr);
test.skip(`docker container for ${image} failed to start`, () => {});
test.skip(`docker container for ${image} failed to start (exit: ${exitCode})`, () => {});
return false;
}
if (signalCode) {
test.skip(`docker container for ${image} failed to start (signal: ${signalCode})`, () => {});
return false;
}
containerId = stdout.toString("utf-8").trim();
}
let port: number;
{
const { exitCode, stdout, stderr } = Bun.spawnSync({
const { exitCode, stdout, stderr, signalCode } = Bun.spawnSync({
cmd: [docker, "port", containerId],
stdout: "pipe",
stderr: "pipe",
});
if (exitCode !== 0) {
process.stderr.write(stderr);
test.skip(`docker container for ${image} failed to find a port`, () => {});
test.skip(`docker container for ${image} failed to find a port (exit: ${exitCode})`, () => {});
return false;
}
if (signalCode) {
test.skip(`docker container for ${image} failed to find a port (signal: ${signalCode})`, () => {});
return false;
}
const [firstPort] = stdout

View File

@@ -13,7 +13,10 @@ export const isEnabled =
stdout: "pipe",
stderr: "inherit",
env: bunEnv,
timeout: 5_000,
});
if (info.exitCode !== 0) return false;
if (info.signalCode) return false;
return info.stdout.toString().indexOf("Server Version:") !== -1;
} catch (error) {
return false;