-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbucketreqcounter_test.go
41 lines (38 loc) · 1.11 KB
/
bucketreqcounter_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
package web
import (
"net/http"
"testing"
"time"
"github.com/signalfx/golib/v3/sfxclient"
"github.com/signalfx/golib/v3/timekeeper/timekeepertest"
. "github.com/smartystreets/goconvey/convey"
)
func TestBucketRequestCounter(t *testing.T) {
Convey("With an empty rolling bucket", t, func() {
r := sfxclient.NewRollingBucket("mname", nil)
tk := timekeepertest.NewStubClock(time.Now())
r.Timer = tk
rq := BucketRequestCounter{
Bucket: r,
}
Convey("Wrap should work", func() {
wrapped := rq.Wrap(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
So(wrapped, ShouldNotBeNil)
wrapped.ServeHTTP(nil, nil)
})
Convey("A single request should get the right points", func() {
rq.ServeHTTP(nil, nil, http.HandlerFunc(func(http.ResponseWriter, *http.Request) {
tk.Incr(time.Second * 2)
}))
rq.ServeHTTP(nil, nil, http.HandlerFunc(func(http.ResponseWriter, *http.Request) {
tk.Incr(time.Second)
}))
tk.Incr(sfxclient.DefaultBucketWidth)
dps := rq.Datapoints()
So(len(dps), ShouldEqual, 1+5+len(r.Quantiles))
for _, dp := range dps {
t.Log(dp.String())
}
})
})
}