Merge "Fix a bug where error count was reset before returning it." into tm-dev am: 1b81993295 am: 716a1dd70b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17982495

Change-Id: Ie7d1ee02a6737e67b34cb40ae2e50790f95377fc
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Siim Sammul
2022-04-29 18:34:42 +00:00
committed by Automerger Merge Worker
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 {