Skip to content

Commit

Permalink
make test_age_time less intermittent (#26280)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored Jun 28, 2022
1 parent bfc390f commit d07b079
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions runtime/src/bucket_map_holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ impl<T: IndexValue> BucketMapHolder<T> {
self.count_buckets_flushed.load(Ordering::Acquire)
}

/// if all buckets are flushed at the current age and time has elapsed, then advanced age
/// if all buckets are flushed at the current age and time has elapsed, then advance age
pub fn maybe_advance_age(&self) -> bool {
self.maybe_advance_age_internal(self.all_buckets_flushed_at_current_age())
}

/// if all buckets are flushed at the current age and time has elapsed, then advanced age
/// if all buckets are flushed at the current age and time has elapsed, then advance age
fn maybe_advance_age_internal(&self, all_buckets_flushed_at_current_age: bool) -> bool {
// call has_age_interval_elapsed last since calling it modifies state on success
if all_buckets_flushed_at_current_age && self.has_age_interval_elapsed() {
Expand Down Expand Up @@ -468,13 +468,24 @@ pub mod tests {
let now = Instant::now();
test.bucket_flushed_at_current_age(true); // done with age 0
(0..threads).into_par_iter().for_each(|_| {
while now.elapsed().as_millis() < (time as u128) {
// This test used to be more strict with time, but in a parallel, multi test environment,
// sometimes threads starve and this test intermittently fails. So, give it 10x the necesary time it should require.
while now.elapsed().as_millis() < (time as u128) * 10 {
if test.maybe_advance_age() {
test.bucket_flushed_at_current_age(true);
}

if test.current_age() >= expected {
break;
}
}
});
assert_eq!(test.current_age(), expected);
assert!(
test.current_age() >= expected,
"{}, {}",
test.current_age(),
expected
);
}

#[test]
Expand Down

0 comments on commit d07b079

Please sign in to comment.