Skip to content

Commit c9cdf5d

Browse files
committed
Make rate limit tests tolerant of one second timing differences
Fixes #760
1 parent f60bb41 commit c9cdf5d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/test/java/org/kohsuke/github/GHRateLimitTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.time.Duration;
1111
import java.util.Date;
1212

13-
import static org.hamcrest.CoreMatchers.*;
13+
import static org.hamcrest.Matchers.*;
1414
import static org.hamcrest.core.IsInstanceOf.instanceOf;
1515

1616
/**
@@ -163,16 +163,20 @@ private void verifyRateLimitValues(GHRateLimit previousLimit, int remaining) {
163163
}
164164

165165
private void verifyRateLimitValues(GHRateLimit previousLimit, int remaining, boolean changedResetDate) {
166-
// newer or unchange
167-
int resetComparisionValue = changedResetDate ? 1 : 0;
168-
169166
// Basic checks of values
170167
assertThat(rateLimit, notNullValue());
171168
assertThat(rateLimit.getLimit(), equalTo(previousLimit.getLimit()));
172169
assertThat(rateLimit.getRemaining(), equalTo(remaining));
173170

174171
// Check that the reset date of the current limit is not older than the previous one
175-
assertThat(rateLimit.getResetDate().compareTo(previousLimit.getResetDate()), equalTo(resetComparisionValue));
172+
long diffMillis = rateLimit.getResetDate().getTime() - previousLimit.getResetDate().getTime();
173+
174+
assertThat(diffMillis, greaterThanOrEqualTo(0L));
175+
if (changedResetDate) {
176+
assertThat(diffMillis, greaterThan(1000L));
177+
} else {
178+
assertThat(diffMillis, lessThanOrEqualTo(1000L));
179+
}
176180

177181
// Additional checks for record values
178182
assertThat(rateLimit.getCore().getLimit(), equalTo(rateLimit.getLimit()));

0 commit comments

Comments
 (0)