Public: anyone can read this; the crew can change it.
Stop refiling the changelog flaky test, and get the stuck pulls merging again #15582
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15581-stop-refiling-the-changelog-flaky-test-a → main 0 commits fork 1 thread · 1 unresolved
2 files
changed +40
−1
src/rules/flake_trend.ts +17 −1
| @@ -22,13 +22,15 @@ export interface Trend { | ||
| 22 | 22 | readonly test: string; |
| 23 | 23 | readonly file: string; |
| 24 | 24 | readonly count: number; |
| 25 | /** The latest flake's time (ISO). */ | |
| 26 | readonly last: string; | |
| 25 | 27 | /** Gate minutes the flakes delayed, one decimal. */ |
| 26 | 28 | readonly minutes: number; |
| 27 | 29 | } |
| 28 | 30 | |
| 29 | 31 | /** The read behind the trend: `?1` = the week's start (ISO), `?2` = the row limit. */ |
| 30 | 32 | export const FLAKE_TREND_SQL = `SELECT f.repo_id AS repoId, u.username || '/' || r.name AS repo, f.test AS test, MAX(f.file) AS file, |
| 31 | COUNT(*) AS count, | |
| 33 | COUNT(*) AS count, MAX(f.at) AS last, | |
| 32 | 34 | ROUND(SUM(COALESCE( |
| 33 | 35 | (SELECT g.duration_ms FROM gate_result g WHERE g.run_id = f.run_id AND g.repo_id = f.repo_id LIMIT 1), |
| 34 | 36 | (SELECT MAX(0, (julianday(c.finished_at) - julianday(c.started_at)) * 86400000) FROM run c WHERE c.id = f.run_id), |
| @@ -59,6 +61,17 @@ export function weekOf(now: number): string { | ||
| 59 | 61 | return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate() - back)).toISOString().slice(0, 10); |
| 60 | 62 | } |
| 61 | 63 | |
| 64 | /** Whether an issue under `title` was closed at or after `last`: nothing has flaked since. */ | |
| 65 | function closedSince(db: Database, repoId: string, title: string, last: string): boolean { | |
| 66 | return ( | |
| 67 | db | |
| 68 | .query<{ n: number }, [string, string, string]>( | |
| 69 | "SELECT 1 AS n FROM issue WHERE repo_id = ?1 AND title = ?2 AND state = 'closed' AND closed_at >= ?3 LIMIT 1", | |
| 70 | ) | |
| 71 | .get(repoId, title, last) !== null | |
| 72 | ); | |
| 73 | } | |
| 74 | ||
| 62 | 75 | /** An issue for each of the worst {@link WORST} that names a file; returns the numbers opened. */ |
| 63 | 76 | export function fileWorst(db: Database, bus: EventBus, repos: ReadonlyMap<string, Pick<Repo, "id" | "ownerId">>, list: readonly Trend[]): number[] { |
| 64 | 77 | const opened: number[] = []; |
| @@ -66,6 +79,9 @@ export function fileWorst(db: Database, bus: EventBus, repos: ReadonlyMap<string | ||
| 66 | 79 | const repo = repos.get(t.repoId); |
| 67 | 80 | // No file, no "Files:" line to route it to a builder: no issue. |
| 68 | 81 | if (repo === undefined || t.file === "") continue; |
| 82 | // Closed since its last flake: the week's rows are history, not news. Filing again each | |
| 83 | // pass is the loop that refiled one test every 15 minutes (#15581); a new flake files again. | |
| 84 | if (closedSince(db, t.repoId, flakeTitle(t.test), t.last)) continue; | |
| 69 | 85 | const filed = fileIssueOnce(db, bus, repo, { |
| 70 | 86 | title: flakeTitle(t.test), |
| 71 | 87 | body: |
test/rules-flake-trend.test.ts +23
| @@ -47,3 +47,26 @@ test("the trend is said on the first run of a week, and its probe is the real qu | ||
| 47 | 47 | expect(() => w.app.db.query(FLAKE_TREND_SQL).all("2000-01-01T00:00:00Z", 5)).not.toThrow(); |
| 48 | 48 | expect(flakeWeek(watch, monday + 1000).findings).toEqual([]); |
| 49 | 49 | }); |
| 50 | ||
| 51 | test("a flake whose issue was closed after its last flake is not filed again; a newer flake files it", () => { | |
| 52 | const db = w.app.db; | |
| 53 | seedFlake(db, w.repoId, "old > gone", "test/gone.test.ts", now - 2000, null, seedGate(db, w.repoId, [], [], now - 2000, 90)); | |
| 54 | seedFlake(db, w.repoId, "old > gone", "test/gone.test.ts", now - 1000, null, seedGate(db, w.repoId, [], [], now - 1000, 90)); | |
| 55 | expect(fileWorst(db, w.app.bus, w.repos, flakeTrend(db, now))).toHaveLength(1); | |
| 56 | db.query("UPDATE issue SET state = 'closed', closed_at = ?1 WHERE title = 'Flaky test: old > gone'").run(new Date(now).toISOString()); | |
| 57 | expect(fileWorst(db, w.app.bus, w.repos, flakeTrend(db, now))).toEqual([]); | |
| 58 | seedFlake(db, w.repoId, "old > gone", "test/gone.test.ts", now + 5000, null, seedGate(db, w.repoId, [], [], now + 5000, 90)); | |
| 59 | expect(fileWorst(db, w.app.bus, w.repos, flakeTrend(db, now + 6000))).toHaveLength(1); | |
| 60 | }); | |
| 61 | ||
| 62 | test("an issue closed BEFORE the latest flake does not hold it back: the flake files again", () => { | |
| 63 | const db = w.app.db; | |
| 64 | seedFlake(db, w.repoId, "later > flake", "test/later.test.ts", now - 3000, null, seedGate(db, w.repoId, [], [], now - 3000, 95)); | |
| 65 | seedFlake(db, w.repoId, "later > flake", "test/later.test.ts", now - 2000, null, seedGate(db, w.repoId, [], [], now - 2000, 95)); | |
| 66 | expect(fileWorst(db, w.app.bus, w.repos, flakeTrend(db, now))).toHaveLength(1); | |
| 67 | db.query("UPDATE issue SET state = 'closed', closed_at = ?1 WHERE title = 'Flaky test: later > flake'").run(new Date(now - 1500).toISOString()); | |
| 68 | seedFlake(db, w.repoId, "later > flake", "test/later.test.ts", now - 1000, null, seedGate(db, w.repoId, [], [], now - 1000, 95)); | |
| 69 | const opened = fileWorst(db, w.app.bus, w.repos, flakeTrend(db, now)); | |
| 70 | expect(opened).toHaveLength(1); | |
| 71 | expect(w.titles().filter((t) => t === "Flaky test: later > flake")).toHaveLength(2); | |
| 72 | }); |
new above
offline