Light, fluffy, and always free - The AWS Local Emulator alternative
test: cover scheduler recurrence and timezone boundaries (#4347)
Aniket Shuklaecc4b1a569f1
diff --git a/src/test/java/io/github/hectorvent/floci/services/scheduler/ScheduleDispatcherTest.java b/src/test/java/io/github/hectorvent/floci/services/scheduler/ScheduleDispatcherTest.javaindex 120a43db3e..150b46b44f 100644--- a/src/test/java/io/github/hectorvent/floci/services/scheduler/ScheduleDispatcherTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/scheduler/ScheduleDispatcherTest.java@@ -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());+ }+@Testvoid unsupportedExpressionIsSkippedNotThrown() {Schedule s = newSchedule("weird", "every 5 minutes", "ENABLED");diff --git a/src/test/java/io/github/hectorvent/floci/services/scheduler/SchedulerExpressionParserTest.java b/src/test/java/io/github/hectorvent/floci/services/scheduler/SchedulerExpressionParserTest.javaindex 428cf0811d..82b140ca86 100644--- a/src/test/java/io/github/hectorvent/floci/services/scheduler/SchedulerExpressionParserTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/scheduler/SchedulerExpressionParserTest.java@@ -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"));+ }+@Testvoid nextCronFireRejectsWrongFieldCount() {Instant from = Instant.now();diff --git a/src/test/java/io/github/hectorvent/floci/services/scheduler/SchedulerServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/scheduler/SchedulerServiceTest.javaindex 482f0dde43..75e9d7820a 100644--- a/src/test/java/io/github/hectorvent/floci/services/scheduler/SchedulerServiceTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/scheduler/SchedulerServiceTest.java@@ -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()));+ }+@Testvoid updateScheduleNotFoundThrows() {AwsException e = assertThrows(AwsException.class, () ->