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
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ npm run test:image
npm audit --audit-level=high
```

`npm run check` covers strict TypeScript, 57 Action tests, 17 supervisor tests,
`npm run check` covers strict TypeScript, 58 Action tests, 17 supervisor tests,
and the bundled Action. Supervisor tests also run successfully under the image's
Python 3.9 runtime.

Expand Down
8 changes: 7 additions & 1 deletion src/orchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
type WorkflowIdentity,
} from "./identity.js";
import { encodeRunHookPayload } from "./payload.js";
import { pollSequentially } from "./polling.js";
import { PollingError, pollSequentially } from "./polling.js";
import {
getSafeErrorName,
OperationRetryError,
Expand Down Expand Up @@ -349,6 +349,12 @@ function userFacingFailure(
`${stage} exhausted Lambda MicroVM capacity in ${region}; review AWS Service Quotas for this account and Region`,
);
}
if (
(error instanceof PollingError && error.reason === "deadline") ||
(error instanceof OperationRetryError && error.reason === "deadline")
) {
return new ActionExecutionError(`${stage} timed out in ${region}`);
}
return new ActionExecutionError(
`${stage} failed (${getSafeErrorName(error)})`,
);
Expand Down
9 changes: 6 additions & 3 deletions src/polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export type PollingOptions<TObserved, TResult> = {
};

export class PollingError extends Error {
public readonly reason: "deadline" | "terminal";

public constructor(
operation: string,
reason: "deadline" | "terminal",
Expand All @@ -25,6 +27,7 @@ export class PollingError extends Error {
const suffix = detail === undefined ? "" : ` (${detail})`;
super(`${operation} polling failed: ${reason}${suffix}`);
this.name = "PollingError";
this.reason = reason;
}
}

Expand All @@ -44,8 +47,10 @@ export async function pollSequentially<TObserved, TResult>(
initialDelayMaxMs,
baseIntervalMs,
maxIntervalMs,
now,
);
if (now() >= options.deadline) {
throw new PollingError(options.operation, "deadline");
}

const initialDelay = Math.floor(
assertRandom(random()) * (initialDelayMaxMs + 1),
Expand Down Expand Up @@ -101,12 +106,10 @@ function validateOptions(
initialDelayMaxMs: number,
baseIntervalMs: number,
maxIntervalMs: number,
now: () => number,
): void {
if (
operation.trim().length === 0 ||
!Number.isSafeInteger(deadline) ||
deadline <= now() ||
!Number.isSafeInteger(initialDelayMaxMs) ||
initialDelayMaxMs < 0 ||
!Number.isSafeInteger(baseIntervalMs) ||
Expand Down
3 changes: 1 addition & 2 deletions test/orchestration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { describe, expect, it, vi } from "vitest";
import type { StartConfig, StopConfig } from "../src/config.js";
import { decodeJitPayload } from "../src/payload.js";
import {
ActionExecutionError,
startRunner,
stopRunner,
type ActionReporter,
Expand Down Expand Up @@ -167,7 +166,7 @@ describe("Action orchestration", () => {
createReporter().api,
runtime.api,
),
).rejects.toEqual(expect.any(ActionExecutionError));
).rejects.toThrow("GitHub runner readiness timed out in us-east-1");

expect(microvms.terminateRequests).toEqual(["mvm-1"]);
expect(github.deleteRequests).toEqual([42]);
Expand Down
12 changes: 12 additions & 0 deletions test/polling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,16 @@ describe("quota-aware polling", () => {
}),
).rejects.toThrow("deadline");
});

it("classifies an already-expired deadline as a timeout", async () => {
await expect(
pollSequentially({
operation: "GetMicrovm",
deadline: 1_000,
observe: async () => "PENDING",
decide: () => ({ status: "pending" }),
now: () => 1_000,
}),
).rejects.toThrow("polling failed: deadline");
});
});
Loading