@@ -76,7 +76,8 @@ TEST_F(RateLimiterTest, BasicTokenAcquisition) {
7676 ASSERT_EQ (rateLimiter.stats ().rejectedAdmissions .get (), 0 );
7777 // Immediate acquisition (without throttling, i.e. no sleep) still counts as a queue time of
7878 // zero, so the average timing metric will have that as its first value.
79- ASSERT_EQ (rateLimiter.stats ().averageTimeQueuedMicros .get (), 0.0 );
79+ ASSERT (rateLimiter.stats ().averageTimeQueuedMicros .get ().has_value ());
80+ ASSERT_APPROX_EQUAL (*rateLimiter.stats ().averageTimeQueuedMicros .get (), 0.0 , 0.1 );
8081}
8182
8283// Verify that RateLimiter::setBurstSize range checks its input.
@@ -202,9 +203,10 @@ TEST_F(RateLimiterTest, RejectOverMaxWaiters) {
202203 (status2.code () == ErrorCodes::TemporarilyUnavailable));
203204 ASSERT_EQ (rateLimiter.stats ().rejectedAdmissions .get (), 1 );
204205
205- // Assert that the token balance is between 0 and -1, as only one token should have been
206- // borrowed from the bucket.
207- ASSERT_LT (rateLimiter.tokenBalance (), 0 );
206+ // Assert that the token balance is between ~0 and -1, as only one token should have been
207+ // borrowed from the bucket. The bucket may have refilled slightly past 0 on slow machines,
208+ // and so we account for that in the assertion.
209+ ASSERT_LT (rateLimiter.tokenBalance (), 0.2 );
208210 ASSERT_GT (rateLimiter.tokenBalance (), -1 );
209211
210212 // Interrupt the other token acquisition.
@@ -428,7 +430,8 @@ TEST_F(RateLimiterWithMockClockTest, ConcurrentTokenAcquisitionWithQueueing) {
428430 ASSERT_EQ (rateLimiter.stats ().successfulAdmissions .get (), maxTokens);
429431 ASSERT_EQ (rateLimiter.stats ().removedFromQueue .get (), 0 );
430432 ASSERT_EQ (rateLimiter.stats ().rejectedAdmissions .get (), 0 );
431- ASSERT_EQ (rateLimiter.stats ().averageTimeQueuedMicros .get (), 0.0 );
433+ ASSERT (rateLimiter.stats ().averageTimeQueuedMicros .get ().has_value ());
434+ ASSERT_APPROX_EQUAL (*rateLimiter.stats ().averageTimeQueuedMicros .get (), 0.0 , .1 );
432435
433436 // Make sure we've enqueued all the remaining waiters so that we don't race with advancing
434437 // the mock clock.
@@ -449,7 +452,8 @@ TEST_F(RateLimiterWithMockClockTest, ConcurrentTokenAcquisitionWithQueueing) {
449452 ASSERT_EQ (rateLimiter.stats ().addedToQueue .get (), numThreads - maxTokens);
450453 ASSERT_EQ (rateLimiter.stats ().removedFromQueue .get (), 0 );
451454 ASSERT_EQ (rateLimiter.stats ().rejectedAdmissions .get (), 0 );
452- ASSERT_EQ (rateLimiter.stats ().averageTimeQueuedMicros .get (), 0.0 );
455+ ASSERT (rateLimiter.stats ().averageTimeQueuedMicros .get ().has_value ());
456+ ASSERT_APPROX_EQUAL (*rateLimiter.stats ().averageTimeQueuedMicros .get (), 0.0 , .1 );
453457
454458 // Advancing time less than tokenInterval doesn't cause a token to be acquired.
455459 auto smallAdvance = Milliseconds{10 };
0 commit comments