Public: anyone can read this; the crew can change it.

Stop refiling the changelog flaky test, and get the stuck pulls merging again #15582

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/15581-stop-refiling-the-changelog-flaky-test-a → main 0 commits fork 1 thread · 1 unresolved

  • Merged. scout/15581-stop-refiling-the-changelog-flaky-test-a was merged into main as 6ff7457.

Review

Sign in to review this change.
2 files changed +40 −1
src/rules/flake_trend.ts +17 −1
@@ -22,13 +22,15 @@ export interface Trend {
2222 readonly test: string;
2323 readonly file: string;
2424 readonly count: number;
25 /** The latest flake's time (ISO). */
26 readonly last: string;
2527 /** Gate minutes the flakes delayed, one decimal. */
2628 readonly minutes: number;
2729 }
2830
2931 /** The read behind the trend: `?1` = the week's start (ISO), `?2` = the row limit. */
3032 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,
3234 ROUND(SUM(COALESCE(
3335 (SELECT g.duration_ms FROM gate_result g WHERE g.run_id = f.run_id AND g.repo_id = f.repo_id LIMIT 1),
3436 (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 {
5961 return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate() - back)).toISOString().slice(0, 10);
6062 }
6163
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
6275 /** An issue for each of the worst {@link WORST} that names a file; returns the numbers opened. */
6376 export function fileWorst(db: Database, bus: EventBus, repos: ReadonlyMap<string, Pick<Repo, "id" | "ownerId">>, list: readonly Trend[]): number[] {
6477 const opened: number[] = [];
@@ -66,6 +79,9 @@ export function fileWorst(db: Database, bus: EventBus, repos: ReadonlyMap<string
6679 const repo = repos.get(t.repoId);
6780 // No file, no "Files:" line to route it to a builder: no issue.
6881 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;
6985 const filed = fileIssueOnce(db, bus, repo, {
7086 title: flakeTitle(t.test),
7187 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
4747 expect(() => w.app.db.query(FLAKE_TREND_SQL).all("2000-01-01T00:00:00Z", 5)).not.toThrow();
4848 expect(flakeWeek(watch, monday + 1000).findings).toEqual([]);
4949 });
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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs