Skip to content
Merged
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
34 changes: 34 additions & 0 deletions src/lib/onboard/experimental/portable-demo-lifecycle-stop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,40 @@ afterEach(() => {
});

describe("portable demo sandbox stop reconciliation", () => {
it("returns already-stopped for an exited container without another mutation (#9200)", () => {
const harness = createStopHarness();
harness.runtime.setState(false, "exited");
const beforeStop = vi.fn();

expect(stopSandbox(harness, {}, beforeStop)).toEqual({ kind: "already-stopped" });

expect(beforeStop).not.toHaveBeenCalled();
expectReceiptUnchanged(harness);
expect(
harness.runtime.podman.mock.calls.some(([args]) => {
const command = args[0] === "--url" ? args.slice(2) : args;
return command[0] === "stop";
}),
).toBe(false);
});

it("rejects a non-running container with no Podman status (#9200)", () => {
const harness = createStopHarness();
harness.runtime.setState(false, null);
const beforeStop = vi.fn();

expect(() => stopSandbox(harness, {}, beforeStop)).toThrow("is not in the exited state");

expect(beforeStop).not.toHaveBeenCalled();
expectReceiptUnchanged(harness);
expect(
harness.runtime.podman.mock.calls.some(([args]) => {
const command = args[0] === "--url" ? args.slice(2) : args;
return command[0] === "stop";
}),
).toBe(false);
});

it("waits for an already-stopping container to settle without another mutation (#9200)", () => {
const harness = createStopHarness();
let now = 0;
Expand Down
5 changes: 4 additions & 1 deletion src/lib/onboard/experimental/portable-demo-lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,10 @@ export function stopPortableDemoSandboxLifecycle(
};

if (!inspection.running) {
if (inspection.status !== "stopping") return { kind: "already-stopped" };
if (inspection.status === "exited") return { kind: "already-stopped" };
if (inspection.status !== "stopping") {
throw new Error(`Portable sandbox '${sandboxName}' is not in the exited state`);
}
if (waitFor(STOP_SETTLEMENT_TIMEOUT_MS, timing, inspectExitedState)) {
return { kind: "already-stopped" };
}
Expand Down
Loading