Skip to content

Latest commit

 

History

History
108 lines (87 loc) · 6.12 KB

flaky-test-quarantine.md

File metadata and controls

108 lines (87 loc) · 6.12 KB

Flaky-test quarantine

A quarantined test is skipped in normal CI so a known-flaky case stops blocking merges. An automation owns the list: it quarantines a test that fails in at least 2 of the last 10 completed main CI runs (threshold 2/10). This document describes the mechanism and how to edit the list by hand.

How it works

  • The list lives in the Lakebase Postgres table quarantined_tests in project ug-ci (workspace eng-ml-inference-team-us-east-1, branch production, database databricks_postgres). CI reads rows with repo = <this repo> and active = true. Open it directly with databricks psql --project ug-ci (see the Lakebase docs).
  • The quarantine-list job in .github/workflows/ci.yml runs scripts/quarantine_fetch.py once per run and uploads the quarantine-list artifact. It is a job of its own so the unit shards, which run PR code, never hold credentials. The script mints a one-hour Lakebase credential with the CI Databricks identity (M2M OAuth from the E2E_ADMIN_SP_CLIENT_ID/E2E_ADMIN_SP_CLIENT_SECRET secrets when available, else the static DATABRICKS_BEARER the integration tests use), asks SCIM /Me who it is, prints that identity (it is the Postgres username), and runs one read-only psql query. With no secrets (fork PRs) or on any error it writes an empty list and CI runs every test (fail open).
  • Every CI job that runs pytest downloads the artifact (Download the quarantine list, continue-on-error) to $RUNNER_TEMP/quarantine/quarantine.json; the plugin tests/quarantine.py reads UG_QUARANTINE_FILE, else that path, and marks matching cases skip with reason quarantined (flaky): <reason>. Cases are skipped, not deselected, so reports that count cases (scripts/unit_test_times.py, tests.live_shard verify) still see each once.
  • test_id is the repo-relative path from the repository root plus the pytest node tail, whatever the pytest rootdir is, e.g. tests/integration/test_installation.py::test_x or tests/test_e2e.py::TestGeminiLaunch::test_launch_gemini_per_model[param].

Coverage

Suite Plugin loaded by List reaches it by
Unit shards (Linux, Windows) root conftest.py download step, UG_QUARANTINE_FILE exported
Agent launch tests (tests/test_e2e.py) root conftest.py download step, default path
Claude mod (tests/native_claude) root conftest.py download step, default path
Integration (scripts/run_integration.py, live-steps action and direct lanes) tests/integration/conftest.py download step; run_integration.py forwards UG_QUARANTINE_FILE into the isolated pytest
CUJs (tests/e2e_cuj, dedicated-cuj) tests/e2e_cuj/conftest.py download step, default path

run_integration.py normally fails on any skipped test. It now tolerates skips whose JUnit message starts with quarantined (flaky):; every other skip still fails the run.

Not covered: harness-latest.yml and publish-skills-test.yml run pytest in separate workflows that have no quarantine-list job, and integration-advisory.yml and fork-integration.yml call the integration lanes without one. There the download fails open, so every test runs.

Recovery lane

The hourly schedule run writes an empty list, so quarantined tests still run on main and produce real results in every suite's JUnit (for example the unit-shard-<OS>-<n> artifacts). A quarantined test that fails there turns that scheduled run red like any other failure; the automation reads these results to decide when to un-quarantine. PR, merge-group and manual runs apply the skips.

Manual edits

Connect with the CLI-minted credential as the Postgres password (SSL is required, and the username is your Databricks email; tokens live one hour):

databricks postgres generate-database-credential \
  projects/ug-ci/branches/production/endpoints/primary --profile eng-ml-inference --output json \
  | jq -r .token > /tmp/pg-token   # or paste it into PGPASSWORD yourself
PGPASSWORD=$(cat /tmp/pg-token) psql "host=ep-jolly-lab-d2fu17n9-pooler.database.us-east-1.cloud.databricks.com \
  port=5432 dbname=databricks_postgres user=<you>@databricks.com sslmode=require"

The table's primary key is (repo, branch, test_id), so quarantine is an upsert:

-- Quarantine
INSERT INTO quarantined_tests
  (repo, branch, test_id, active, quarantined_at, reason, last_evaluated_at, updated_by)
VALUES ('databricks/unity-gateway', 'main', 'tests/test_x.py::TestY::test_z', true,
        current_timestamp, 'manual: <why>', current_timestamp, '<your-name>')
ON CONFLICT (repo, branch, test_id) DO UPDATE SET
  active = true, reason = EXCLUDED.reason, last_evaluated_at = EXCLUDED.last_evaluated_at,
  updated_by = EXCLUDED.updated_by;

-- Un-quarantine
UPDATE quarantined_tests
SET active = false, unquarantined_at = current_timestamp, updated_by = '<your-name>'
WHERE repo = 'databricks/unity-gateway' AND branch = 'main' AND test_id = 'tests/test_x.py::TestY::test_z';

Roles and grants

The Postgres role for a Databricks identity is its email (users) or application ID (service principals). The project owner's role exists already; other identities need one via the databricks_auth extension (run once per identity, connected as the owner):

CREATE EXTENSION IF NOT EXISTS databricks_auth;
SELECT databricks_create_role('<email-or-application-id>', 'SERVICE_PRINCIPAL');  -- or 'USER'

-- read-only, what the CI fetcher needs
GRANT CONNECT ON DATABASE databricks_postgres TO "<email-or-application-id>";
GRANT USAGE ON SCHEMA public TO "<email-or-application-id>";
GRANT SELECT ON quarantined_tests TO "<email-or-application-id>";

-- the automation additionally writes (no DELETE)
GRANT SELECT, INSERT, UPDATE ON quarantined_tests TO "<automation-application-id>";

The first Quarantine list CI run logs CI identity <name> on <host>; grant that name. The Lakebase location (workspace host, endpoint, pooler host, database, table) is set once, in the plain env of the quarantine-list job in .github/workflows/ci.yml.