Skip to content

Commit 18fb2b2

Browse files
fix(tests): Stop test_global_config from leaking option overrides (#128459)
Fixes intermittent master failures of `tests/relay_integration/test_integration.py::SentryRemoteTest::test_standalone_attachment` (`assert None` in `post_and_retrieve_attachment`), e.g. https://github.com/getsentry/sentry/actions/runs/39675570221. **Cause** `test_global_config` in `tests/sentry/api/endpoints/test_relay_globalconfig_v3.py` uses the `@override_options` decorator together with pytest-django's `settings` fixture (added in #127378). The decorator's `override_settings(SENTRY_OPTIONS=...)` exits before the fixture's override is torn down. The fixture then restores the decorator's settings holder, so the overridden `SENTRY_OPTIONS` stay in place for every later test on that worker. After running it, `options.get("relay.objectstore-attachments.sample-rate")` returns `1.0` in an unrelated test instead of `0.0`, and the same goes for `relay.attachment-inline.limit` and `relay.upload-max-chunk.size`. These values reach the test Relay through the global config. The leak has existed since Oct 15. It started failing on master after #128359 added test files, which changed the shard plan. Part 0 of the split `test_integration.py` moved from shard 14 to shard 10, which also runs `test_relay_globalconfig_v3.py`. It fails only when xdist `--dist=loadfile` puts both files on the same worker, which is why it fails on some runs and not others. All 5 reruns fail because the leaked state stays for the life of the worker. **Fix** Nest `override_settings` inside the test body so the two overrides unwind in order. The test change is the only change. **Verification** (local, `-n0`, Kafka/Snuba/Relay via devservices) - `pytest test_relay_globalconfig_v3.py test_integration.py::SentryRemoteTest::test_standalone_attachment`: parent commit fails 1 of 10, fixed commit passes 10 of 10 (run twice) - `test_standalone_attachment` alone passes on the parent commit - `prek` is clean on the changed file <!-- junior-request-attribution:start --> via **dan**. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3ACUHS29QJ0%3A1792617789.618129 --> -- [View Junior Session](https://junior-prod.sentry.dev/conversations/slack%3ACUHS29QJ0%3A1792617789.618129) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3ACUHS29QJ0%3A1792617789.618129/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Dan Fuller <dfuller@sentry.io>
1 parent d34b312 commit 18fb2b2

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎tests/sentry/api/endpoints/test_relay_globalconfig_v3.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import orjson
55
import pytest
6+
from django.test import override_settings
67
from django.urls import reverse
78
from sentry_relay.processing import normalize_global_config
89

@@ -60,9 +61,11 @@ def inner(version, global_):
6061
"relay.upload-max-chunk.size": 123,
6162
}
6263
)
63-
def test_global_config(settings, inbound_filters_custom_error_values) -> None:
64-
settings.SENTRY_INBOUND_FILTER_CUSTOM_VALUES = inbound_filters_custom_error_values
65-
config = get_global_config()
64+
def test_global_config(inbound_filters_custom_error_values) -> None:
65+
# Nest the settings override inside `override_options`: the `settings` fixture
66+
# is torn down after the decorator exits, which leaks the options into later tests.
67+
with override_settings(SENTRY_INBOUND_FILTER_CUSTOM_VALUES=inbound_filters_custom_error_values):
68+
config = get_global_config()
6669

6770
normalized = normalize_global_config(config)
6871
expected = deepcopy(config)

0 commit comments

Comments
 (0)