generated from xmidt-org/.go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer_test.go
46 lines (36 loc) · 904 Bytes
/
timer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-FileCopyrightText: 2023 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package retry
import (
"testing"
"time"
"github.com/stretchr/testify/suite"
)
type TimerSuite struct {
suite.Suite
}
// TestDefaultTimer is just a smoke test to make sure the defaultTimer
// operates basically as intended.
func (suite *TimerSuite) TestDefaultTimer() {
ch, stop := defaultTimer(100 * time.Millisecond)
suite.NotNil(ch)
suite.Require().NotNil(stop)
stop()
stop() // idempotent
}
func (suite *TimerSuite) TestImmediateTimer() {
ch, stop := immediateTimer(5 * time.Second)
suite.Require().NotNil(ch)
suite.Require().NotNil(stop)
select {
case <-ch:
// passing
case <-time.After(time.Second):
suite.Fail("immediate timer channel was not signaled")
}
stop()
stop() // idempotent
}
func TestTimer(t *testing.T) {
suite.Run(t, new(TimerSuite))
}