Skip to content

Commit

Permalink
test: Fix non-idempotent test
Browse files Browse the repository at this point in the history
Fix `tests/test_basic.py::test_event_processor_drop_records_client_report` so that the test is idempotent on failure. Previously, the test was only idempotent on success; if the test failed, it would cause many other unrelated tests to fail with it.
  • Loading branch information
szokeasaurusrex committed Jul 8, 2024
1 parent 9b6a718 commit 9c9f709
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from tests.conftest import patch_start_tracing_child

import sentry_sdk
import sentry_sdk.scope
from sentry_sdk import (
push_scope,
configure_scope,
Expand All @@ -29,10 +30,7 @@
)
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk.integrations.redis import RedisIntegration
from sentry_sdk.scope import ( # noqa: F401
add_global_event_processor,
global_event_processors,
)
from sentry_sdk.scope import add_global_event_processor
from sentry_sdk.utils import get_sdk_name, reraise
from sentry_sdk.tracing_utils import has_tracing_enabled

Expand Down Expand Up @@ -581,21 +579,31 @@ def test_event_processor_drop_records_client_report(
events = capture_events()
reports = capture_client_reports()

global global_event_processors
# Ensure full idempotency by restoring the original global event processors list object, not just a copy.
old_processors = sentry_sdk.scope.global_event_processors

@add_global_event_processor
def foo(event, hint):
return None
try:
sentry_sdk.scope.global_event_processors = (
sentry_sdk.scope.global_event_processors.copy()
)

capture_message("dropped")
@add_global_event_processor
def foo(event, hint):
return None

with start_transaction(name="dropped"):
pass
capture_message("dropped")

assert len(events) == 0
assert reports == [("event_processor", "error"), ("event_processor", "transaction")]
with start_transaction(name="dropped"):
pass

assert len(events) == 0
assert reports == [
("event_processor", "error"),
("event_processor", "transaction"),
]

global_event_processors.pop()
finally:
sentry_sdk.scope.global_event_processors = old_processors


@pytest.mark.parametrize(
Expand Down

0 comments on commit 9c9f709

Please sign in to comment.