Skip to content

Commit ee681ad

Browse files
test: Assert presence profile chunks after session shutdown
1 parent bc380bf commit ee681ad

1 file changed

Lines changed: 12 additions & 17 deletions

File tree

tests/profiler/test_continuous_profiler.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,6 @@ def assert_single_transaction_without_profile_chunks(envelopes):
243243
pytest.param(get_client_options(False), id="experiment"),
244244
],
245245
)
246-
@mock.patch(
247-
"sentry_sdk.profiler.continuous_profiler.ProfileBuffer.should_flush",
248-
lambda a, b: True,
249-
) # Force flushing profile of first transaction.
250246
def test_continuous_profiler_auto_start_and_manual_stop(
251247
sentry_init,
252248
capture_envelopes,
@@ -270,14 +266,11 @@ def test_continuous_profiler_auto_start_and_manual_stop(
270266
with sentry_sdk.start_span(op="op"):
271267
pass
272268

273-
# Wait so profiles are captured before assertions.
274-
sentry_sdk.profiler.continuous_profiler._scheduler.teardown()
275-
276-
assert_single_transaction_with_profile_chunks(envelopes, thread)
277-
278269
for _ in range(3):
279270
stop_profiler_func()
280271

272+
assert_single_transaction_with_profile_chunks(envelopes, thread)
273+
281274
envelopes.clear()
282275

283276
with sentry_sdk.start_transaction(name="profiling"):
@@ -292,9 +285,11 @@ def test_continuous_profiler_auto_start_and_manual_stop(
292285

293286
with sentry_sdk.start_transaction(name="profiling"):
294287
with sentry_sdk.start_span(op="op"):
295-
time.sleep(0.05)
288+
pass
296289

297-
assert_single_transaction_with_profile_chunks(envelopes, thread)
290+
stop_profiler_func()
291+
292+
assert_single_transaction_with_profile_chunks(envelopes, thread)
298293

299294

300295
@pytest.mark.parametrize(
@@ -431,12 +426,12 @@ def test_continuous_profiler_manual_start_and_stop_unsampled(
431426

432427
with sentry_sdk.start_transaction(name="profiling"):
433428
with sentry_sdk.start_span(op="op"):
434-
time.sleep(0.05)
435-
436-
assert_single_transaction_without_profile_chunks(envelopes)
429+
pass
437430

438431
stop_profiler_func()
439432

433+
assert_single_transaction_without_profile_chunks(envelopes)
434+
440435

441436
@pytest.mark.parametrize(
442437
"mode",
@@ -629,7 +624,6 @@ def test_continuous_profiler_manual_start_and_stop_noop_when_using_trace_lifecyl
629624
mock_teardown.assert_not_called()
630625

631626

632-
@mock.patch("sentry_sdk.profiler.continuous_profiler.PROFILE_BUFFER_SECONDS", 0.01)
633627
def test_continuous_profiler_run_does_not_null_buffer(
634628
sentry_init,
635629
capture_envelopes,
@@ -662,8 +656,7 @@ def test_continuous_profiler_run_does_not_null_buffer(
662656
envelopes.clear()
663657
with sentry_sdk.start_transaction(name="profiling"):
664658
with sentry_sdk.start_span(op="op"):
665-
time.sleep(0.1)
666-
assert_single_transaction_with_profile_chunks(envelopes, thread)
659+
pass
667660

668661
# Get the scheduler and create a sentinel buffer.
669662
# 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(
673666
# Stop the profiler so the thread exits cleanly
674667
stop_profiler()
675668

669+
assert_single_transaction_with_profile_chunks(envelopes, thread)
670+
676671
# Now set up a fresh buffer and mark the scheduler as not running
677672
# (simulating the state right after ensure_running() created a new buffer
678673
# but the old thread hasn't done cleanup yet).

0 commit comments

Comments
 (0)