Skip to content

Commit 55cdccf

Browse files
authored
test(profiling): make sure we have sample before terminating process (#4175)
The current multiprocessing test wants to have at least one sample in the generated pprof file. However, there's a tiny chance we don't have any event by the time the profiler is stopped, which makes the test flaky.
1 parent 4ba44c4 commit 55cdccf

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tests/profiling/_test_multiprocessing.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55

66

77
def f():
8-
time.sleep(1)
8+
import ddtrace.profiling.bootstrap
9+
10+
profiler = ddtrace.profiling.bootstrap.profiler
11+
for _ in range(50):
12+
if any(map(len, profiler._recorder.events.values())):
13+
break
14+
time.sleep(0.1)
15+
# Manually stop the profiler: atexit hooks are not called in subprocesses launched by multiprocessing and we want to
16+
# be sure the profile are flushed out
17+
profiler.stop()
918

1019

1120
if __name__ == "__main__":

0 commit comments

Comments
 (0)