Merge "Fix a bug where error count was reset before returning it." into tm-dev

This commit is contained in:
Siim Sammul
2022-04-29 08:09:45 +00:00
committed by Android (Google) Code Review
2 changed files with 12 additions and 1 deletions

View File

@@ -64,9 +64,10 @@ public class DropboxRateLimiter {
}
if (now - errRecord.getStartTime() > RATE_LIMIT_BUFFER_DURATION) {
final int errCount = recentlyDroppedCount(errRecord);
errRecord.setStartTime(now);
errRecord.setCount(1);
return new RateLimitResult(false, recentlyDroppedCount(errRecord));
return new RateLimitResult(false, errCount);
}
errRecord.incrementCount();

View File

@@ -90,6 +90,16 @@ public class DropboxRateLimiterTest {
mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated());
assertEquals(2,
mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated());
// After 11 seconds the rate limiting buffer will be cleared and rate limiting will stop.
mClock.setOffsetMillis(11000);
// The first call after rate limiting stops will still return the number of dropped events.
assertEquals(2,
mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated());
// The next call should show that the dropped event counter was reset.
assertEquals(0,
mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated());
}
private static class TestClock implements DropboxRateLimiter.Clock {