Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions tests/profiler/test_continuous_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@
assert "profile" not in transaction["contexts"]


@pytest.mark.forked
@pytest.mark.parametrize(
"mode",
[
Expand Down Expand Up @@ -243,7 +242,10 @@
pytest.param(get_client_options(False), id="experiment"),
],
)
@mock.patch("sentry_sdk.profiler.continuous_profiler.PROFILE_BUFFER_SECONDS", 0.01)
@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,
Expand All @@ -264,8 +266,12 @@
thread = threading.current_thread()

with sentry_sdk.start_transaction(name="profiling"):
with sentry_sdk.start_span(op="op"):
time.sleep(0.05)
pass

# Wait so profiles are captured before assertions.
sentry_sdk.profiler.continuous_profiler._scheduler.running = False
sentry_sdk.profiler.continuous_profiler._scheduler.thread.join()

Check warning on line 274 in tests/profiler/test_continuous_profiler.py

View check run for this annotation

@sentry/warden / warden: find-bugs

Test may fail due to race condition: no time for profiler to capture samples

The test removes `time.sleep(0.05)` inside the span and replaces it with `pass`. The profiler thread samples at intervals (`self.interval = 1.0 / frequency`). Without any delay, the profiler thread may not execute its sampling loop before `_scheduler.running = False` is set, resulting in zero profile chunks being captured. The assertion `assert len(items["profile_chunk"]) > 0` would then fail.
Comment thread
alexander-alderman-webb marked this conversation as resolved.
Outdated

assert_single_transaction_with_profile_chunks(envelopes, thread)

Expand Down
Loading