@@ -27,43 +27,51 @@ func TestNotifier(t *testing.T) {
27
27
{
28
28
Name : "zero deadline" ,
29
29
Countdown : durations (),
30
- Ticks : ticks (now , 0 ),
30
+ Ticks : fakeTicker (now , time . Second , 0 ),
31
31
ConditionDeadline : time.Time {},
32
32
NumConditions : 1 ,
33
33
NumCallbacks : 0 ,
34
34
},
35
35
{
36
36
Name : "no calls" ,
37
37
Countdown : durations (),
38
- Ticks : ticks (now , 0 ),
38
+ Ticks : fakeTicker (now , time . Second , 0 ),
39
39
ConditionDeadline : now ,
40
40
NumConditions : 1 ,
41
41
NumCallbacks : 0 ,
42
42
},
43
43
{
44
44
Name : "exactly one call" ,
45
45
Countdown : durations (time .Second ),
46
- Ticks : ticks (now , 2 ),
47
- ConditionDeadline : now .Add (2 * time .Second ),
46
+ Ticks : fakeTicker (now , time . Second , 1 ),
47
+ ConditionDeadline : now .Add (time .Second ),
48
48
NumConditions : 2 ,
49
49
NumCallbacks : 1 ,
50
50
},
51
51
{
52
52
Name : "two calls" ,
53
53
Countdown : durations (4 * time .Second , 2 * time .Second ),
54
- Ticks : ticks (now , 5 ),
54
+ Ticks : fakeTicker (now , time . Second , 5 ),
55
55
ConditionDeadline : now .Add (5 * time .Second ),
56
56
NumConditions : 6 ,
57
57
NumCallbacks : 2 ,
58
58
},
59
59
{
60
60
Name : "wrong order should not matter" ,
61
61
Countdown : durations (2 * time .Second , 4 * time .Second ),
62
- Ticks : ticks (now , 5 ),
62
+ Ticks : fakeTicker (now , time . Second , 5 ),
63
63
ConditionDeadline : now .Add (5 * time .Second ),
64
64
NumConditions : 6 ,
65
65
NumCallbacks : 2 ,
66
66
},
67
+ {
68
+ Name : "ssh autostop notify" ,
69
+ Countdown : durations (5 * time .Minute , time .Minute ),
70
+ Ticks : fakeTicker (now , 30 * time .Second , 120 ),
71
+ ConditionDeadline : now .Add (30 * time .Minute ),
72
+ NumConditions : 121 ,
73
+ NumCallbacks : 2 ,
74
+ },
67
75
}
68
76
69
77
for _ , testCase := range testCases {
@@ -91,6 +99,7 @@ func TestNotifier(t *testing.T) {
91
99
close (ch )
92
100
wg .Wait ()
93
101
require .Equal (t , testCase .NumCallbacks , numCalls .Load ())
102
+ require .Equal (t , testCase .NumConditions , numConditions .Load ())
94
103
})
95
104
}
96
105
}
@@ -99,11 +108,10 @@ func durations(ds ...time.Duration) []time.Duration {
99
108
return ds
100
109
}
101
110
102
- func ticks (t time.Time , n int ) []time.Time {
103
- ts := make ([]time.Time , n + 1 )
104
- ts = append (ts , t )
105
- for i := 0 ; i < n ; i ++ {
106
- ts = append (ts , t .Add (time .Duration (n )* time .Second ))
111
+ func fakeTicker (t time.Time , d time.Duration , n int ) []time.Time {
112
+ ts := make ([]time.Time , 0 )
113
+ for i := 1 ; i <= n ; i ++ {
114
+ ts = append (ts , t .Add (time .Duration (n )* d ))
107
115
}
108
116
return ts
109
117
}
0 commit comments