


























@@ -765,17 +765,16 @@ describe("TelegramPollingSession", () => {
765765});
766766});
767767768-it("does not trigger stall restart when non-getUpdates API calls are active", async () => {
768+it("triggers stall restart when getUpdates is stale despite recent non-getUpdates API success", async () => {
769769const abort = new AbortController();
770770const botStop = vi.fn(async () => undefined);
771771const runnerStop = vi.fn(async () => undefined);
772772const getApiMiddleware = mockBotCapturingApiMiddleware(botStop);
773773const resolveFirstTask = mockLongRunningPollingCycle(runnerStop);
774774775775// t=0: lastGetUpdatesAt and lastApiActivityAt initialized
776-// t=150_001: watchdog fires (getUpdates stale for 150s)
777-// But right before watchdog, a sendMessage succeeds at t=150_001
778-// All subsequent Date.now calls return the same value, giving apiIdle = 0.
776+// t=150_001: watchdog fires (getUpdates stale for 150s).
777+// Right before watchdog, a sendMessage succeeds at t=150_001.
779778const watchdogHarness = installPollingStallWatchdogHarness();
780779781780const log = vi.fn();
@@ -789,20 +788,19 @@ describe("TelegramPollingSession", () => {
789788const watchdog = await watchdogHarness.waitForWatchdog();
790789791790// Simulate a sendMessage call through the middleware before watchdog fires.
792-// This updates lastApiActivityAt, proving the network is alive.
791+// This updates unrelated API liveness, but inbound getUpdates remains stale.
793792const apiMiddleware = getApiMiddleware();
794793if (apiMiddleware) {
795794const fakePrev = vi.fn(async () => ({ ok: true }));
796795await apiMiddleware(fakePrev, "sendMessage", { chat_id: 123, text: "hello" });
797796}
798797799-// Now fire the watchdog — getUpdates is stale (120s) but API was just active
798+// Now fire the watchdog — getUpdates is stale (120s) even though API was just active.
800799watchdog?.();
801800802-// The watchdog should NOT have triggered a restart
803-expect(runnerStop).not.toHaveBeenCalled();
804-expect(botStop).not.toHaveBeenCalled();
805-expect(log).not.toHaveBeenCalledWith(expect.stringContaining("Polling stall detected"));
801+expect(runnerStop).toHaveBeenCalledTimes(1);
802+expect(botStop).toHaveBeenCalledTimes(1);
803+expect(log).toHaveBeenCalledWith(expect.stringContaining("Polling stall detected"));
806804807805// Clean up: abort to end the session
808806abort.abort();
@@ -813,7 +811,7 @@ describe("TelegramPollingSession", () => {
813811}
814812});
815813816-it("does not trigger stall restart while a recent non-getUpdates API call is in-flight", async () => {
814+it("triggers stall restart while a recent non-getUpdates API call is in-flight", async () => {
817815const abort = new AbortController();
818816const botStop = vi.fn(async () => undefined);
819817const runnerStop = vi.fn(async () => undefined);
@@ -848,13 +846,12 @@ describe("TelegramPollingSession", () => {
848846const sendPromise = apiMiddleware(slowPrev, "sendMessage", { chat_id: 123, text: "hello" });
849847850848// Fire the watchdog while sendMessage is still in-flight.
851-// The in-flight call started 60s ago, so API liveness is still recent.
849+// API liveness is still recent, but inbound getUpdates is stale.
852850watchdog?.();
853851854-// The watchdog should NOT have triggered a restart
855-expect(runnerStop).not.toHaveBeenCalled();
856-expect(botStop).not.toHaveBeenCalled();
857-expect(log).not.toHaveBeenCalledWith(expect.stringContaining("Polling stall detected"));
852+expect(runnerStop).toHaveBeenCalledTimes(1);
853+expect(botStop).toHaveBeenCalledTimes(1);
854+expect(log).toHaveBeenCalledWith(expect.stringContaining("Polling stall detected"));
858855859856// Resolve the in-flight call to clean up
860857resolveSendMessage?.({ ok: true });
@@ -920,7 +917,7 @@ describe("TelegramPollingSession", () => {
920917}
921918});
922919923-it("does not trigger stall restart when a newer non-getUpdates API call starts while an older one is still in-flight", async () => {
920+it("triggers stall restart when getUpdates is stale despite newer in-flight non-getUpdates API activity", async () => {
924921const abort = new AbortController();
925922const botStop = vi.fn(async () => undefined);
926923const runnerStop = vi.fn(async () => undefined);
@@ -965,13 +962,13 @@ describe("TelegramPollingSession", () => {
965962{ chat_id: 123, text: "newer" },
966963);
967964968-// The older send is stale, but the newer send started just now.
969-// Watchdog liveness must follow the newest active non-getUpdates call.
965+// The older send is stale and the newer send started recently.
966+// Watchdog liveness must still follow getUpdates, not unrelated API calls.
970967watchdog?.();
971968972-expect(runnerStop).not.toHaveBeenCalled();
973-expect(botStop).not.toHaveBeenCalled();
974-expect(log).not.toHaveBeenCalledWith(expect.stringContaining("Polling stall detected"));
969+expect(runnerStop).toHaveBeenCalledTimes(1);
970+expect(botStop).toHaveBeenCalledTimes(1);
971+expect(log).toHaveBeenCalledWith(expect.stringContaining("Polling stall detected"));
975972976973resolveFirstSend?.({ ok: true });
977974resolveSecondSend?.({ ok: true });
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。