| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // 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/golang/protobuf/proto" |
| 13 "github.com/julienschmidt/httprouter" | 14 "github.com/julienschmidt/httprouter" |
| 14 "github.com/luci/gae/service/datastore" | 15 "github.com/luci/gae/service/datastore" |
| 15 "github.com/luci/luci-go/common/clock/testclock" | 16 "github.com/luci/luci-go/common/clock/testclock" |
| 16 "github.com/luci/luci-go/common/tsmon" | 17 "github.com/luci/luci-go/common/tsmon" |
| 17 "github.com/luci/luci-go/common/tsmon/metric" | 18 "github.com/luci/luci-go/common/tsmon/metric" |
| 18 "github.com/luci/luci-go/common/tsmon/monitor" | 19 "github.com/luci/luci-go/common/tsmon/monitor" |
| 19 "github.com/luci/luci-go/common/tsmon/store" | 20 "github.com/luci/luci-go/common/tsmon/store" |
| 20 "github.com/luci/luci-go/common/tsmon/target" | 21 "github.com/luci/luci-go/common/tsmon/target" |
| 21 "golang.org/x/net/context" | 22 "golang.org/x/net/context" |
| 22 | 23 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 44 c := context.Background() | 45 c := context.Background() |
| 45 | 46 |
| 46 Convey("Register callback without metrics panics", t, func() { | 47 Convey("Register callback without metrics panics", t, func() { |
| 47 So(func() { | 48 So(func() { |
| 48 RegisterGlobalCallbackIn(c, func(context.Context) {}) | 49 RegisterGlobalCallbackIn(c, func(context.Context) {}) |
| 49 }, ShouldPanic) | 50 }, ShouldPanic) |
| 50 }) | 51 }) |
| 51 | 52 |
| 52 Convey("Global callbacks", t, func() { | 53 Convey("Global callbacks", t, func() { |
| 53 c, clock := buildGAETestContext() | 54 c, clock := buildGAETestContext() |
| 54 » » s := store.NewInMemory(&target.Task{ServiceName: "default target
"}) | 55 » » s := store.NewInMemory(&target.Task{ServiceName: proto.String("d
efault target")}) |
| 55 mon := &monitor.Fake{} | 56 mon := &monitor.Fake{} |
| 56 state := tsmon.GetState(c) | 57 state := tsmon.GetState(c) |
| 57 state.S = s | 58 state.S = s |
| 58 state.M = mon | 59 state.M = mon |
| 59 m := metric.NewCallbackStringIn(c, "foo", "") | 60 m := metric.NewCallbackStringIn(c, "foo", "") |
| 60 | 61 |
| 61 RegisterGlobalCallbackIn(c, func(c context.Context) { | 62 RegisterGlobalCallbackIn(c, func(c context.Context) { |
| 62 m.Set(c, "bar") | 63 m.Set(c, "bar") |
| 63 }, m) | 64 }, m) |
| 64 | 65 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 85 So(err, ShouldBeNil) | 86 So(err, ShouldBeNil) |
| 86 So(val, ShouldBeNil) | 87 So(val, ShouldBeNil) |
| 87 | 88 |
| 88 So(len(mon.Cells), ShouldEqual, 1) | 89 So(len(mon.Cells), ShouldEqual, 1) |
| 89 So(len(mon.Cells[0]), ShouldEqual, 1) | 90 So(len(mon.Cells[0]), ShouldEqual, 1) |
| 90 So(mon.Cells[0][0].Value, ShouldEqual, "bar") | 91 So(mon.Cells[0][0].Value, ShouldEqual, "bar") |
| 91 }) | 92 }) |
| 92 }) | 93 }) |
| 93 }) | 94 }) |
| 94 } | 95 } |
| OLD | NEW |