Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(profiling): Reduce continuous profiling test flakiness #4052

Merged
Merged
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
32 changes: 21 additions & 11 deletions tests/profiler/test_continuous_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_continuous_profiler_setup_twice(mode, make_options, teardown_profiling)


def assert_single_transaction_with_profile_chunks(
envelopes, thread, max_chunks, transactions=1
envelopes, thread, max_chunks=None, transactions=1
):
items = defaultdict(list)
for envelope in envelopes:
Expand All @@ -136,7 +136,8 @@ def assert_single_transaction_with_profile_chunks(

assert len(items["transaction"]) == transactions
assert len(items["profile_chunk"]) > 0
assert len(items["profile_chunk"]) <= max_chunks
if max_chunks is not None:
assert len(items["profile_chunk"]) <= max_chunks

transaction = items["transaction"][0].payload.json

Expand Down Expand Up @@ -235,7 +236,7 @@ def test_continuous_profiler_auto_start_and_manual_stop(
with sentry_sdk.start_span(op="op"):
time.sleep(0.05)

assert_single_transaction_with_profile_chunks(envelopes, thread, max_chunks=10)
assert_single_transaction_with_profile_chunks(envelopes, thread)

for _ in range(3):
stop_profiler()
Expand All @@ -256,7 +257,7 @@ def test_continuous_profiler_auto_start_and_manual_stop(
with sentry_sdk.start_span(op="op"):
time.sleep(0.05)

assert_single_transaction_with_profile_chunks(envelopes, thread, max_chunks=10)
assert_single_transaction_with_profile_chunks(envelopes, thread)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -299,18 +300,27 @@ def test_continuous_profiler_manual_start_and_stop_sampled(
envelopes.clear()

with sentry_sdk.start_transaction(name="profiling"):
assert get_profiler_id() is not None, "profiler should be running"
with sentry_sdk.start_span(op="op"):
time.sleep(0.05)
time.sleep(0.1)
assert get_profiler_id() is not None, "profiler should be running"

assert_single_transaction_with_profile_chunks(envelopes, thread, max_chunks=10)
assert_single_transaction_with_profile_chunks(envelopes, thread)

assert get_profiler_id() is not None, "profiler should be running"

stop_profiler()

# the profiler stops immediately in manual mode
assert get_profiler_id() is None, "profiler should not be running"

envelopes.clear()

with sentry_sdk.start_transaction(name="profiling"):
assert get_profiler_id() is None, "profiler should not be running"
with sentry_sdk.start_span(op="op"):
time.sleep(0.05)
time.sleep(0.1)
assert get_profiler_id() is None, "profiler should not be running"

assert_single_transaction_without_profile_chunks(envelopes)

Expand Down Expand Up @@ -397,17 +407,17 @@ def test_continuous_profiler_auto_start_and_stop_sampled(
with sentry_sdk.start_transaction(name="profiling 1"):
assert get_profiler_id() is not None, "profiler should be running"
with sentry_sdk.start_span(op="op"):
time.sleep(0.03)
time.sleep(0.1)
assert get_profiler_id() is not None, "profiler should be running"

# the profiler takes a while to stop so if we start a transaction
# immediately, it'll be part of the same chunk
# the profiler takes a while to stop in auto mode so if we start
# a transaction immediately, it'll be part of the same chunk
assert get_profiler_id() is not None, "profiler should be running"

with sentry_sdk.start_transaction(name="profiling 2"):
assert get_profiler_id() is not None, "profiler should be running"
with sentry_sdk.start_span(op="op"):
time.sleep(0.03)
time.sleep(0.1)
assert get_profiler_id() is not None, "profiler should be running"

# wait at least 1 cycle for the profiler to stop
Expand Down
Loading