Skip to content

Commit 4b482ed

Browse files
nicktrnTrigger.dev RepoOps
authored andcommitted
test(webapp): retry pg_stat_activity read in alert partition test
Mono-RevId: edd849a674edd3a308c2f8e979ad6ec908395989
1 parent e228086 commit 4b482ed

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

‎apps/webapp/test/alertPartitions.test.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,21 @@ describe("ensureAlertHistoryPartitions", () => {
194194
expect(result.connectionStuck).toBe(true);
195195
stuck = result.deferred[result.deferred.length - 1]?.name;
196196
expect(stuck).toMatch(/^AlertDelivery_p/);
197-
const { rows } = await client.query(
198-
`SELECT count(*)::int AS n FROM pg_stat_activity
197+
const readActive = async () => {
198+
const { rows } = await client.query(
199+
`SELECT count(*)::int AS n FROM pg_stat_activity
199200
WHERE query LIKE '%alerts-partitions:%' AND state = 'active'
200201
AND pid <> pg_backend_pid()`
201-
);
202-
expect(rows[0]?.n).toBe(0);
202+
);
203+
return rows[0]?.n as number | undefined;
204+
};
205+
const settleBy = Date.now() + 2_000;
206+
let active = await readActive();
207+
while (active !== 0 && Date.now() < settleBy) {
208+
await new Promise((r) => setTimeout(r, 50));
209+
active = await readActive();
210+
}
211+
expect(active).toBe(0);
203212
} finally {
204213
release();
205214
await holder;

0 commit comments

Comments
 (0)