Skip to content
Open
Changes from all commits
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
29 changes: 12 additions & 17 deletions tests/profiler/test_continuous_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"):
Expand All @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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).
Expand Down
Loading