





















@@ -6,7 +6,7 @@ import {
66createStartAccountContext,
77} from "openclaw/plugin-sdk/channel-test-helpers";
88import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
9-import { afterEach, describe, expect, it, vi } from "vitest";
9+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
1010import { readCachedTelegramBotInfo, writeCachedTelegramBotInfo } from "./bot-info-cache.js";
1111import type { TelegramBotInfo } from "./bot-info.js";
1212import { telegramPlugin } from "./channel.js";
@@ -160,13 +160,23 @@ async function waitForCondition(check: () => boolean, message: string, timeoutMs
160160throw new Error(message);
161161}
162162163+async function waitForMicrotaskCondition(check: () => boolean, message: string, attempts = 100) {
164+for (let attempt = 0; attempt < attempts; attempt += 1) {
165+if (check()) {
166+return;
167+}
168+await Promise.resolve();
169+}
170+throw new Error(message);
171+}
172+163173async function releaseStartupProbeControls(releaseProbe: Array<() => void>) {
164174for (let attempt = 0; attempt < 10; attempt += 1) {
165175const releases = releaseProbe.splice(0);
166176for (const release of releases) {
167177release();
168178}
169-await new Promise((resolve) => setTimeout(resolve, 0));
179+await Promise.resolve();
170180if (releaseProbe.length === 0) {
171181return;
172182}
@@ -176,7 +186,13 @@ async function releaseStartupProbeControls(releaseProbe: Array<() => void>) {
176186}
177187}
178188189+beforeEach(() => {
190+vi.useRealTimers();
191+resetTelegramStartupProbeLimiterForTests();
192+});
193+179194afterEach(async () => {
195+vi.useRealTimers();
180196clearTelegramRuntime();
181197resetTelegramPollingLeasesForTests();
182198resetTelegramStartupProbeLimiterForTests();
@@ -464,14 +480,14 @@ describe("telegramPlugin gateway startup", () => {
464480const third = runProbe();
465481const tasks = [first, second, third];
466482try {
467-await waitForCondition(
483+await waitForMicrotaskCondition(
468484() => releaseProbe.length === 2,
469485"expected two startup probes to begin",
470486);
471487expect(maxActiveProbes).toBe(2);
472488473489releaseProbe.shift()?.();
474-await waitForCondition(
490+await waitForMicrotaskCondition(
475491() => releaseProbe.length === 2,
476492"expected queued startup probe to begin after a slot opens",
477493);
@@ -503,7 +519,7 @@ describe("telegramPlugin gateway startup", () => {
503519(error: unknown) => error,
504520);
505521try {
506-await waitForCondition(
522+await waitForMicrotaskCondition(
507523() => releaseProbe.length === 2,
508524"expected startup probe slots to fill",
509525);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。