-
Notifications
You must be signed in to change notification settings - Fork 0
/
wheel_test.go
35 lines (33 loc) · 686 Bytes
/
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
package timer
import (
"fmt"
"sync"
"testing"
"time"
)
//TestTimeWheel test timewheel.
func TestTimeWheel(t *testing.T) {
var deviation int64
var num int64 = 100
sleepTime := time.Millisecond * 20000
timer := New(20, time.Millisecond*5)
wg := sync.WaitGroup{}
for i := 0; i < 100; i++ {
wg.Add(1)
go func(i int) {
start := time.Now().UnixNano()
<-timer.After(time.Millisecond * 100)
end := time.Now().UnixNano()
d := (end - start) - int64(sleepTime)
if d >= 0 {
deviation += d
} else {
deviation -= d
}
wg.Done()
}(i)
time.Sleep(time.Millisecond * 100)
}
wg.Wait()
fmt.Println(float64(deviation) / float64(num*int64(sleepTime)))
}