Skip to content

Commit ad2137d

Browse files
test(profiling): make memalloc test less flaky (#15769)
1 parent 6d1955c commit ad2137d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

ddtrace/profiling/collector/memalloc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,15 @@ def snapshot(self) -> None:
9494
# DEV: This can happen if either _memalloc has not been started or has been stopped.
9595
LOG.debug("Unable to collect heap events from process %d", os.getpid(), exc_info=True)
9696

97-
def snapshot_and_parse_pprof(self, output_filename: str) -> Any:
97+
def snapshot_and_parse_pprof(self, output_filename: str, assert_samples: bool = True) -> Any:
9898
"""Export samples to profile, upload, and parse the pprof profile.
9999
100100
This is similar to test_snapshot() but exports to the profile and returns
101101
the parsed pprof profile instead of Python objects.
102102
103103
Args:
104104
output_filename: The pprof output filename prefix (without .pid.counter suffix)
105+
assert_samples: Whether to assert that the profile contains samples
105106
106107
Returns:
107108
Parsed pprof profile object (pprof_pb2.Profile)
@@ -123,4 +124,4 @@ def snapshot_and_parse_pprof(self, output_filename: str) -> Any:
123124
"pprof_utils is not available. snapshot_and_parse_pprof() is only available in test environment."
124125
)
125126

126-
return pprof_utils.parse_newest_profile(output_filename)
127+
return pprof_utils.parse_newest_profile(output_filename, assert_samples=assert_samples)

tests/profiling/collector/test_memalloc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ def test_memory_collector_python_interface_with_allocation_tracking(tmp_path):
550550
tmp_path, "test_memory_collector_python_interface_with_allocation_tracking"
551551
)
552552

553-
mc = memalloc.MemoryCollector(heap_sample_size=128)
553+
mc = memalloc.MemoryCollector(heap_sample_size=32)
554554

555555
with mc:
556556
first_batch = []
@@ -623,11 +623,11 @@ def test_memory_collector_python_interface_with_allocation_tracking_no_deletion(
623623
tmp_path, "test_memory_collector_python_interface_with_allocation_tracking_no_deletion"
624624
)
625625

626-
mc = memalloc.MemoryCollector(heap_sample_size=128)
626+
mc = memalloc.MemoryCollector(heap_sample_size=32)
627627

628628
with mc:
629-
# Take initial snapshot to reset allocation tracking
630-
mc.snapshot_and_parse_pprof(output_filename)
629+
# Take initial snapshot to reset allocation tracking (may have no samples)
630+
mc.snapshot_and_parse_pprof(output_filename, assert_samples=False)
631631

632632
first_batch = []
633633
for i in range(20):

0 commit comments

Comments
 (0)