Skip to content
Draft
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
4 changes: 2 additions & 2 deletions ts/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1316,9 +1316,9 @@ export interface ActionOptions {
* returning "not found" repeatedly), stall detection short-circuits the
* loop instead of waiting for the full timeout.
*
* Set to `"0s"` to disable stall detection.
* Omit this option or set it to `"0s"` to disable stall detection.
*
* @default "30s"
* @default disabled
*/
readonly stallTimeout?: undefined | string;
}
Expand Down
7 changes: 6 additions & 1 deletion ts/retry.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from "bun:test";
import { Duration } from "./duration";
import { Recorder } from "./recording";
import { retryUntil } from "./retry";
import { resolveStallTimeoutMs, retryUntil } from "./retry";

test("retryUntil records success flow events", async () => {
const recorder = new Recorder();
Expand Down Expand Up @@ -69,6 +69,11 @@ test("retryUntil records timeout flow events", async () => {
});

describe("stall detection", () => {
test("is opt-in so ordinary eventual convergence uses the action timeout", () => {
expect(resolveStallTimeoutMs(undefined)).toBe(0);
expect(resolveStallTimeoutMs("30s")).toBe(30_000);
});

test("bails early when the same error repeats beyond stallTimeout", async () => {
const recorder = new Recorder();

Expand Down
12 changes: 6 additions & 6 deletions ts/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export interface RetryOptions {
* returning "not found" 1,500 times), stall detection short-circuits the
* loop instead of waiting for the full timeout.
*
* Set to `0` or `"0s"` to disable stall detection.
* Omit this option or set it to `0` / `"0s"` to disable stall detection.
*
* @default "30s"
* @default disabled
*/
stallTimeout?: undefined | string | Duration;

Expand Down Expand Up @@ -60,16 +60,16 @@ function errorFingerprint(err: unknown): string {
return String(err).slice(0, 200);
}

const DEFAULT_STALL_TIMEOUT_MS = 30_000;

/**
* Resolves the stall-timeout option.
*
* Returns `0` when stall detection is disabled (value is `0` / `"0s"` / `"0"`).
*/
function resolveStallTimeoutMs(value: undefined | string | Duration): number {
export function resolveStallTimeoutMs(
value: undefined | string | Duration
): number {
if (value === undefined) {
return DEFAULT_STALL_TIMEOUT_MS;
return 0;
}
if (typeof value === "number" && value === 0) {
return 0;
Expand Down
4 changes: 1 addition & 3 deletions ts/scenario/use-cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,7 @@ describe("resolveCluster", () => {
kind: "Cluster",
metadata: { name: "workload-2", namespace: "capi-system" },
status: {
v1beta2: {
conditions: [{ type: "Available", status: "True" }],
},
conditions: [{ type: "Available", status: "True" }],
},
});
kubectl.onGet(() => readyYaml);
Expand Down
5 changes: 1 addition & 4 deletions ts/scenario/use-cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ export async function resolveCluster(
| undefined;
targetType = "Ready";
} else if (version === "v1beta2") {
const v1beta2 = status["v1beta2"] as
| Record<string, unknown>
| undefined;
conditions = v1beta2?.["conditions"] as
conditions = status["conditions"] as
| Array<Record<string, unknown>>
| undefined;
targetType = "Available";
Expand Down
Loading