Skip to content

test(ci): assert Relay rejection outcomes instead of ingestion timeouts - #128956

Closed
joshuarli wants to merge 3 commits into
masterfrom
ci/relay-rejection-outcomes
Closed

joshuarli wants to merge 3 commits into
masterfrom
ci/relay-rejection-outcomes

Conversation

@joshuarli

Copy link
Copy Markdown
Member

Why

The existing negative Relay tests call a helper that catches an AssertionError from the successful-ingestion path. An expected rejection therefore waits out the roughly 16-second ingestion timeout, and unrelated assertion failures can also look like successful rejection.

The post-merge master run shows a 16.54s missing-signature case on backend shard 17, and three filter cases totaling 53.36s on backend shard 5. This patch targets that timeout floor directly.

Changes

  • Add a lazy outcome-capture fixture that snapshots every outcomes-topic partition's concrete high-water offset before posting the event. Explicit offsets avoid the race in resolving OFFSET_END only at first poll.
  • Introduce post_and_assert_rejected, which submits a unique event ID, requires the cold asynchronous HTTP 200 response, and waits for the expected rejection outcome while pumping the existing ingestion consumer.
  • Match outcomes by organization, project, and key after the captured offsets. Relay aggregates away event IDs, so matching an outcome by event ID would be incorrect.
  • Require the error category, quantity of one, expected outcome enum, and exact reason. A missing outcome, unexpected outcome, or timeout fails the test.
  • Keep the final eventstore absence assertion. The explicit terminal rejection outcome is the primary evidence; this is not a claim that polling one Kafka topic drains all other topics.
  • Convert all nine negative cases: four filter cases and five trusted-Relay/signature cases.
  • Preserve the five follow-up warm HTTP 403 assertions and make the valid-signature case use the strict successful-ingestion helper.
  • Remove the broad assertion-catching helper and add eight rejection-helper cases, alongside the two existing readiness cases.

Expected outcome reasons are localhost, browser-extensions, web-crawlers, and legacy-browsers for filtered events; invalid_signature for untrusted, expired, or invalid signatures; and missing_signature for missing or null signatures.

The capture consumer is created only when a negative test invokes it and is closed in a finally block. Kafka errors propagate rather than becoming successful rejection.

Validation

  • All ten helper/readiness cases passed with actual application imports after the final changes.
  • The rejection tests use Arroyo's local broker, producer, and memory message storage. HTTP, eventstore lookup, and the waiting harness are mocked; the rejection helper itself is the actual implementation.
  • Cases verify that unrelated or unscoped outcomes are ignored, wrong category/quantity/reason/outcome fail, absent outcomes fail, unexpected immediate HTTP 403 fails, and an ingested event fails.
  • Repository pre-commit checks passed, including formatting and lint checks.
  • git diff --check passed.
  • The patch applies cleanly to the stated master base and reproduces all five reviewed files exactly.

The outcome schema and signature reasons were checked against Relay commit 2419fb638ab8ffb69928f36dfda5cf63da7604a0, particularly the outcome aggregation implementation and trusted-Relay integration tests.

CI validation still needed

This workspace has neither Docker nor the running services needed for the real Relay/Kafka integration suite. The real consumer's high-water capture and actual outcome delivery have therefore not been integration-tested here. Normal pytest also encounters Redis-dependent global teardown. The focused mypy attempt failed during Django plugin/stub initialization; it did not establish a passing type check.

Run the normal backend suite, including tests/relay_integration/test_message_filters.py and tests/relay_integration/test_integration.py, and inspect all nine converted cases. Expected successful durations should follow actual outcome delivery instead of a fixed ingestion timeout, but no CI speedup is claimed yet. Consumer setup, Kafka polling, and outcome batching remain part of the new cost.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 27, 2026
@joshuarli joshuarli added the Trigger: Override Selective Testing Run the full test suite; necessary in cases where selected tests are flaky due to reshuffling label Oct 27, 2026
@joshuarli joshuarli closed this Oct 28, 2026
joshuarli added a commit that referenced this pull request Nov 18, 2026
…on (#131170)

Supersedes #129071. Builds on the outcome-capture idea
from #128956, rebased onto current master.

`post_and_try_retrieve_event` swallowed the `AssertionError` from the
success path. That made every expected Relay rejection wait out the 16s
ingest timeout, and let unrelated failures pass as rejections.

`post_and_assert_rejected` replaces it. It reads the per-worker
`outcomes` topic from the high watermarks captured before the POST, then
waits for the outcome Relay emits for the project's org/project/key. It
asserts that outcome's type and reason. Relay aggregates outcomes and
drops event IDs, so the match uses org/project/key. That's unambiguous
because project IDs are snowflakes and each case posts once.

<!-- junior-request-attribution:start -->
via @joshuarli.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A0647f040aa198c6c1f091bf70f7089e1 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A0647f040aa198c6c1f091bf70f7089e1)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A0647f040aa198c6c1f091bf70f7089e1/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Joshua Li <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — be0dddcb Deployed Oct 28, 2026 by vercel[bot]
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 Trigger: Override Selective Testing Run the full test suite; necessary in cases where selected tests are flaky due to reshuffling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant