-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathstretcher_test.go
43 lines (39 loc) · 1.02 KB
/
stretcher_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
package stretcher_test
import (
"context"
"os"
"testing"
"time"
"github.com/fujiwara/stretcher"
)
func TestRandomTime(t *testing.T) {
var sum time.Duration
for i := 0; i < 10000; i++ {
s := stretcher.RandomTime(10)
e := time.Duration(10) * time.Second
if s > e {
t.Errorf("RandomTime too long. expected %s got %s", e, s)
}
sum += s
}
avg := sum / 10000
if avg < time.Duration(4)*time.Second || time.Duration(6)*time.Second < avg {
t.Errorf("average of random time(0 ~ 10s) is out of range (%s)", avg)
}
}
func TestInitSleep(t *testing.T) {
ctx := context.Background()
sleep := time.Duration(1 * time.Second)
start := time.Now()
os.Stdin.Close() // expect to return after parseEvents with error
stretcher.LogBuffer.Reset()
err := stretcher.Run(ctx, stretcher.Config{InitSleep: sleep})
if err == nil {
t.Errorf("err should not be nil: %s", err)
}
end := time.Now()
diff := end.Sub(start)
if diff < sleep {
t.Errorf("sleeping time is not enough. expected at least %s, but returned in %s", sleep, diff)
}
}