Skip to content

Commit 6a97ba4

Browse files
authored
test(worker): await inference admission before cancellation (#125835)
1 parent 1ecd53f commit 6a97ba4

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎src/worker/worker.runtime.test.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
type WorkerInferenceTerminalFrame,
3737
type WorkerInferenceTerminalOutcome,
3838
} from "../../packages/gateway-protocol/src/schema/worker-inference.js";
39+
import { createDeferred, withTestTimeout } from "../../test/helpers/promise.js";
3940
import { createOperationalRunInstanceRef } from "../agents/admitted-run-context.js";
4041
import { listRunningSessions } from "../agents/bash-process-registry.js";
4142
import { buildWorkerConnectParams, type WorkerLaunchDescriptor } from "./launch-descriptor.js";
@@ -94,6 +95,7 @@ const WORKER_LOOP_REPLAY = {
9495
};
9596
const BUNDLE_HASH = Array.from({ length: 64 }, () => "a").join("");
9697
const CREDENTIAL = ["worker", "fixture", "admission"].join("-");
98+
const WORKER_INFERENCE_START_TIMEOUT_MS = 90_000;
9799

98100
type InferencePlan =
99101
| "text"
@@ -165,6 +167,7 @@ class FakeWorkerGateway {
165167
private sentLiveResync = 0;
166168
private unavailable = false;
167169
private ignoredAdmission = false;
170+
private readonly inferenceStarted = createDeferred();
168171

169172
socketPath = "";
170173
connectionCount = 0;
@@ -176,6 +179,14 @@ class FakeWorkerGateway {
176179
readonly sessionSpawnRequests: WorkerSessionsSpawnParams[] = [];
177180
readonly applicationOrder: string[] = [];
178181

182+
waitForInferenceStart(): Promise<void> {
183+
return withTestTimeout(
184+
this.inferenceStarted.promise,
185+
WORKER_INFERENCE_START_TIMEOUT_MS,
186+
"worker inference start did not reach the fake Gateway",
187+
);
188+
}
189+
179190
constructor(private readonly options: FakeGatewayOptions = {}) {
180191
this.httpServer = createServer();
181192
this.webSocketServer = new WebSocketServer({ server: this.httpServer });
@@ -468,6 +479,7 @@ class FakeWorkerGateway {
468479
private handleInference(socket: WebSocket, frame: WorkerInferenceStartRequestFrame): void {
469480
this.methods.push(frame.method);
470481
this.inferenceRequests.push(structuredClone(frame.params));
482+
this.inferenceStarted.resolve();
471483
if (this.options.silenceFirstInference && !this.droppedInference) {
472484
this.droppedInference = true;
473485
return;
@@ -1168,7 +1180,7 @@ describe("worker runtime", () => {
11681180
const { gateway, launch } = await setup({ inferencePlans: ["hold"] });
11691181
const controller = new AbortController();
11701182
const result = runWorkerDescriptor(launch, { signal: controller.signal });
1171-
await waitForFast(() => expect(gateway.inferenceRequests).toHaveLength(1));
1183+
await gateway.waitForInferenceStart();
11721184

11731185
controller.abort(new Error("operator stopped worker"));
11741186

@@ -1187,7 +1199,7 @@ describe("worker runtime", () => {
11871199
});
11881200
const controller = new AbortController();
11891201
const result = runWorkerDescriptor(launch, { signal: controller.signal });
1190-
await waitForFast(() => expect(gateway.inferenceRequests).toHaveLength(1));
1202+
await gateway.waitForInferenceStart();
11911203

11921204
vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
11931205
const timeoutSpy = vi.spyOn(globalThis, "setTimeout");

0 commit comments

Comments
 (0)