Skip to content

Commit 4c0b283

Browse files
test: Join thread in continuous profiler test (#6125)
Flush the profiler's buffer after the first profile is collected, and suspend execution of the main thread until the flush completes before evaluating assertions.
1 parent 6abe578 commit 4c0b283

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

tests/profiler/test_continuous_profiler.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,10 @@ def assert_single_transaction_without_profile_chunks(envelopes):
243243
pytest.param(get_client_options(False), id="experiment"),
244244
],
245245
)
246-
@mock.patch("sentry_sdk.profiler.continuous_profiler.PROFILE_BUFFER_SECONDS", 0.01)
246+
@mock.patch(
247+
"sentry_sdk.profiler.continuous_profiler.ProfileBuffer.should_flush",
248+
lambda a, b: True,
249+
) # Force flushing profile of first transaction.
247250
def test_continuous_profiler_auto_start_and_manual_stop(
248251
sentry_init,
249252
capture_envelopes,
@@ -265,7 +268,10 @@ def test_continuous_profiler_auto_start_and_manual_stop(
265268

266269
with sentry_sdk.start_transaction(name="profiling"):
267270
with sentry_sdk.start_span(op="op"):
268-
time.sleep(0.05)
271+
pass
272+
273+
# Wait so profiles are captured before assertions.
274+
sentry_sdk.profiler.continuous_profiler._scheduler.teardown()
269275

270276
assert_single_transaction_with_profile_chunks(envelopes, thread)
271277

0 commit comments

Comments
 (0)