aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-alm-client
diff options
context:
space:
mode:
authorAurelien Poscia <aurelien.poscia@sonarsource.com>2023-09-12 11:34:46 +0200
committersonartech <sonartech@sonarsource.com>2023-09-12 20:02:41 +0000
commita87e7b2da9f5a38eb68cbf119ba368306c367a58 (patch)
treec93540850bc1321580b52309a32a0a67fc823491 /server/sonar-alm-client
parent6d021927d626cbe78bb2ee17bb2cc40ac5e6ee02 (diff)
downloadsonarqube-a87e7b2da9f5a38eb68cbf119ba368306c367a58.tar.gz
sonarqube-a87e7b2da9f5a38eb68cbf119ba368306c367a58.zip
SONAR-20451 Fix flakyness of RatioBasedRateLimitCheckerTest.checkRateLimit
Diffstat (limited to 'server/sonar-alm-client')
-rw-r--r--server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/RatioBasedRateLimitCheckerTest.java11
1 files changed, 6 insertions, 5 deletions
diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/RatioBasedRateLimitCheckerTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/RatioBasedRateLimitCheckerTest.java
index 407e9056144..83913b19cb4 100644
--- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/RatioBasedRateLimitCheckerTest.java
+++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/RatioBasedRateLimitCheckerTest.java
@@ -23,18 +23,18 @@ import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.sql.Date;
-import java.time.Instant;
import java.time.temporal.ChronoUnit;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kohsuke.github.GHRateLimit;
-import org.mockito.Mockito;
import org.slf4j.event.Level;
import org.sonar.api.testfixtures.log.LogTester;
import static java.lang.String.format;
+import static java.time.Instant.now;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.alm.client.github.RatioBasedRateLimitChecker.RATE_RATIO_EXCEEDED_MESSAGE;
@@ -63,18 +63,19 @@ public class RatioBasedRateLimitCheckerTest {
@Test
@UseDataProvider("rates")
public void checkRateLimit(int limit, int remaining, boolean rateLimitShouldBeExceeded) throws InterruptedException {
- GHRateLimit.Record record = Mockito.mock(GHRateLimit.Record.class);
+ GHRateLimit.Record record = mock();
when(record.getLimit()).thenReturn(limit);
when(record.getRemaining()).thenReturn(remaining);
- when(record.getResetDate()).thenReturn(Date.from(Instant.now().plus(100, ChronoUnit.MILLIS)));
+ when(record.getResetDate()).thenReturn(Date.from(now().plus(100, ChronoUnit.MILLIS)));
long start = System.currentTimeMillis();
boolean result = ratioBasedRateLimitChecker.checkRateLimit(record, 10);
long stop = System.currentTimeMillis();
long totalTime = stop - start;
+
if (rateLimitShouldBeExceeded) {
assertThat(result).isTrue();
- assertThat(totalTime).isGreaterThanOrEqualTo(MILLIS_BEFORE_RESET - 10);
+ assertThat(stop).isGreaterThanOrEqualTo(record.getResetDate().getTime());
assertThat(logTester.logs(Level.WARN)).contains(
format(RATE_RATIO_EXCEEDED_MESSAGE.replaceAll("\\{\\}", "%s"), limit - remaining, limit));
} else {