make test_age_time less intermittent (#26280)

This commit is contained in:
Jeff Washington (jwash) 2022-06-28 09:13:01 -05:00 committed by GitHub
parent bfc390f9ed
commit d07b079850
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 4 deletions

View File

@ -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() {
@ -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]