





















@@ -146,6 +146,7 @@ function sendMessageOptionsAt(index: number): Record<string, unknown> {
146146}
147147148148async function waitForCondition(check: () => boolean, message: string, timeoutMs = 5_000) {
149+vi.useRealTimers();
149150const deadline = Date.now() + timeoutMs;
150151while (Date.now() < deadline) {
151152if (check()) {
@@ -449,25 +450,32 @@ describe("telegramPlugin gateway startup", () => {
449450const first = startTelegramAccount("alpha");
450451const second = startTelegramAccount("bravo");
451452const third = startTelegramAccount("charlie");
453+const tasks = [first.task, second.task, third.task];
454+try {
455+await waitForCondition(
456+() => probeTelegram.mock.calls.length === 2,
457+"expected two startup probes to begin",
458+);
459+expect(maxActiveProbes).toBe(2);
460+expect(releaseProbe).toHaveLength(2);
452461453-await waitForCondition(
454-() => probeTelegram.mock.calls.length === 2,
455-"expected two startup probes to begin",
456-);
457-expect(maxActiveProbes).toBe(2);
458-expect(releaseProbe).toHaveLength(2);
459-460-releaseProbe.shift()?.();
461-await waitForCondition(
462-() => probeTelegram.mock.calls.length === 3,
463-"expected queued startup probe to begin after a slot opens",
464-);
465-expect(maxActiveProbes).toBe(2);
462+releaseProbe.shift()?.();
463+await waitForCondition(
464+() => probeTelegram.mock.calls.length === 3,
465+"expected queued startup probe to begin after a slot opens",
466+);
467+expect(maxActiveProbes).toBe(2);
466468467-for (const release of releaseProbe.splice(0)) {
468-release();
469+for (const release of releaseProbe.splice(0)) {
470+release();
471+}
472+await Promise.all(tasks);
473+} finally {
474+for (const release of releaseProbe.splice(0)) {
475+release();
476+}
477+await Promise.allSettled(tasks);
469478}
470-await Promise.all([first.task, second.task, third.task]);
471479expect(monitorTelegramProvider).toHaveBeenCalledTimes(3);
472480});
473481@@ -495,17 +503,25 @@ describe("telegramPlugin gateway startup", () => {
495503const second = startTelegramAccount("bravo");
496504const abortQueued = new AbortController();
497505const queued = startTelegramAccount("charlie", {}, abortQueued.signal);
506+const tasks = [first.task, second.task, queued.task];
507+try {
508+await waitForCondition(
509+() => probeTelegram.mock.calls.length === 2,
510+"expected startup probe slots to fill",
511+);
512+abortQueued.abort();
498513499-await waitForCondition(
500-() => probeTelegram.mock.calls.length === 2,
501-"expected startup probe slots to fill",
502-);
503-abortQueued.abort();
504-505-for (const release of releaseProbe.splice(0)) {
506-release();
514+for (const release of releaseProbe.splice(0)) {
515+release();
516+}
517+await Promise.all(tasks);
518+} finally {
519+abortQueued.abort();
520+for (const release of releaseProbe.splice(0)) {
521+release();
522+}
523+await Promise.allSettled(tasks);
507524}
508-await Promise.all([first.task, second.task, queued.task]);
509525expect(probeTelegram).toHaveBeenCalledTimes(2);
510526expect(monitorTelegramProvider).toHaveBeenCalledTimes(2);
511527});
此內容由慣性聚合(RSS閱讀器)自動聚合整理,僅供閱讀參考。 原文來自 — 版權歸原作者所有。