Skip to content

Commit

Permalink
tests: Fix a flaky test
Browse files Browse the repository at this point in the history
This test was treating every `free()` for the same address as though it
was freeing a block of memory we care about, instead of only the first
`free()` for that address after it was allocated.

Fix this by only paying attention to the first free found for an address
after it was allocated by an allocator we're interested in.

Authored-by: Matt Wozniski <mwozniski@bloomberg.net>
Reviewed-by: Pablo Galindo <pgalindo3@bloomberg.net>
Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
  • Loading branch information
godlygeek authored and GitHub Enterprise committed Apr 7, 2022
1 parent 0513460 commit b8a2f71
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions tests/integration/test_native_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,18 @@ def test_multithreaded_extension_with_native_tracking(tmpdir, monkeypatch):

# THEN
records = list(FileReader(output).get_allocation_records())
memaligns = [
record for record in records if record.allocator == AllocatorType.MEMALIGN
]
memaligns = []
memalign_frees = []
outstanding_memaligns = set()

for record in records:
if record.allocator == AllocatorType.MEMALIGN:
memaligns.append(record)
outstanding_memaligns.add(record.address)
elif record.allocator == AllocatorType.FREE:
if record.address in outstanding_memaligns:
outstanding_memaligns.remove(record.address)
memalign_frees.append(record)

assert len(memaligns) == 100 * 100 # 100 threads allocate 100 times in testext
assert all(len(memalign.stack_trace()) == 0 for memalign in memaligns)
Expand All @@ -53,14 +62,7 @@ def test_multithreaded_extension_with_native_tracking(tmpdir, monkeypatch):
for record in memaligns
)

memaligns_addr = {record.address for record in memaligns}
memalign_frees = [
record
for record in records
if record.address in memaligns_addr and record.allocator == AllocatorType.FREE
]

assert len(memalign_frees) >= 100 * 100
assert len(memalign_frees) == 100 * 100
assert all(len(memalign.stack_trace()) == 0 for memalign in memalign_frees)
assert all(len(record.native_stack_trace()) == 0 for record in memalign_frees)

Expand Down

0 comments on commit b8a2f71

Please sign in to comment.