File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -219,20 +219,27 @@ func TestSlottedTicker(t *testing.T) {
219
219
slotNumber : 4 ,
220
220
},
221
221
}
222
- for name , tc := range testCases {
222
+ for name , c := range testCases {
223
+ tc := c
223
224
t .Run (name , func (t * testing.T ) {
224
225
infoFunc := func () (int , int ) {
225
226
return tc .slotNumber , tc .totalSlots
226
227
}
227
228
ticker := NewSlottedTicker (infoFunc , tc .duration )
228
- for i := 0 ; i < 15 ; i ++ {
229
- tTime := <- ticker .C
230
- slotSize := tc .duration .Milliseconds () / int64 (tc .totalSlots )
231
- slotShiftInMs := tTime .UnixMilli () % tc .duration .Milliseconds ()
232
- slot := slotShiftInMs / slotSize
233
- require .GreaterOrEqual (t , slot , int64 (tc .slotNumber ))
234
- require .LessOrEqual (t , slot , int64 (tc .slotNumber + 1 ))
235
- }
229
+ tTime := <- ticker .C
230
+ slotSize := tc .duration .Milliseconds () / int64 (tc .totalSlots )
231
+ slotShiftInMs := tTime .UnixMilli () % tc .duration .Milliseconds ()
232
+ slot := slotShiftInMs / slotSize
233
+ successCount := 0
234
+ test .Poll (t , 2 * time .Second , true , func () interface {} {
235
+ if slot == int64 (tc .slotNumber ) {
236
+ successCount ++
237
+ } else {
238
+ successCount --
239
+ }
240
+
241
+ return successCount == 50
242
+ })
236
243
ticker .Stop ()
237
244
})
238
245
}
You can’t perform that action at this time.
0 commit comments