| 13 | ) |
| 14 | |
| 15 | func TestNotifier(t *testing.T) { |
| 16 | t.Parallel() |
| 17 | |
| 18 | now := time.Date(2022, 5, 13, 0, 0, 0, 0, time.UTC) |
| 19 | |
| 20 | testCases := []struct { |
| 21 | Name string |
| 22 | Countdown []time.Duration |
| 23 | PollInterval time.Duration |
| 24 | NTicks int |
| 25 | ConditionDeadline time.Time |
| 26 | NumConditions int |
| 27 | NumCallbacks int |
| 28 | }{ |
| 29 | { |
| 30 | Name: "zero deadline", |
| 31 | Countdown: durations(), |
| 32 | PollInterval: time.Second, |
| 33 | NTicks: 0, |
| 34 | ConditionDeadline: time.Time{}, |
| 35 | NumConditions: 1, |
| 36 | NumCallbacks: 0, |
| 37 | }, |
| 38 | { |
| 39 | Name: "no calls", |
| 40 | Countdown: durations(), |
| 41 | PollInterval: time.Second, |
| 42 | NTicks: 0, |
| 43 | ConditionDeadline: now, |
| 44 | NumConditions: 1, |
| 45 | NumCallbacks: 0, |
| 46 | }, |
| 47 | { |
| 48 | Name: "exactly one call", |
| 49 | Countdown: durations(time.Second), |
| 50 | PollInterval: time.Second, |
| 51 | NTicks: 1, |
| 52 | ConditionDeadline: now.Add(time.Second), |
| 53 | NumConditions: 2, |
| 54 | NumCallbacks: 1, |
| 55 | }, |
| 56 | { |
| 57 | Name: "two calls", |
| 58 | Countdown: durations(4*time.Second, 2*time.Second), |
| 59 | PollInterval: time.Second, |
| 60 | NTicks: 5, |
| 61 | ConditionDeadline: now.Add(5 * time.Second), |
| 62 | NumConditions: 6, |
| 63 | NumCallbacks: 2, |
| 64 | }, |
| 65 | { |
| 66 | Name: "wrong order should not matter", |
| 67 | Countdown: durations(2*time.Second, 4*time.Second), |
| 68 | PollInterval: time.Second, |
| 69 | NTicks: 5, |
| 70 | ConditionDeadline: now.Add(5 * time.Second), |
| 71 | NumConditions: 6, |
| 72 | NumCallbacks: 2, |