You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(tests): proper dummy transport clean up for hub cloning (#2957)
* test(test_helper): add failing regression specs for clone_hub event leak (#2951)
Captures the documented bug where setup_sentry_test is ineffective in
request specs because clone_hub_to_current_thread clones @main_hub rather
than the thread-local hub setup_sentry_test mutated, and DummyTransport
has no #clear, so events from a prior unrelated request leak into a later
test via the main hub's base-layer DummyTransport.
- Reproduction spec (intentional TDD red): after a setup/teardown cycle,
an intermediate clone_hub_to_current_thread + capture, then a second
setup_sentry_test, sentry_events must be empty both immediately and
after a further clone_hub_to_current_thread. Currently the second
assertion fails because the stale event is still visible.
- Guard spec (passes today, must keep passing): events captured through
a hub cloned by the Rack middleware after setup_sentry_test remain
observable via sentry_events, so the eventual fix cannot regress by
silently dropping request-captured events.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* feat(test_helper): add DummyTransport#clear to empty captured events
clear_sentry_events called #clear only if the transport responded to
it; DummyTransport never did, so clearing the testing transport was a
silent no-op. Add #clear that empties the captured events and envelopes
in place (keeping array references valid).
Refs #2951
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(test_helper): anchor setup/teardown to the main hub (#2951)
setup_sentry_test mutated the thread-local hub, but
Sentry.clone_hub_to_current_thread (used by
Sentry::Rack::CaptureExceptions) always clones the *main* hub. After an
intermediate clone the thread-local hub is a clone, so a later
setup_sentry_test reconfigured the clone while the main hub kept a
stale DummyTransport on its base layer. Combined with clear being a
no-op for that transport, an unrelated request's event leaked into the
next test's sentry_events (intermittent under RSpec random ordering).
- setup_sentry_test now binds the base and test clients on the main
hub and realigns the current thread's hub to it, so direct
sentry_events reads and request-time clones share one DummyTransport.
- teardown_sentry_test pops the testing layer off the main hub (where
setup pushed it) instead of the current thread's hub.
- clear_sentry_events now clears every transport reachable from the
current hub and the main hub (including its base layer) via the new
sentry_test_transports helper, so no stale DummyTransport survives.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test(test_helper): add Rack two-request leak regression spec (#2951)
Drives two consecutive requests through the real
Sentry::Rack::CaptureExceptions middleware (which calls
clone_hub_to_current_thread) wrapped in setup_sentry_test/
teardown_sentry_test, asserting the first request's event does not
leak into the second and that each request's event stays observable
via sentry_events. Fails against pre-fix code (second request sees
2 events); passes with the #2951 fix.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(test_helper): use public Hub#clients instead of @stack ivar (#2951)
Address code review feedback on the #2951 fix:
- Add a documented public Sentry::Hub#clients accessor returning all
clients across the scope stack, and use it from
TestHelper#sentry_test_transports instead of reaching into Hub's
private @stack ivar. This keeps the test helper resilient to future
Hub internals refactors. Covered by new hub_spec.rb examples.
- Replace the final inline teardown_sentry_test in the #2951 regression
and Rack consecutive-requests describe blocks with an unconditional
'after { teardown_sentry_test }' hook, matching the sibling describe
style so cleanup runs even if an expectation fails mid-example. The
intentional mid-scenario teardowns remain inline.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments