okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

Aly Raffaufrefactor(gleam): clean up code and enforce focused lint checksb585313

main
1.1 KiB30 linesraw
1/// A failing account's backoff grows over hours before its caps apply, far
2/// past what an E2E poll can wait for.
3import albedo/daemon/quota.{Settings}
4import gleam/list
5import gleeunit/should
6
7fn waits(settings: quota.Settings, failures: List(Int)) -> List(Int) {
8  list.map(failures, quota.wait_seconds(settings, _, False))
9}
10
11pub fn a_healthy_account_keeps_its_cadence_test() -> Nil {
12  let settings = Settings(600, 120, True)
13  quota.wait_seconds(settings, 0, False) |> should.equal(600)
14  quota.wait_seconds(settings, 0, True) |> should.equal(120)
15}
16
17pub fn failures_double_the_wait_whether_or_not_the_account_is_busy_test() -> Nil {
18  let settings = Settings(10, 5, True)
19  waits(settings, [1, 2, 3]) |> should.equal([20, 40, 80])
20  quota.wait_seconds(settings, 1, True) |> should.equal(20)
21}
22
23pub fn the_backoff_stops_doubling_after_six_failures_test() -> Nil {
24  waits(Settings(10, 5, True), [6, 7, 50]) |> should.equal([640, 640, 640])
25}
26
27pub fn the_backoff_never_waits_past_an_hour_test() -> Nil {
28  waits(Settings(600, 120, True), [1, 2, 3, 6])
29  |> should.equal([1200, 2400, 3600, 3600])
30}