diff --git a/cloud/console-react/src/api/chv.closeup.test.ts b/cloud/console-react/src/api/chv.closeup.test.ts index 47adda4..ed7d758 100644 --- a/cloud/console-react/src/api/chv.closeup.test.ts +++ b/cloud/console-react/src/api/chv.closeup.test.ts @@ -69,8 +69,17 @@ describe("附件拦截与排队提示边角(closeup)", () => { }); describe("isWorkerAlive 边界(closeup)", () => { - it("last_seen 恰好 120 秒算在线(<=120)", () => { + // 精确边界不用活时钟测:原写法先取 Date.now() 再让被测函数 + // 内部重取一次时钟,age = 120 + 两次取时钟的差,两次取时钟 + // 跨过毫秒边界时 age = 120.001,<=120 判定为 false,约 7% + // 概率抖动(30 轮 2 败,均是本用例)。生产逻辑 <=120 本身 + // 没错,错的是用活时钟测精确边界。 + it("恰好 120 秒算在线(<=120,用不取时钟的字段确定性测)", () => { + expect(isWorkerAlive({ executor: "cloud-hypervisor", last_seen_seconds_ago: 120 })).toBe(true); + expect(isWorkerAlive({ executor: "cloud-hypervisor", last_seen_seconds_ago: 121 })).toBe(false); + }); + it("活时钟只测带 1 秒余量的内侧,不测精确边界", () => { const now = Date.now() / 1000; - expect(isWorkerAlive({ executor: "cloud-hypervisor", last_seen: now - 120 })).toBe(true); + expect(isWorkerAlive({ executor: "cloud-hypervisor", last_seen: now - 119 })).toBe(true); }); });