Skip to content

Commit

Permalink
Fix flaky test in AdaptiveSchedulerTest.testSchedule,fix #1076
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Nioche <[email protected]>
  • Loading branch information
jnioche committed Dec 6, 2023
1 parent 5740f42 commit c3ae8c7
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
Expand Down Expand Up @@ -84,7 +85,7 @@ public void testSchedule() throws MalformedURLException {
Metadata metadata = new Metadata();
metadata.addValue("fetch.statusCode", "200");
metadata.addValue(AdaptiveScheduler.SIGNATURE_KEY, md5sumEmptyContent);
Optional<Date> nextFetch = scheduler.schedule(Status.FETCHED, metadata);
scheduler.schedule(Status.FETCHED, metadata);
Instant firstFetch =
DateUtils.round(Calendar.getInstance().getTime(), Calendar.SECOND).toInstant();

Expand All @@ -98,15 +99,15 @@ public void testSchedule() throws MalformedURLException {
lastModified, ZonedDateTime::from)),
Calendar.SECOND)
.toInstant();
Assert.assertEquals(firstFetch, lastModifiedTime);
Assert.assertTrue(firstFetch.until(lastModifiedTime, ChronoUnit.SECONDS) <= 1);
String fetchInterval = metadata.getFirstValue(AdaptiveScheduler.FETCH_INTERVAL_KEY);
Assert.assertNotNull(fetchInterval);
/* initial interval is the default interval */
Assert.assertEquals(5, Integer.parseInt(fetchInterval));

/* test with signature not modified */
metadata.addValue(AdaptiveScheduler.SIGNATURE_OLD_KEY, md5sumEmptyContent);
nextFetch = scheduler.schedule(Status.FETCHED, metadata);
scheduler.schedule(Status.FETCHED, metadata);
fetchInterval = metadata.getFirstValue(AdaptiveScheduler.FETCH_INTERVAL_KEY);
Assert.assertNotNull(fetchInterval);
/* interval should be bigger than initial interval */
Expand All @@ -117,7 +118,7 @@ public void testSchedule() throws MalformedURLException {

/* test with HTTP 304 "not modified" */
metadata.setValue("fetch.statusCode", "304");
nextFetch = scheduler.schedule(Status.FETCHED, metadata);
scheduler.schedule(Status.FETCHED, metadata);
fetchInterval = metadata.getFirstValue(AdaptiveScheduler.FETCH_INTERVAL_KEY);
Assert.assertNotNull(fetchInterval);
/* interval should be bigger than initial interval and interval from last step */
Expand All @@ -130,7 +131,7 @@ public void testSchedule() throws MalformedURLException {
/* test with a changed signature */
metadata.setValue("fetch.statusCode", "200");
metadata.addValue(AdaptiveScheduler.SIGNATURE_KEY, md5sumSpaceContent);
nextFetch = scheduler.schedule(Status.FETCHED, metadata);
scheduler.schedule(Status.FETCHED, metadata);
Instant lastFetch =
DateUtils.round(Calendar.getInstance().getTime(), Calendar.SECOND).toInstant();
fetchInterval = metadata.getFirstValue(AdaptiveScheduler.FETCH_INTERVAL_KEY);
Expand All @@ -148,6 +149,6 @@ public void testSchedule() throws MalformedURLException {
lastModified, ZonedDateTime::from)),
Calendar.SECOND)
.toInstant();
Assert.assertEquals(lastFetch, lastModifiedTime);
Assert.assertTrue(lastFetch.until(lastModifiedTime, ChronoUnit.SECONDS) <= 1);
}
}

0 comments on commit c3ae8c7

Please sign in to comment.