


























@@ -3,7 +3,6 @@
33 */
44import { beforeEach, describe, expect, it, vi } from "vitest";
55import {
6-acknowledgeNodePendingWork,
76drainNodePendingWork,
87enqueueNodePendingWork,
98getNodePendingWorkStateCountForTests,
@@ -26,7 +25,7 @@ describe("node pending work", () => {
2625expect(drained.hasMore).toBe(false);
2726});
282729-it("dedupes explicit work by type and removes acknowledged items", () => {
28+it("dedupes explicit work by type until the node drains it", () => {
3029const first = enqueueNodePendingWork({ nodeId: "node-2", type: "location.request" });
3130const second = enqueueNodePendingWork({ nodeId: "node-2", type: "location.request" });
3231@@ -36,15 +35,11 @@ describe("node pending work", () => {
36353736const drained = drainNodePendingWork("node-2");
3837expect(drained.items.map((item) => item.type)).toEqual(["location.request", "status.request"]);
38+expect(getNodePendingWorkStateCountForTests()).toBe(0);
393940-const acked = acknowledgeNodePendingWork({
41-nodeId: "node-2",
42-itemIds: [first.item.id, "baseline-status"],
43-});
44-expect(acked.removedItemIds).toEqual([first.item.id]);
45-46-const afterAck = drainNodePendingWork("node-2");
47-expect(afterAck.items.map((item) => item.id)).toEqual(["baseline-status"]);
40+const afterDrain = enqueueNodePendingWork({ nodeId: "node-2", type: "location.request" });
41+expect(afterDrain.deduped).toBe(false);
42+expect(afterDrain.item.id).not.toBe(first.item.id);
4843});
49445045it("keeps hasMore true when the baseline status item is deferred by maxItems", () => {
@@ -54,36 +49,47 @@ describe("node pending work", () => {
54495550expect(drained.items.map((item) => item.type)).toEqual(["location.request"]);
5651expect(drained.hasMore).toBe(true);
52+expect(getNodePendingWorkStateCountForTests()).toBe(0);
53+54+const next = drainNodePendingWork("node-3", { maxItems: 1 });
55+expect(next.items.map((item) => item.id)).toEqual(["baseline-status"]);
56+expect(next.hasMore).toBe(false);
5757});
585859-it("does not allocate state for drain-only nodes with no queued work", () => {
60-expect(getNodePendingWorkStateCountForTests()).toBe(0);
59+it("keeps explicit work queued when maxItems defers it", () => {
60+enqueueNodePendingWork({ nodeId: "node-4", type: "status.request", priority: "normal" });
61+enqueueNodePendingWork({ nodeId: "node-4", type: "location.request", priority: "high" });
616262-const drained = drainNodePendingWork("node-4");
63-const acked = acknowledgeNodePendingWork({ nodeId: "node-4", itemIds: ["baseline-status"] });
63+const firstDrain = drainNodePendingWork("node-4", { maxItems: 1 });
64+expect(firstDrain.items.map((item) => item.type)).toEqual(["location.request"]);
65+expect(firstDrain.hasMore).toBe(true);
66+expect(getNodePendingWorkStateCountForTests()).toBe(1);
646765-expect(drained.items.map((item) => item.id)).toEqual(["baseline-status"]);
66-expect(acked).toEqual({ revision: 0, removedItemIds: [] });
68+const secondDrain = drainNodePendingWork("node-4", { maxItems: 1 });
69+expect(secondDrain.items.map((item) => item.type)).toEqual(["status.request"]);
70+expect(secondDrain.items.map((item) => item.id)).not.toEqual(["baseline-status"]);
71+expect(secondDrain.hasMore).toBe(false);
6772expect(getNodePendingWorkStateCountForTests()).toBe(0);
6873});
697470-it("prunes the state entry once all explicit items are acknowledged", () => {
71-const { item } = enqueueNodePendingWork({ nodeId: "node-5", type: "status.request" });
72-expect(getNodePendingWorkStateCountForTests()).toBe(1);
75+it("does not allocate state for drain-only nodes with no queued work", () => {
76+expect(getNodePendingWorkStateCountForTests()).toBe(0);
77+78+const drained = drainNodePendingWork("node-5");
737974-acknowledgeNodePendingWork({ nodeId: "node-5", itemIds: [item.id] });
80+expect(drained.items.map((item) => item.id)).toEqual(["baseline-status"]);
7581expect(getNodePendingWorkStateCountForTests()).toBe(0);
7682});
77837884it("prunes the state entry when all items expire naturally via drain", () => {
7985const queued = enqueueNodePendingWork({
80-nodeId: "node-6",
86+nodeId: "node-7",
8187type: "location.request",
8288expiresInMs: 5_000,
8389});
8490expect(getNodePendingWorkStateCountForTests()).toBe(1);
859186-const drained = drainNodePendingWork("node-6", { nowMs: Date.now() + 60_000 });
92+const drained = drainNodePendingWork("node-7", { nowMs: Date.now() + 60_000 });
87938894expect(drained.revision).toBeGreaterThan(queued.revision);
8995expect(getNodePendingWorkStateCountForTests()).toBe(0);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。