Skip to content

Commit fd30b14

Browse files
fix(tests): Fix flaky continuous profiler test under gevent
The `assert_single_transaction_with_profile_chunks` helper now polls for profile_chunk envelope items with a timeout instead of asserting immediately. Under gevent on slow CI runners, the profiler thread may not have flushed its buffer by the time the assertion runs, causing sporadic failures. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent de650c8 commit fd30b14

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

tests/profiler/test_continuous_profiler.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,28 @@ def test_continuous_profiler_setup_twice(mode, make_options, teardown_profiling)
135135
assert not is_profile_session_sampled()
136136

137137

138-
def assert_single_transaction_with_profile_chunks(
139-
envelopes, thread, max_chunks=None, transactions=1
140-
):
138+
def _collect_envelope_items(envelopes):
141139
items = defaultdict(list)
142140
for envelope in envelopes:
143141
for item in envelope.items:
144142
items[item.type].append(item)
143+
return items
144+
145+
146+
def assert_single_transaction_with_profile_chunks(
147+
envelopes, thread, max_chunks=None, transactions=1, timeout=2.0
148+
):
149+
# Poll for profile_chunk items to arrive, since the profiler thread
150+
# may not have flushed yet when this assertion runs (especially under
151+
# gevent on slow CI runners).
152+
deadline = time.monotonic() + timeout
153+
while True:
154+
items = _collect_envelope_items(envelopes)
155+
if len(items["profile_chunk"]) > 0:
156+
break
157+
if time.monotonic() >= deadline:
158+
break
159+
time.sleep(0.01)
145160

146161
assert len(items["transaction"]) == transactions
147162
assert len(items["profile_chunk"]) > 0

0 commit comments

Comments
 (0)