-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwheel_test.go
53 lines (43 loc) · 1.07 KB
/
wheel_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
47
48
49
50
51
52
53
package cow
import (
"reflect"
"testing"
"time"
)
func TestSchedule(t *testing.T) {
cli := New()
cli.Start()
result := 0
// schedule an immediate callback
cli.Schedule(0, []byte("123"), func([]byte) {
result++
})
// schedule 3 callbacks in 1 second
cli.Schedule(1*time.Second, []byte("123"), func([]byte) {
result++
})
cli.Schedule(1*time.Second, []byte("123"), func([]byte) {
result++
})
cli.Schedule(1*time.Second, []byte("123"), func([]byte) {
result++
})
// schedule callback in 2 second
cli.Schedule(2*time.Second, []byte("123"), func([]byte) {
result++
})
// Wait for all callbacks to be triggered
time.Sleep(3 * time.Second)
cli.Stop()
expectedCallbacks := 5
if result != expectedCallbacks {
t.Fatalf("expected %d callback to be executed but got %d", expectedCallbacks, result)
}
}
func TestOption(t *testing.T) {
customVal := 2 * time.Second
cli := New(WithTickInterval(customVal))
if !reflect.DeepEqual(cli.tickInterval, customVal) {
t.Fatalf("incorrect config values. expected %+v but got %+v", customVal, cli.tickInterval)
}
}