Repository navigation
fix(tests): Address review feedback on test infra changes - #127948
Merged
Merged
Conversation
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>
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 |
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
marked this pull request as ready for review
October 17, 2026 19:11
joshuarli
approved these changes
Oct 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes from the retro on #127938, #127939, #127941, #127942 and #127943. Scheduling is unchanged:
--dist=loadfile, deterministic order, and xdist 3.8.0 withloadscopereorder = False.Filtered sharded runs (first commit)
Since #127943,
pytest-selected.pyplans shards by file before pytest applies-m/-k. Snuba's CI runs sentry's tests withPYTEST_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/-kin the args orPYTEST_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 16sentryshards included.I ran Snuba's collection locally (
make test-python-ciargs plus the filter,--collect-only, 16 shards). Unsharded, 78 tests are selected:Fixes
rerunsentries, and failure comments only showed "contains 1 failed subtest".json_report_reruns.pynow keeps one parentsetup/call/teardownand puts subtests in asubtestslist with their context and longrepr. Real reruns keep their own subtests. Failure comments show each failed subtest'sSUBFAILEDline and traceback.ACCESS EXCLUSIVE, 1slock_timeout). If another transaction has touched a table, the lock times out and Django's flush runs, which waits for that transaction the wayTRUNCATEalways has. That made thepg_stat_activitycheck redundant, so I removed it.min(1s, time left)and no probe starts after the deadline. It catchesrequests.RequestExceptioninstead ofException. The error includes the last status or exception, and the container is removed on failure.test_buffer.pybuilds a freshSpansBufferfor each permutation...paths also fall back to hash sharding.pytest_shard_pluginraises a usage error if the rootdir isn't the working directory (e.g.--rootdirpointing elsewhere), instead of quietly mismatching paths.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 aCounter). 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):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]