diff --git a/packages/testkit/test/accept-pending.test.ts b/packages/testkit/test/accept-pending.test.ts index e6bab41f..5973b468 100644 --- a/packages/testkit/test/accept-pending.test.ts +++ b/packages/testkit/test/accept-pending.test.ts @@ -292,8 +292,12 @@ describe("ready-for-review only when mergeable", () => { t.green(t.push()); t.pull().mergeable = true; await t.toReview(); - await cardTick(); - const fresh = await cards(t.proj.id); + // The watchdog ticks until the card goes: on a loaded CI runner one Gitea answer may come too late for the first tick. + const fresh = await waitFor("a new message", async () => { + await cardTick(); + const c = await cards(t.proj.id); + return c.length ? c : null; + }); assert.equal(fresh.length, 1, "a new message"); assert.notEqual(fresh[0]!.id, q!.id); await t.stopAll(); diff --git a/packages/testkit/test/accept-screen.test.ts b/packages/testkit/test/accept-screen.test.ts index 9f176a16..52758187 100644 --- a/packages/testkit/test/accept-screen.test.ts +++ b/packages/testkit/test/accept-screen.test.ts @@ -6,7 +6,7 @@ import { mkdtempSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { after, before, describe, test } from "node:test"; -import { core, db, project, runner, setDefaultOwner, teardown } from "./helpers.ts"; +import { core, db, project, runner, setDefaultOwner, teardown, waitFor } from "./helpers.ts"; import { MockGitea } from "../src/mock-gitea.ts"; import { questions, releases, tasks, telegramOutbox, users } from "@peppa/db"; import { eq, sql } from "drizzle-orm"; @@ -132,7 +132,14 @@ describe("Сводка готовых в Telegram", () => { const { proj, refs } = await inReview(5); const t0 = Date.now(); for (const ref of refs) await core.sendReviewCard(db, ref, { text: `${ref.key} готова` }, null, null as never).catch(() => null); - const cards = (await db.select().from(questions).where(eq(questions.projectId, proj.id))).filter((q) => q.msgType === "done"); + // A slow Gitea answer (a loaded CI runner) holds a card back; the watchdog's ticks send it, as live. + const done = async () => (await db.select().from(questions).where(eq(questions.projectId, proj.id))).filter((q) => q.msgType === "done"); + const cards = await waitFor("five cards", async () => { + const c = await done(); + if (c.length >= 5) return c; + await runner.reviewCardTick(db); + return null; + }); assert.equal(cards.length, 5); for (const q of cards) assert.equal(await core.acceptDigestHold(db, q, new Date(t0 + 60_000)), "wait", "within the pause"); for (const q of cards) assert.equal(await core.acceptDigestHold(db, q, new Date(t0 + 400_000)), "held", "more than two within an hour");