From ee681ad42aaff006498ccbd2fd9ba07bed7b38f3 Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Wed, 6 May 2026 15:30:43 +0200 Subject: [PATCH] test: Assert presence profile chunks after session shutdown --- tests/profiler/test_continuous_profiler.py | 29 +++++++++------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/tests/profiler/test_continuous_profiler.py b/tests/profiler/test_continuous_profiler.py index cda9ab787f..3c0e9a6f6a 100644 --- a/tests/profiler/test_continuous_profiler.py +++ b/tests/profiler/test_continuous_profiler.py @@ -243,10 +243,6 @@ def assert_single_transaction_without_profile_chunks(envelopes): pytest.param(get_client_options(False), id="experiment"), ], ) -@mock.patch( - "sentry_sdk.profiler.continuous_profiler.ProfileBuffer.should_flush", - lambda a, b: True, -) # Force flushing profile of first transaction. def test_continuous_profiler_auto_start_and_manual_stop( sentry_init, capture_envelopes, @@ -270,14 +266,11 @@ def test_continuous_profiler_auto_start_and_manual_stop( with sentry_sdk.start_span(op="op"): pass - # Wait so profiles are captured before assertions. - sentry_sdk.profiler.continuous_profiler._scheduler.teardown() - - assert_single_transaction_with_profile_chunks(envelopes, thread) - for _ in range(3): stop_profiler_func() + assert_single_transaction_with_profile_chunks(envelopes, thread) + envelopes.clear() with sentry_sdk.start_transaction(name="profiling"): @@ -292,9 +285,11 @@ def test_continuous_profiler_auto_start_and_manual_stop( with sentry_sdk.start_transaction(name="profiling"): with sentry_sdk.start_span(op="op"): - time.sleep(0.05) + pass - assert_single_transaction_with_profile_chunks(envelopes, thread) + stop_profiler_func() + + assert_single_transaction_with_profile_chunks(envelopes, thread) @pytest.mark.parametrize( @@ -431,12 +426,12 @@ def test_continuous_profiler_manual_start_and_stop_unsampled( with sentry_sdk.start_transaction(name="profiling"): with sentry_sdk.start_span(op="op"): - time.sleep(0.05) - - assert_single_transaction_without_profile_chunks(envelopes) + pass stop_profiler_func() + assert_single_transaction_without_profile_chunks(envelopes) + @pytest.mark.parametrize( "mode", @@ -629,7 +624,6 @@ def test_continuous_profiler_manual_start_and_stop_noop_when_using_trace_lifecyl mock_teardown.assert_not_called() -@mock.patch("sentry_sdk.profiler.continuous_profiler.PROFILE_BUFFER_SECONDS", 0.01) def test_continuous_profiler_run_does_not_null_buffer( sentry_init, capture_envelopes, @@ -662,8 +656,7 @@ def test_continuous_profiler_run_does_not_null_buffer( envelopes.clear() with sentry_sdk.start_transaction(name="profiling"): with sentry_sdk.start_span(op="op"): - time.sleep(0.1) - assert_single_transaction_with_profile_chunks(envelopes, thread) + pass # Get the scheduler and create a sentinel buffer. # We'll call run() directly to verify it doesn't null out self.buffer. @@ -673,6 +666,8 @@ def test_continuous_profiler_run_does_not_null_buffer( # Stop the profiler so the thread exits cleanly stop_profiler() + assert_single_transaction_with_profile_chunks(envelopes, thread) + # Now set up a fresh buffer and mark the scheduler as not running # (simulating the state right after ensure_running() created a new buffer # but the old thread hasn't done cleanup yet).