| index 6a0497ada..bc140119c 100644 |
| --- a/internal/console/alertengine_test.go |
| +++ b/internal/console/alertengine_test.go |
| @@ -209,14 +209,13 @@ func TestStepOneFireOneClear(t *testing.T) { |
| } |
| |
| func TestStepLateMemberUpdateHourly(t *testing.T) { |
| - // The fire at 5 starts the update clock. b2 joins inside the first 30 |
| - // minutes and b3 inside the hour after the fire: both silent. b4 at 70 |
| - // is the first update; b5 at 100 is inside that hour: silent. b6 at 131 |
| - // is the next. |
| - joins := map[string]int{"b1": 0, "b2": 10, "b3": 40, "b4": 70, "b5": 100, "b6": 131} |
| + // b2 joins inside the first 30 minutes: silent. b3 at 35 is the first |
| + // update; b4 at 50 is inside that hour: silent. b5 at 96 is the next, |
| + // and b6 at 100 is silent again. |
| + joins := map[string]int{"b1": 0, "b2": 10, "b3": 35, "b4": 50, "b5": 96, "b6": 100} |
| order := []string{"b1", "b2", "b3", "b4", "b5", "b6"} |
| sim := newStepSim(t) |
| - sim.run(0, 150, func(m int) []alertSignal { |
| + sim.run(0, 120, func(m int) []alertSignal { |
| var sigs []alertSignal |
| for _, b := range order { |
| if m >= joins[b] { |
| @@ -227,14 +226,14 @@ func TestStepLateMemberUpdateHourly(t *testing.T) { |
| }) |
| sim.emitsAre( |
| simWant{5, "fire", []string{"b1"}}, |
| - simWant{70, "update", order[:4]}, |
| - simWant{131, "update", order}, |
| + simWant{35, "update", order[:3]}, |
| + simWant{96, "update", order[:5]}, |
| ) |
| - if j := sim.emits[1].Joined; !slices.Equal(j, []string{"b4"}) { |
| - t.Fatalf("first update Joined = %v, want [b4]", j) |
| + if j := sim.emits[1].Joined; !slices.Equal(j, []string{"b3"}) { |
| + t.Fatalf("first update Joined = %v, want [b3]", j) |
| } |
| - if j := sim.emits[2].Joined; !slices.Equal(j, []string{"b6"}) { |
| - t.Fatalf("second update Joined = %v, want [b6]", j) |
| + if j := sim.emits[2].Joined; !slices.Equal(j, []string{"b5"}) { |
| + t.Fatalf("second update Joined = %v, want [b5]", j) |
| } |
| if sim.emits[0].Joined != nil { |
| t.Fatalf("fire Joined = %v, want none", sim.emits[0].Joined) |
| @@ -242,17 +241,23 @@ func TestStepLateMemberUpdateHourly(t *testing.T) { |
| } |
| |
| func TestStepUpdateAfterLateFireWaits(t *testing.T) { |
| - // A fire held back by a snooze until 25 h resets the update clock: a |
| - // member joining a minute later is folded in silently. |
| + // A fire held back by a snooze until 25 h starts its own quiet half |
| + // hour (R-19): b2 joining a minute later is folded in silently, and b3 |
| + // joining 31 minutes after the fire is the first update. |
| + const fire = 25 * 60 |
| sim := newStepSim(t) |
| - sim.snoozedUntil[diskKey("b1")] = minute(25 * 60) |
| - sim.run(0, 25*60+120, func(m int) []alertSignal { |
| - if m > 25*60 { |
| - return []alertSignal{firing("b1"), firing("b2")} |
| + sim.snoozedUntil[diskKey("b1")] = minute(fire) |
| + sim.run(0, fire+120, func(m int) []alertSignal { |
| + sigs := []alertSignal{firing("b1")} |
| + if m > fire { |
| + sigs = append(sigs, firing("b2")) |
| + } |
| + if m >= fire+31 { |
| + sigs = append(sigs, firing("b3")) |
| } |
| - return []alertSignal{firing("b1")} |
| + return sigs |
| }) |
| - sim.emitsAre(simWant{25 * 60, "fire", []string{"b1"}}) |
| + sim.emitsAre(simWant{fire, "fire", []string{"b1"}}, simWant{fire + 31, "update", []string{"b1", "b2", "b3"}}) |
| } |
| |
| func TestStepFlappingAcrossIncidents(t *testing.T) { |
| @@ -557,7 +562,8 @@ func TestStepDoesNotModifyOpen(t *testing.T) { |
| // TestStepInvariantsRandom (ruling R-18) runs 500 seeded three-day |
| // timelines over three boxes that fire, clear and go gone at random, with |
| // passes that miss a box and snoozes that come and go, and checks the |
| -// noise rules' invariants after every step. |
| +// noise rules' invariants after every step: (f) and (i) are the R-19 |
| +// update clocks. |
| func TestStepInvariantsRandom(t *testing.T) { |
| const seeds, steps = 500, 3 * 24 * 60 |
| subjects := []string{"b1", "b2", "b3"} |
| @@ -584,6 +590,10 @@ func runStepInvariants(t *testing.T, seed uint64, steps int, subjects []string) |
| lastMsg := map[int64]time.Time{} |
| lastReminder := map[int64]time.Time{} |
| lastUpdate := map[int64]time.Time{} |
| + // The R-19 clocks: the last fire or reminder, the last update or |
| + // reminder. |
| + lastFireOrReminder := map[int64]time.Time{} |
| + lastUpdateOrReminder := map[int64]time.Time{} |
| cleared := map[int64]bool{} |
| |
| for m := range steps { |
| @@ -634,6 +644,7 @@ func runStepInvariants(t *testing.T, seed uint64, steps int, subjects []string) |
| return fmt.Errorf("minute %d: fire for incident %d before NotifyAt", m, id) |
| } |
| notified[id] = true |
| + lastFireOrReminder[id] = now |
| case alertKindReminder: |
| if !notified[id] || now.Sub(lastMsg[id]) < alertReminderEvery { // (e) |
| return fmt.Errorf("minute %d: reminder for incident %d %v after its last message", m, id, now.Sub(lastMsg[id])) |
| @@ -642,6 +653,7 @@ func runStepInvariants(t *testing.T, seed uint64, steps int, subjects []string) |
| return fmt.Errorf("minute %d: reminders for incident %d %v apart", m, id, now.Sub(r)) |
| } |
| lastReminder[id] = now |
| + lastFireOrReminder[id], lastUpdateOrReminder[id] = now, now |
| case alertKindUpdate: |
| if !notified[id] { |
| return fmt.Errorf("minute %d: update for unannounced incident %d", m, id) |
| @@ -649,7 +661,14 @@ func runStepInvariants(t *testing.T, seed uint64, steps int, subjects []string) |
| if u, ok := lastUpdate[id]; ok && now.Sub(u) < alertUpdateEvery { // (f) |
| return fmt.Errorf("minute %d: updates for incident %d %v apart", m, id, now.Sub(u)) |
| } |
| + if u, ok := lastUpdateOrReminder[id]; ok && now.Sub(u) < alertUpdateEvery { // (f) |
| + return fmt.Errorf("minute %d: update for incident %d %v after its last update or reminder", m, id, now.Sub(u)) |
| + } |
| + if f, ok := lastFireOrReminder[id]; ok && now.Sub(f) < alertUpdateQuiet { // (i) |
| + return fmt.Errorf("minute %d: update for incident %d %v after its last fire or reminder", m, id, now.Sub(f)) |
| + } |
| lastUpdate[id] = now |
| + lastUpdateOrReminder[id] = now |
| case alertKindClear: |
| clears[id]++ |
| } |