Alerts: a delivery no channel took leaves the cooldown unspent
This commit is contained in:
@@ -60,6 +60,7 @@ def manager(clock: Clock) -> tuple[AlertManager, list[Alert]]:
|
||||
|
||||
async def capture(channel, alert):
|
||||
sent.append(alert)
|
||||
return True
|
||||
|
||||
alerts.send = capture # type: ignore[method-assign]
|
||||
return alerts, sent
|
||||
@@ -264,6 +265,27 @@ def test_a_ledger_that_fails_does_not_stop_the_alert():
|
||||
assert len(sent) == 1
|
||||
|
||||
|
||||
def test_an_alert_no_channel_took_does_not_spend_its_cooldown():
|
||||
clock = Clock()
|
||||
alerts, sent = manager(clock)
|
||||
delivered = iter([False, True])
|
||||
|
||||
async def flaky(channel, alert):
|
||||
sent.append(alert)
|
||||
return next(delivered)
|
||||
|
||||
alerts.send = flaky # type: ignore[method-assign]
|
||||
|
||||
async def scenario():
|
||||
await alerts.handle(error_event())
|
||||
clock.advance(10)
|
||||
await alerts.handle(error_event())
|
||||
|
||||
asyncio.run(scenario())
|
||||
|
||||
assert len(sent) == 2
|
||||
|
||||
|
||||
def test_an_alert_held_back_by_the_ceiling_does_not_spend_its_cooldown():
|
||||
clock = Clock()
|
||||
alerts, sent = manager(clock)
|
||||
|
||||
@@ -141,8 +141,9 @@ def test_a_device_away_after_a_restart_alerts_nobody(tmp_path: Path) -> None:
|
||||
),
|
||||
)
|
||||
|
||||
async def capture(channel: Channel, alert: Alert) -> None:
|
||||
async def capture(channel: Channel, alert: Alert) -> bool:
|
||||
sent.append(alert)
|
||||
return True
|
||||
|
||||
alerts.send = capture # type: ignore[method-assign]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user