From d07b0798504f757340868d15c199aba9bd00ba5d Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Tue, 28 Jun 2022 09:13:01 -0500 Subject: [PATCH] make test_age_time less intermittent (#26280) --- runtime/src/bucket_map_holder.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/runtime/src/bucket_map_holder.rs b/runtime/src/bucket_map_holder.rs index f7e4a9c05..37d43d513 100644 --- a/runtime/src/bucket_map_holder.rs +++ b/runtime/src/bucket_map_holder.rs @@ -155,12 +155,12 @@ impl BucketMapHolder { 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]