test(chv): 修复 isWorkerAlive 边界测试抖动(精确边界改确定性字段测)

This commit is contained in:
host committed 2026-11-01 00:44:12 +08:00
1 parent 54f20dfe55
commit e718f0f326
1 file changed
+11 -2
@@ -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);
});
});