test: cover scheduler recurrence and timezone boundaries (#4347)

This commit is contained in:
Aniket Shukla authored and GitHub committed 2026-09-24 15:42:29 -04:00
1 parent b658c5f020
commit ecc4b1a569
3 files changed
+103

No files matched your search

@@ -204,6 +204,69 @@ class ScheduleDispatcherTest {
verify(invoker, times(2)).invoke(eq(s), any());
}
@Test
void rateWithTimezoneStillUsesElapsedHoursAcrossSpringForward() {
Schedule s = newSchedule("rate-dst", "rate(1 day)", "ENABLED");
s.setScheduleExpressionTimezone("America/Los_Angeles");
s.setCreationDate(Instant.parse("2026-03-07T10:30:00Z"));
when(schedulerService.listAllSchedules()).thenReturn(List.of(s));
dispatcher.tick(Instant.parse("2026-03-08T09:30:00Z"));
verify(invoker, never()).invoke(any(), any());
dispatcher.tick(Instant.parse("2026-03-08T10:30:00Z"));
verify(invoker).invoke(s, Instant.parse("2026-03-08T10:30:00Z"));
}
@Test
void cronWithTimezoneDispatchesAtLocalTime() {
Schedule s = newSchedule("cron-local", "cron(30 8 * * ? *)", "ENABLED");
s.setScheduleExpressionTimezone("America/Los_Angeles");
when(schedulerService.listAllSchedules()).thenReturn(List.of(s));
dispatcher.tick(Instant.parse("2026-04-21T15:29:00Z"));
verify(invoker, never()).invoke(any(), any());
dispatcher.tick(Instant.parse("2026-04-21T15:30:00Z"));
verify(invoker).invoke(s, Instant.parse("2026-04-21T15:30:00Z"));
}
@Test
void cronWithoutTimezoneDefaultsToUtc() {
Schedule s = newSchedule("cron-utc", "cron(30 10 * * ? *)", "ENABLED");
when(schedulerService.listAllSchedules()).thenReturn(List.of(s));
dispatcher.tick(Instant.parse("2026-04-21T10:29:00Z"));
verify(invoker, never()).invoke(any(), any());
dispatcher.tick(Instant.parse("2026-04-21T10:30:00Z"));
verify(invoker).invoke(s, Instant.parse("2026-04-21T10:30:00Z"));
}
@Test
void recurringScheduleRespectsInclusiveStartAndEndDates() {
Schedule s = newSchedule("bounded", "cron(0 10 * * ? *)", "ENABLED");
s.setStartDate(Instant.parse("2026-04-21T10:00:00Z"));
s.setEndDate(Instant.parse("2026-04-22T10:00:00Z"));
when(schedulerService.listAllSchedules()).thenReturn(List.of(s));
dispatcher.tick(Instant.parse("2026-04-21T09:59:59Z"));
verify(invoker, never()).invoke(any(), any());
dispatcher.tick(Instant.parse("2026-04-21T10:00:00Z"));
dispatcher.tick(Instant.parse("2026-04-22T10:00:00Z"));
dispatcher.tick(Instant.parse("2026-04-23T10:00:00Z"));
verify(invoker).invoke(s, Instant.parse("2026-04-21T10:00:00Z"));
verify(invoker).invoke(s, Instant.parse("2026-04-22T10:00:00Z"));
verify(invoker, times(2)).invoke(eq(s), any());
}
@Test
void disabledRecurringScheduleNeverDispatches() {
Schedule s = newSchedule("disabled-cron", "cron(0 10 * * ? *)", "DISABLED");
when(schedulerService.listAllSchedules()).thenReturn(List.of(s));
dispatcher.tick(Instant.parse("2026-04-21T10:00:00Z"));
dispatcher.tick(Instant.parse("2026-04-22T10:00:00Z"));
verify(invoker, never()).invoke(any(), any());
}
@Test
void unsupportedExpressionIsSkippedNotThrown() {
Schedule s = newSchedule("weird", "every 5 minutes", "ENABLED");
@@ -90,6 +90,25 @@ class SchedulerExpressionParserTest {
"10:00 UTC and 10:00 Europe/Berlin are different absolute instants");
}
@Test
void cronSkipsNonexistentLocalTimeDuringSpringForward() {
// Los Angeles advances from 01:59 to 03:00 on 2026-03-08.
assertEquals(Instant.parse("2026-03-09T09:30:00Z"),
SchedulerExpressionParser.nextCronFire("cron(30 2 * * ? *)",
Instant.parse("2026-03-08T09:00:00Z"), "America/Los_Angeles"));
}
@Test
void cronRunsOnlyOnceDuringFallBack() {
// 01:30 happens twice on 2026-11-01; AWS invokes only at its first occurrence.
String expression = "cron(30 1 * * ? *)";
Instant first = SchedulerExpressionParser.nextCronFire(expression,
Instant.parse("2026-11-01T07:00:00Z"), "America/Los_Angeles");
assertEquals(Instant.parse("2026-11-01T08:30:00Z"), first);
assertEquals(Instant.parse("2026-11-02T09:30:00Z"),
SchedulerExpressionParser.nextCronFire(expression, first, "America/Los_Angeles"));
}
@Test
void nextCronFireRejectsWrongFieldCount() {
Instant from = Instant.now();
@@ -512,6 +512,27 @@ class SchedulerServiceTest {
assertTrue(updated.getLastModificationDate().compareTo(updated.getCreationDate()) >= 0);
}
@Test
void createAndUpdatePreserveRecurringExpressionAndTimezone() {
Target target = new Target("arn:t", "arn:r", null, null);
FlexibleTimeWindow window = new FlexibleTimeWindow("OFF", null);
Schedule created = service.createSchedule(
newRequest("recurring", null, "rate(1 day)", window, target), REGION);
assertEquals("rate(1 day)", created.getScheduleExpression());
assertNull(created.getScheduleExpressionTimezone());
ScheduleRequest update = newRequest("recurring", null, "cron(30 8 * * ? *)", window, target);
update.setScheduleExpressionTimezone("America/Los_Angeles");
Schedule updated = service.updateSchedule(update, REGION);
Schedule fetched = service.getSchedule("recurring", null, REGION);
assertEquals("cron(30 8 * * ? *)", updated.getScheduleExpression());
assertEquals("America/Los_Angeles", fetched.getScheduleExpressionTimezone());
assertEquals(Instant.parse("2026-04-21T15:30:00Z"),
SchedulerExpressionParser.nextCronFire(fetched.getScheduleExpression(),
Instant.parse("2026-04-21T00:00:00Z"),
fetched.getScheduleExpressionTimezone()));
}
@Test
void updateScheduleNotFoundThrows() {
AwsException e = assertThrows(AwsException.class, () ->