| 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/tsmon" | 16 "github.com/luci/luci-go/common/tsmon" |
| 16 "github.com/luci/luci-go/common/tsmon/field" | 17 "github.com/luci/luci-go/common/tsmon/field" |
| 17 "github.com/luci/luci-go/common/tsmon/monitor" | 18 "github.com/luci/luci-go/common/tsmon/monitor" |
| 18 "github.com/luci/luci-go/common/tsmon/store" | 19 "github.com/luci/luci-go/common/tsmon/store" |
| 19 "github.com/luci/luci-go/common/tsmon/target" | 20 "github.com/luci/luci-go/common/tsmon/target" |
| 20 "github.com/luci/luci-go/common/tsmon/types" | 21 "github.com/luci/luci-go/common/tsmon/types" |
| 21 "golang.org/x/net/context" | 22 "golang.org/x/net/context" |
| 22 | 23 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 98 |
| 98 lastFlushed.Time = clock.Now().Add(-2 * time.Minute) | 99 lastFlushed.Time = clock.Now().Add(-2 * time.Minute) |
| 99 | 100 |
| 100 rec := httptest.NewRecorder() | 101 rec := httptest.NewRecorder() |
| 101 Middleware(func(c context.Context, rw http.ResponseWriter, r *ht
tp.Request, p httprouter.Params) { | 102 Middleware(func(c context.Context, rw http.ResponseWriter, r *ht
tp.Request, p httprouter.Params) { |
| 102 f(c, rw, r, p) | 103 f(c, rw, r, p) |
| 103 | 104 |
| 104 // Override the TaskNum here - it's created just before
this handler runs | 105 // Override the TaskNum here - it's created just before
this handler runs |
| 105 // and used just after. | 106 // and used just after. |
| 106 tar := tsmon.Store(c).DefaultTarget().(*target.Task) | 107 tar := tsmon.Store(c).DefaultTarget().(*target.Task) |
| 107 » » » tar.TaskNum = 0 | 108 » » » tar.TaskNum = proto.Int32(int32(0)) |
| 108 tsmon.Store(c).SetDefaultTarget(tar) | 109 tsmon.Store(c).SetDefaultTarget(tar) |
| 109 })(c, rec, &http.Request{}, nil) | 110 })(c, rec, &http.Request{}, nil) |
| 110 So(rec.Code, ShouldEqual, http.StatusOK) | 111 So(rec.Code, ShouldEqual, http.StatusOK) |
| 111 | 112 |
| 112 So(len(tsmon.GetState(c).RegisteredMetrics), ShouldEqual, 1) | 113 So(len(tsmon.GetState(c).RegisteredMetrics), ShouldEqual, 1) |
| 113 | 114 |
| 114 monitor := tsmon.GetState(c).M.(*monitor.Fake) | 115 monitor := tsmon.GetState(c).M.(*monitor.Fake) |
| 115 So(len(monitor.Cells), ShouldEqual, 0) | 116 So(len(monitor.Cells), ShouldEqual, 0) |
| 116 | 117 |
| 117 // Value should be reset. | 118 // Value should be reset. |
| 118 value, err := tsmon.Store(c).Get(c, metric, time.Time{}, []inter
face{}{}) | 119 value, err := tsmon.Store(c).Get(c, metric, time.Time{}, []inter
face{}{}) |
| 119 So(err, ShouldBeNil) | 120 So(err, ShouldBeNil) |
| 120 So(value, ShouldBeNil) | 121 So(value, ShouldBeNil) |
| 121 }) | 122 }) |
| 122 } | 123 } |
| OLD | NEW |