OLD | NEW |
1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package tsmon | 5 package tsmon |
6 | 6 |
7 import ( | 7 import ( |
8 "net/http" | 8 "net/http" |
9 "net/http/httptest" | 9 "net/http/httptest" |
10 "testing" | 10 "testing" |
11 "time" | 11 "time" |
12 | 12 |
13 "github.com/luci/gae/service/datastore" | 13 "github.com/luci/gae/service/datastore" |
14 "github.com/luci/luci-go/common/clock" | 14 "github.com/luci/luci-go/common/clock" |
15 "github.com/luci/luci-go/common/tsmon" | 15 "github.com/luci/luci-go/common/tsmon" |
16 "github.com/luci/luci-go/common/tsmon/metric" | 16 "github.com/luci/luci-go/common/tsmon/metric" |
| 17 "github.com/luci/luci-go/common/tsmon/types" |
17 "github.com/luci/luci-go/server/router" | 18 "github.com/luci/luci-go/server/router" |
18 "golang.org/x/net/context" | 19 "golang.org/x/net/context" |
19 | 20 |
20 . "github.com/smartystreets/goconvey/convey" | 21 . "github.com/smartystreets/goconvey/convey" |
21 ) | 22 ) |
22 | 23 |
23 func flushNowWithMiddleware(c context.Context, state *State) { | 24 func flushNowWithMiddleware(c context.Context, state *State) { |
24 ds := datastore.Get(c) | 25 ds := datastore.Get(c) |
25 | 26 |
26 i := instance{ | 27 i := instance{ |
(...skipping 12 matching lines...) Expand all Loading... |
39 nil, | 40 nil, |
40 ) | 41 ) |
41 So(rec.Code, ShouldEqual, http.StatusOK) | 42 So(rec.Code, ShouldEqual, http.StatusOK) |
42 } | 43 } |
43 | 44 |
44 func TestGlobalCallbacks(t *testing.T) { | 45 func TestGlobalCallbacks(t *testing.T) { |
45 Convey("Global callbacks", t, func() { | 46 Convey("Global callbacks", t, func() { |
46 c, _ := buildGAETestContext() | 47 c, _ := buildGAETestContext() |
47 state, mon := buildTestState() | 48 state, mon := buildTestState() |
48 | 49 |
49 » » m := metric.NewCallbackStringIn(c, "foo", "") | 50 » » m := metric.NewCallbackStringIn(c, "foo", "", types.MetricMetada
ta{}) |
50 | 51 |
51 tsmon.RegisterGlobalCallbackIn(c, func(c context.Context) { | 52 tsmon.RegisterGlobalCallbackIn(c, func(c context.Context) { |
52 m.Set(c, "bar") | 53 m.Set(c, "bar") |
53 }, m) | 54 }, m) |
54 | 55 |
55 Convey("are not run on flush", func() { | 56 Convey("are not run on flush", func() { |
56 flushNowWithMiddleware(c, state) | 57 flushNowWithMiddleware(c, state) |
57 val, err := tsmon.Store(c).Get(c, m, time.Time{}, []inte
rface{}{}) | 58 val, err := tsmon.Store(c).Get(c, m, time.Time{}, []inte
rface{}{}) |
58 So(err, ShouldBeNil) | 59 So(err, ShouldBeNil) |
59 So(val, ShouldBeNil) | 60 So(val, ShouldBeNil) |
(...skipping 22 matching lines...) Expand all Loading... |
82 So(err, ShouldBeNil) | 83 So(err, ShouldBeNil) |
83 So(val, ShouldBeNil) | 84 So(val, ShouldBeNil) |
84 | 85 |
85 So(len(mon.Cells), ShouldEqual, 1) | 86 So(len(mon.Cells), ShouldEqual, 1) |
86 So(len(mon.Cells[0]), ShouldEqual, 1) | 87 So(len(mon.Cells[0]), ShouldEqual, 1) |
87 So(mon.Cells[0][0].Value, ShouldEqual, "bar") | 88 So(mon.Cells[0][0].Value, ShouldEqual, "bar") |
88 }) | 89 }) |
89 }) | 90 }) |
90 }) | 91 }) |
91 } | 92 } |
OLD | NEW |