File: counter_test.go

package info (click to toggle)
golang-github-facebookgo-stats 0.0~git20151006.0.1b76add-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 108 kB
  • sloc: makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,237 bytes parent folder | download | duplicates (3)
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
60
package stats_test

import (
	"testing"

	"github.com/facebookgo/ensure"
	"github.com/facebookgo/stats"
)

func TestSimpleCounterAggregation(t *testing.T) {
	t.Parallel()

	a := stats.Aggregates{}
	a.Add(&stats.SimpleCounter{
		Key:    "foo.avg",
		Values: []float64{1},
		Type:   stats.AggregateAvg,
	})
	a.Add(&stats.SimpleCounter{
		Key:    "foo.sum",
		Values: []float64{1},
		Type:   stats.AggregateSum,
	})
	a.Add(&stats.SimpleCounter{
		Key:    "foo.time",
		Values: []float64{0, 1, 2, 3, 4},
		Type:   stats.AggregateHistogram,
	})
	a.Add(&stats.SimpleCounter{
		Key:    "foo.sum",
		Values: []float64{2},
		Type:   stats.AggregateSum,
	})
	a.Add(&stats.SimpleCounter{
		Key:    "foo.time",
		Values: []float64{5, 6, 7, 8, 9, 10},
		Type:   stats.AggregateHistogram,
	})
	a.Add(&stats.SimpleCounter{
		Key:    "foo.avg",
		Values: []float64{2},
		Type:   stats.AggregateAvg,
	})

	all := map[string]float64{}
	for _, counter := range a {
		for key, value := range counter.(*stats.SimpleCounter).Aggregate() {
			all[key] = value
		}
	}

	ensure.DeepEqual(t, all, map[string]float64{
		"foo.avg":      1.5,
		"foo.sum":      3.0,
		"foo.time":     5.0,
		"foo.time.p50": 5.0,
		"foo.time.p95": 10.0,
		"foo.time.p99": 10.0,
	})
}