forked from jamiealquiza/tachymeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeline_test.go
59 lines (46 loc) · 1017 Bytes
/
timeline_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
54
55
56
57
58
59
package tachymeter_test
import (
"io/ioutil"
"os"
"testing"
"time"
"github.com/develersrl/tachymeter"
)
func newTestTachy() *tachymeter.Tachymeter {
ta := tachymeter.New(&tachymeter.Config{Size: 4})
for i := 12; i < 16; i++ {
ta.AddTime(time.Duration(i) * time.Millisecond)
}
return ta
}
func BenchmarkWriteHTMLTo(b *testing.B) {
ta := newTestTachy()
tl := tachymeter.Timeline{}
tl.AddEvent(ta.Calc())
b.ReportAllocs()
b.ResetTimer()
w := ioutil.Discard
for i := 0; i < b.N; i++ {
err := tl.WriteHTMLTo(w)
if err != nil {
b.Fatalf("can't write html: %s", err)
}
}
}
func TestTimelineEmptyMetrics(t *testing.T) {
tmp, err := ioutil.TempDir("", t.Name())
if err != nil {
t.Fatal("TempDir failed: ", err)
}
defer os.RemoveAll(tmp)
tline := &tachymeter.Timeline{}
ta := tachymeter.New(&tachymeter.Config{Size: 30})
m := ta.Calc()
tline.AddEvent(m)
defer func() {
if r := recover(); r != nil {
t.Errorf("WriteHtml panicked: %v", r)
}
}()
tline.WriteHTML(tmp)
}