Skip to content

Commit

Permalink
channel tests: don't reset allocated bytes counter
Browse files Browse the repository at this point in the history
The ALLOCATED atomic is used by the golang::select2 test
to track the total size of the current heap allocations.
It is reset to 0 during the test, which can cause underflow
if existing allocations are deallocated afterwards.
The golang test this is copied from doesn't reset the alloc stats,
and it doesn't affect the test result, since only the difference
in bytes allocated is asserted.
So don't reset the ALLOCATED counter during the test.

Also only sample ALLOCATED once at the end of the test,
to avoid its value being inconsistent between the 2 loads.
  • Loading branch information
calebsander authored and taiki-e committed Jan 16, 2024
1 parent bd87a61 commit 3ce467f
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions crossbeam-channel/tests/golang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,6 @@ mod select2 {
let c = make_unbounded::<i32>();
let dummy = make_unbounded::<i32>();

ALLOCATED.store(0, SeqCst);

go!(c, sender(&c, N));
receiver(&c, &dummy, N);

Expand All @@ -764,10 +762,9 @@ mod select2 {
go!(c, sender(&c, N));
receiver(&c, &dummy, N);

assert!(
!(ALLOCATED.load(SeqCst) > alloc
&& (ALLOCATED.load(SeqCst) - alloc) > (N as usize + 10000))
);
let final_alloc = ALLOCATED.load(SeqCst);

assert!(!(final_alloc > alloc && final_alloc - alloc > N as usize + 10000));
}
}

Expand Down

0 comments on commit 3ce467f

Please sign in to comment.