Skip to content

Commit 8e54169

Browse files
test(profiler): Wait for automatic shutdown (#7364)
The automatic profiler lifecycle shuts down asynchronously after inactive profiles are observed by the sampler. Replace the fixed 200 ms sleeps with a bounded wait for both shutdown and the resulting profile chunk, so loaded CI workers cannot race the assertion. <!-- junior-request-attribution:start --> Requested by **neel**. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC09M26BC6A1%3A1788434448.544309 --> -- [View Junior Session](https://junior-prod.sentry.dev/conversations/slack%3AC09M26BC6A1%3A1788434448.544309) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC09M26BC6A1%3A1788434448.544309/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Neel Shah <6536764+sl0thentr0py@users.noreply.github.com>
1 parent ca4d380 commit 8e54169

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

‎tests/profiler/test_continuous_profiler.py‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@
2727
requires_gevent = pytest.mark.skipif(gevent is None, reason="gevent not enabled")
2828

2929

30+
def wait_for_profiler_to_stop(envelopes, timeout=1.0):
31+
deadline = time.monotonic() + timeout
32+
while time.monotonic() < deadline:
33+
profiler_stopped = get_profiler_id() is None
34+
profile_flushed = any(
35+
item.type == "profile_chunk"
36+
for envelope in envelopes
37+
for item in envelope.items
38+
)
39+
if profiler_stopped and profile_flushed:
40+
return
41+
time.sleep(0.01)
42+
43+
assert get_profiler_id() is None, "profiler should not be running"
44+
assert any(
45+
item.type == "profile_chunk"
46+
for envelope in envelopes
47+
for item in envelope.items
48+
), "profiler should have flushed a profile chunk"
49+
50+
3051
def get_client_options(use_top_level_profiler_mode):
3152
def client_options(
3253
mode=None, auto_start=None, profile_session_sample_rate=1.0, lifecycle="manual"
@@ -807,9 +828,7 @@ def test_continuous_profiler_auto_start_and_stop_sampled(
807828
assert profiler_id is not None, "profiler should be running"
808829
profiler_ids.add(profiler_id)
809830

810-
# wait at least 1 cycle for the profiler to stop
811-
time.sleep(0.2)
812-
assert get_profiler_id() is None, "profiler should not be running"
831+
wait_for_profiler_to_stop(envelopes)
813832

814833
assert len(profiler_ids) == 1
815834
all_profiler_ids.add(profiler_ids.pop())
@@ -891,9 +910,7 @@ def test_continuous_profiler_auto_start_and_stop_sampled_span_streaming(
891910
assert profiler_id is not None, "profiler should be running"
892911
profiler_ids.add(profiler_id)
893912

894-
# wait at least 1 cycle for the profiler to stop
895-
time.sleep(0.2)
896-
assert get_profiler_id() is None, "profiler should not be running"
913+
wait_for_profiler_to_stop(envelopes)
897914

898915
assert len(profiler_ids) == 1
899916
all_profiler_ids.add(profiler_ids.pop())

0 commit comments

Comments
 (0)