fix: ring a snooze that is delivered late
A snooze stays pending for the ring window after it comes due, but the fire was rejected after the two-minute grace and re-registered at the same past instant, so the alarm looped on wakeups and never rang after a reboot or a late delivery.
This commit is contained in:
1 parent
d48c2e68fa
commit
4d29669222
2 files changed
+41
-3
No files matched your search
@@ -363,6 +363,40 @@ class AlarmEngineTest {
|
||||
assertThat(states.state(1L).snoozeCount).isEqualTo(1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a snooze delivered late after a reboot still rings`(@TempDir dir: Path) = runTest {
|
||||
givenAlarm(repeatDays = RepeatDays.EVERY_DAY)
|
||||
val snoozeAt = sevenToday + 9.minutes
|
||||
states.save(
|
||||
ringState(snoozedUntil = snoozeAt, snoozeCount = 1, handledOccurrence = sevenToday),
|
||||
)
|
||||
wallClock.instant = snoozeAt + 4.minutes
|
||||
val engine = engine(dir)
|
||||
|
||||
val outcome = engine.onFire(alarmId = 1L, scheduledFor = snoozeAt)
|
||||
|
||||
assertThat(outcome).isEqualTo(FireOutcome.Ringing(1L))
|
||||
assertThat(states.state(1L).snoozeCount).isEqualTo(1)
|
||||
assertThat(scheduler.next?.fireAt).isEqualTo(sevenTomorrow)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a snooze delivered after its ring window is ignored`(@TempDir dir: Path) = runTest {
|
||||
givenAlarm(repeatDays = RepeatDays.EVERY_DAY)
|
||||
val snoozeAt = sevenToday + 9.minutes
|
||||
states.save(
|
||||
ringState(snoozedUntil = snoozeAt, snoozeCount = 1, handledOccurrence = sevenToday),
|
||||
)
|
||||
wallClock.instant = snoozeAt + 11.minutes
|
||||
val engine = engine(dir)
|
||||
|
||||
val outcome = engine.onFire(alarmId = 1L, scheduledFor = snoozeAt)
|
||||
|
||||
assertThat(outcome).isEqualTo(FireOutcome.Ignored)
|
||||
assertThat(ring.events).isEmpty()
|
||||
assertThat(scheduler.next?.fireAt).isEqualTo(sevenTomorrow)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the ringing alarm never takes the next-alarm slot from another one`(@TempDir dir: Path) = runTest {
|
||||
givenAlarm(id = 1L, hour = 7, repeatDays = RepeatDays.EVERY_DAY)
|
||||
|
||||
Reference in new issue
Block a user