fix: 防止 HWPOD operation 重复派发
This commit is contained in:
@@ -426,6 +426,13 @@ test("cloud-api dispatches hwpod-node-ops to outbound WebSocket hwpod-node by no
|
||||
assert.equal(payload.nodeId, "pc-host-1");
|
||||
assert.equal(payload.results[0].op, "workspace.ls");
|
||||
assert.equal(payload.results[0].output.entries.some((entry: any) => entry.name === "main.c"), true);
|
||||
const recoveredResponse = await fetch(`${runtime.url}/v1/hwpod-node-ops?planId=${encodeURIComponent(plan.planId)}`);
|
||||
const recovered = await recoveredResponse.json();
|
||||
assert.equal(recoveredResponse.status, 200);
|
||||
assert.equal(recovered.status, "completed");
|
||||
assert.equal(recovered.result.planId, payload.planId);
|
||||
assert.equal(recovered.result.status, payload.status);
|
||||
assert.deepEqual(recovered.result.results, payload.results);
|
||||
} finally {
|
||||
connector.close();
|
||||
runtime.stop();
|
||||
@@ -433,6 +440,28 @@ test("cloud-api dispatches hwpod-node-ops to outbound WebSocket hwpod-node by no
|
||||
}
|
||||
});
|
||||
|
||||
test("WebSocket registry reuses one authoritative operation for concurrent duplicate admission", async () => {
|
||||
const sent: any[] = [];
|
||||
let dispatchCount = 0;
|
||||
const socket = { send(value: string) { const message = JSON.parse(value); sent.push(message); if (message.type === "hwpod-node-ops") dispatchCount += 1; }, close() {} };
|
||||
const registry = createHwpodNodeWsRegistry({ now: () => "2026-07-17T02:00:00.000Z" });
|
||||
registry.openBunSocket(socket);
|
||||
registry.handleBunMessage(socket, JSON.stringify({ type: "register", nodeId: "pc-host-1", name: "PC Host", capabilities: ["workspace.ls"], maxInFlight: 2 }));
|
||||
const plan = samplePlan();
|
||||
plan.nodeId = "pc-host-1";
|
||||
plan.planId = "harnessrl-run:build:v1";
|
||||
const first = registry.dispatch(plan, { requestId: "req_first" }, { timeoutMs: 5000 });
|
||||
const retry = registry.dispatch(plan, { requestId: "req_retry" }, { timeoutMs: 5000 });
|
||||
assert.equal(dispatchCount, 1);
|
||||
registry.handleBunMessage(socket, JSON.stringify({ type: "hwpod-node-ops-result", requestId: "req_first", nodeId: "pc-host-1", result: { ok: true, status: "completed", results: [{ opId: "op_1", ok: true }] } }));
|
||||
assert.deepEqual(await retry, await first);
|
||||
assert.equal(registry.lookup(plan.planId)?.result?.status, "completed");
|
||||
const recovered = await registry.dispatch(plan, { requestId: "req_after_completion" }, { timeoutMs: 5000 });
|
||||
assert.equal(recovered.status, "completed");
|
||||
assert.equal(dispatchCount, 1);
|
||||
registry.closeBunSocket(socket);
|
||||
});
|
||||
|
||||
test("WebSocket registry keeps readiness probes separate and rejects dispatch above maxInFlight", async () => {
|
||||
const sent: any[] = [];
|
||||
const socket = { send(value: string) { sent.push(JSON.parse(value)); }, close() {} };
|
||||
|
||||
Reference in New Issue
Block a user