Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fbe145bc authored by Siim Sammul's avatar Siim Sammul Committed by Automerger Merge Worker
Browse files

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

parents 9190766f 1b819932
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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();
+10 −0
Original line number Diff line number Diff line
@@ -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 {