Skip to content

fix(tests): Address review feedback on test infra changes - #127948

Merged
joshuarli merged 3 commits into
masterfrom
jl/test-infra-retro-followups
Oct 17, 2026
Merged

joshuarli merged 3 commits into
masterfrom
jl/test-infra-retro-followups

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes from the retro on #127938, #127939, #127941, #127942 and #127943. Scheduling is unchanged: --dist=loadfile, deterministic order, and xdist 3.8.0 with loadscopereorder = False.

Filtered sharded runs (first commit)

Since #127943, pytest-selected.py plans shards by file before pytest applies -m/-k. Snuba's CI runs sentry's tests with PYTEST_ADDOPTS="-k 'not __In' -m snuba_ci" over 16 shards, so most shards collected 0 tests, exited 5, and cancelled the rest (e.g. getsentry/snuba#8556). With -m/-k in the args or PYTEST_ADDOPTS, every shard now collects everything and keeps its hash share, as before #127943. Sentry's own CI passes neither, so it keeps per-file sharding. Snuba checks out sentry master, so Snuba PRs pick this up on their next run. getsentry/snuba#8556's rerun (attempt 2, started after this merged at 300ebe3) went green, all 16 sentry shards included.

I ran Snuba's collection locally (make test-python-ci args plus the filter, --collect-only, 16 shards). Unsharded, 78 tests are selected:

Shards with 0 tests Tests per shard Union == unsharded
#127943 8 of 16 0–23 yes
this PR 0 of 16 2–8 yes, each test once

Fixes

Tests: the JSON report and the Snuba filter run real plugin stacks in a subprocess (the JSON report in-process and with -n 2; the filter checks each test runs exactly once with a Counter). The flush has a writer blocked during cleanup and a writer that's already open at the flush. Relay uses a mocked clock. The JSON report, filter and flush tests fail without their fix.

Declined: an opt-in flag or kill switch for the flush, non-Postgres support, provenance checks for the durations merge, changes to test_client_config.py (no shared state found; reverse order passes all 758 subtests), and docs for running a single subtest.

CI timing

"Run backend test" step across 22 shards, full runs with no test selection (master push and workflow_dispatch):

Run Sum Median shard Max shard
master a636572 (39051886634) 128.5 min 365 s 436 s
this PR before simplification (39059207673) 123.6 min 342 s 424 s
this PR (39061061527) 131.8 min 382 s 441 s

All 22 shards passed in each run. The spread between the three runs (123.6–131.8 min) is runner noise. Files with transactional tests took 34.9 min on master and 36.4 min here (+4%), while all other files took 297.0 and 304.9 min (+3%). Locally, the lock adds about 18 ms per teardown across all three databases (33 ms against 15 ms without it), while Django's flush takes about 1.14 s. So #127941's saving holds.

via @joshuarli.

--

View Junior Session [Sentry]

Per-file sharding plans whole files before pytest applies marker and keyword
filters, so a filtered run puts its few matching files on a few shards. Snuba's
CI runs sentry's tests with `-m snuba_ci` (via PYTEST_ADDOPTS) over 16 shards:
most shards collected 0 tests, exited with code 5 and cancelled the rest.

When -m or -k appear in the args or PYTEST_ADDOPTS, every shard collects
everything and keeps its per-test hash share, as before per-file sharding.
- Keep pytest 9 subtest reports out of the JSON report's reruns, and show
  failed subtests in backend failure comments.
- Lock tables while the transactional flush takes its inventory and deletes;
  fall back to Django's flush when a writer holds them.
- Bound Relay readiness probes by the time left and remove the container when
  readiness fails.
- Give each span buffer permutation a fresh SpansBuffer.
- Fall back to hash sharding for paths per-file sharding cannot match, and
  validate merged duration shards.

Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
@github-actions github-actions Bot added Scope: Frontend Automatically applied to PRs that change frontend components Scope: Backend Automatically applied to PRs that change backend components labels Oct 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚨 Warning: This pull request contains Frontend and Backend changes!

It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently.

Have questions? Please ask in the #discuss-dev-infra channel.

Keep the fixes and the tests that prove them, and drop the rest: the flush kill switch, test hook and pg_stat_activity check (an ACCESS EXCLUSIVE lock with a timeout covers it), the Relay readiness DI and exception class, the durations provenance checks, the failure-comment subtest cap, and the overlapping tests.

The -m/-k and path checks are now one predicate in pytest-selected.py, and pytest_shard_plugin keeps the rootdir check, which only pytest can make.

Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
@joshuarli
joshuarli marked this pull request as ready for review October 17, 2026 19:11
@joshuarli
joshuarli requested review from a team as code owners October 17, 2026 19:11
@joshuarli
joshuarli enabled auto-merge (squash) October 17, 2026 19:17
@joshuarli
joshuarli merged commit 300ebe3 into master Oct 17, 2026
127 checks passed
@joshuarli
joshuarli deleted the jl/test-infra-retro-followups branch October 17, 2026 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant