Dep helper (#2151)
* Add dep task to update go dependencies * Update go dependencies
This commit is contained in:
parent
8f8b81f56b
commit
0e8977761d
764 changed files with 172 additions and 267451 deletions
77
vendor/github.com/rcrowley/go-metrics/counter_test.go
generated
vendored
77
vendor/github.com/rcrowley/go-metrics/counter_test.go
generated
vendored
|
@ -1,77 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import "testing"
|
||||
|
||||
func BenchmarkCounter(b *testing.B) {
|
||||
c := NewCounter()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
c.Inc(1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCounterClear(t *testing.T) {
|
||||
c := NewCounter()
|
||||
c.Inc(1)
|
||||
c.Clear()
|
||||
if count := c.Count(); 0 != count {
|
||||
t.Errorf("c.Count(): 0 != %v\n", count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCounterDec1(t *testing.T) {
|
||||
c := NewCounter()
|
||||
c.Dec(1)
|
||||
if count := c.Count(); -1 != count {
|
||||
t.Errorf("c.Count(): -1 != %v\n", count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCounterDec2(t *testing.T) {
|
||||
c := NewCounter()
|
||||
c.Dec(2)
|
||||
if count := c.Count(); -2 != count {
|
||||
t.Errorf("c.Count(): -2 != %v\n", count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCounterInc1(t *testing.T) {
|
||||
c := NewCounter()
|
||||
c.Inc(1)
|
||||
if count := c.Count(); 1 != count {
|
||||
t.Errorf("c.Count(): 1 != %v\n", count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCounterInc2(t *testing.T) {
|
||||
c := NewCounter()
|
||||
c.Inc(2)
|
||||
if count := c.Count(); 2 != count {
|
||||
t.Errorf("c.Count(): 2 != %v\n", count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCounterSnapshot(t *testing.T) {
|
||||
c := NewCounter()
|
||||
c.Inc(1)
|
||||
snapshot := c.Snapshot()
|
||||
c.Inc(1)
|
||||
if count := snapshot.Count(); 1 != count {
|
||||
t.Errorf("c.Count(): 1 != %v\n", count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCounterZero(t *testing.T) {
|
||||
c := NewCounter()
|
||||
if count := c.Count(); 0 != count {
|
||||
t.Errorf("c.Count(): 0 != %v\n", count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrRegisterCounter(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
NewRegisteredCounter("foo", r).Inc(47)
|
||||
if c := GetOrRegisterCounter("foo", r); 47 != c.Count() {
|
||||
t.Fatal(c)
|
||||
}
|
||||
}
|
48
vendor/github.com/rcrowley/go-metrics/debug_test.go
generated
vendored
48
vendor/github.com/rcrowley/go-metrics/debug_test.go
generated
vendored
|
@ -1,48 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func BenchmarkDebugGCStats(b *testing.B) {
|
||||
r := NewRegistry()
|
||||
RegisterDebugGCStats(r)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
CaptureDebugGCStatsOnce(r)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDebugGCStatsBlocking(t *testing.T) {
|
||||
if g := runtime.GOMAXPROCS(0); g < 2 {
|
||||
t.Skipf("skipping TestDebugGCMemStatsBlocking with GOMAXPROCS=%d\n", g)
|
||||
return
|
||||
}
|
||||
ch := make(chan int)
|
||||
go testDebugGCStatsBlocking(ch)
|
||||
var gcStats debug.GCStats
|
||||
t0 := time.Now()
|
||||
debug.ReadGCStats(&gcStats)
|
||||
t1 := time.Now()
|
||||
t.Log("i++ during debug.ReadGCStats:", <-ch)
|
||||
go testDebugGCStatsBlocking(ch)
|
||||
d := t1.Sub(t0)
|
||||
t.Log(d)
|
||||
time.Sleep(d)
|
||||
t.Log("i++ during time.Sleep:", <-ch)
|
||||
}
|
||||
|
||||
func testDebugGCStatsBlocking(ch chan int) {
|
||||
i := 0
|
||||
for {
|
||||
select {
|
||||
case ch <- i:
|
||||
return
|
||||
default:
|
||||
i++
|
||||
}
|
||||
}
|
||||
}
|
258
vendor/github.com/rcrowley/go-metrics/ewma_test.go
generated
vendored
258
vendor/github.com/rcrowley/go-metrics/ewma_test.go
generated
vendored
|
@ -1,258 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func BenchmarkEWMA(b *testing.B) {
|
||||
a := NewEWMA1()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
a.Update(1)
|
||||
a.Tick()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEWMAParallel(b *testing.B) {
|
||||
a := NewEWMA1()
|
||||
b.ResetTimer()
|
||||
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
a.Update(1)
|
||||
a.Tick()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// exercise race detector
|
||||
func TestEWMAConcurrency(t *testing.T) {
|
||||
rand.Seed(time.Now().Unix())
|
||||
a := NewEWMA1()
|
||||
wg := &sync.WaitGroup{}
|
||||
reps := 100
|
||||
for i := 0; i < reps; i++ {
|
||||
wg.Add(1)
|
||||
go func(ewma EWMA, wg *sync.WaitGroup) {
|
||||
a.Update(rand.Int63())
|
||||
wg.Done()
|
||||
}(a, wg)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestEWMA1(t *testing.T) {
|
||||
a := NewEWMA1()
|
||||
a.Update(3)
|
||||
a.Tick()
|
||||
if rate := a.Rate(); 0.6 != rate {
|
||||
t.Errorf("initial a.Rate(): 0.6 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.22072766470286553 != rate {
|
||||
t.Errorf("1 minute a.Rate(): 0.22072766470286553 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.08120116994196772 != rate {
|
||||
t.Errorf("2 minute a.Rate(): 0.08120116994196772 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.029872241020718428 != rate {
|
||||
t.Errorf("3 minute a.Rate(): 0.029872241020718428 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.01098938333324054 != rate {
|
||||
t.Errorf("4 minute a.Rate(): 0.01098938333324054 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.004042768199451294 != rate {
|
||||
t.Errorf("5 minute a.Rate(): 0.004042768199451294 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.0014872513059998212 != rate {
|
||||
t.Errorf("6 minute a.Rate(): 0.0014872513059998212 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.0005471291793327122 != rate {
|
||||
t.Errorf("7 minute a.Rate(): 0.0005471291793327122 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.00020127757674150815 != rate {
|
||||
t.Errorf("8 minute a.Rate(): 0.00020127757674150815 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 7.404588245200814e-05 != rate {
|
||||
t.Errorf("9 minute a.Rate(): 7.404588245200814e-05 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 2.7239957857491083e-05 != rate {
|
||||
t.Errorf("10 minute a.Rate(): 2.7239957857491083e-05 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 1.0021020474147462e-05 != rate {
|
||||
t.Errorf("11 minute a.Rate(): 1.0021020474147462e-05 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 3.6865274119969525e-06 != rate {
|
||||
t.Errorf("12 minute a.Rate(): 3.6865274119969525e-06 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 1.3561976441886433e-06 != rate {
|
||||
t.Errorf("13 minute a.Rate(): 1.3561976441886433e-06 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 4.989172314621449e-07 != rate {
|
||||
t.Errorf("14 minute a.Rate(): 4.989172314621449e-07 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 1.8354139230109722e-07 != rate {
|
||||
t.Errorf("15 minute a.Rate(): 1.8354139230109722e-07 != %v\n", rate)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEWMA5(t *testing.T) {
|
||||
a := NewEWMA5()
|
||||
a.Update(3)
|
||||
a.Tick()
|
||||
if rate := a.Rate(); 0.6 != rate {
|
||||
t.Errorf("initial a.Rate(): 0.6 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.49123845184678905 != rate {
|
||||
t.Errorf("1 minute a.Rate(): 0.49123845184678905 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.4021920276213837 != rate {
|
||||
t.Errorf("2 minute a.Rate(): 0.4021920276213837 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.32928698165641596 != rate {
|
||||
t.Errorf("3 minute a.Rate(): 0.32928698165641596 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.269597378470333 != rate {
|
||||
t.Errorf("4 minute a.Rate(): 0.269597378470333 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.2207276647028654 != rate {
|
||||
t.Errorf("5 minute a.Rate(): 0.2207276647028654 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.18071652714732128 != rate {
|
||||
t.Errorf("6 minute a.Rate(): 0.18071652714732128 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.14795817836496392 != rate {
|
||||
t.Errorf("7 minute a.Rate(): 0.14795817836496392 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.12113791079679326 != rate {
|
||||
t.Errorf("8 minute a.Rate(): 0.12113791079679326 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.09917933293295193 != rate {
|
||||
t.Errorf("9 minute a.Rate(): 0.09917933293295193 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.08120116994196763 != rate {
|
||||
t.Errorf("10 minute a.Rate(): 0.08120116994196763 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.06648189501740036 != rate {
|
||||
t.Errorf("11 minute a.Rate(): 0.06648189501740036 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.05443077197364752 != rate {
|
||||
t.Errorf("12 minute a.Rate(): 0.05443077197364752 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.04456414692860035 != rate {
|
||||
t.Errorf("13 minute a.Rate(): 0.04456414692860035 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.03648603757513079 != rate {
|
||||
t.Errorf("14 minute a.Rate(): 0.03648603757513079 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.0298722410207183831020718428 != rate {
|
||||
t.Errorf("15 minute a.Rate(): 0.0298722410207183831020718428 != %v\n", rate)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEWMA15(t *testing.T) {
|
||||
a := NewEWMA15()
|
||||
a.Update(3)
|
||||
a.Tick()
|
||||
if rate := a.Rate(); 0.6 != rate {
|
||||
t.Errorf("initial a.Rate(): 0.6 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.5613041910189706 != rate {
|
||||
t.Errorf("1 minute a.Rate(): 0.5613041910189706 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.5251039914257684 != rate {
|
||||
t.Errorf("2 minute a.Rate(): 0.5251039914257684 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.4912384518467888184678905 != rate {
|
||||
t.Errorf("3 minute a.Rate(): 0.4912384518467888184678905 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.459557003018789 != rate {
|
||||
t.Errorf("4 minute a.Rate(): 0.459557003018789 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.4299187863442732 != rate {
|
||||
t.Errorf("5 minute a.Rate(): 0.4299187863442732 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.4021920276213831 != rate {
|
||||
t.Errorf("6 minute a.Rate(): 0.4021920276213831 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.37625345116383313 != rate {
|
||||
t.Errorf("7 minute a.Rate(): 0.37625345116383313 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.3519877317060185 != rate {
|
||||
t.Errorf("8 minute a.Rate(): 0.3519877317060185 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.3292869816564153165641596 != rate {
|
||||
t.Errorf("9 minute a.Rate(): 0.3292869816564153165641596 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.3080502714195546 != rate {
|
||||
t.Errorf("10 minute a.Rate(): 0.3080502714195546 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.2881831806538789 != rate {
|
||||
t.Errorf("11 minute a.Rate(): 0.2881831806538789 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.26959737847033216 != rate {
|
||||
t.Errorf("12 minute a.Rate(): 0.26959737847033216 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.2522102307052083 != rate {
|
||||
t.Errorf("13 minute a.Rate(): 0.2522102307052083 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.23594443252115815 != rate {
|
||||
t.Errorf("14 minute a.Rate(): 0.23594443252115815 != %v\n", rate)
|
||||
}
|
||||
elapseMinute(a)
|
||||
if rate := a.Rate(); 0.2207276647028646247028654470286553 != rate {
|
||||
t.Errorf("15 minute a.Rate(): 0.2207276647028646247028654470286553 != %v\n", rate)
|
||||
}
|
||||
}
|
||||
|
||||
func elapseMinute(a EWMA) {
|
||||
for i := 0; i < 12; i++ {
|
||||
a.Tick()
|
||||
}
|
||||
}
|
69
vendor/github.com/rcrowley/go-metrics/gauge_float64_test.go
generated
vendored
69
vendor/github.com/rcrowley/go-metrics/gauge_float64_test.go
generated
vendored
|
@ -1,69 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import "testing"
|
||||
|
||||
func BenchmarkGuageFloat64(b *testing.B) {
|
||||
g := NewGaugeFloat64()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
g.Update(float64(i))
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGuageFloat64Parallel(b *testing.B) {
|
||||
g := NewGaugeFloat64()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
g.Update(float64(1))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestGaugeFloat64(t *testing.T) {
|
||||
g := NewGaugeFloat64()
|
||||
g.Update(float64(47.0))
|
||||
if v := g.Value(); float64(47.0) != v {
|
||||
t.Errorf("g.Value(): 47.0 != %v\n", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGaugeFloat64Snapshot(t *testing.T) {
|
||||
g := NewGaugeFloat64()
|
||||
g.Update(float64(47.0))
|
||||
snapshot := g.Snapshot()
|
||||
g.Update(float64(0))
|
||||
if v := snapshot.Value(); float64(47.0) != v {
|
||||
t.Errorf("g.Value(): 47.0 != %v\n", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrRegisterGaugeFloat64(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
NewRegisteredGaugeFloat64("foo", r).Update(float64(47.0))
|
||||
t.Logf("registry: %v", r)
|
||||
if g := GetOrRegisterGaugeFloat64("foo", r); float64(47.0) != g.Value() {
|
||||
t.Fatal(g)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFunctionalGaugeFloat64(t *testing.T) {
|
||||
var counter float64
|
||||
fg := NewFunctionalGaugeFloat64(func() float64 {
|
||||
counter++
|
||||
return counter
|
||||
})
|
||||
fg.Value()
|
||||
fg.Value()
|
||||
if counter != 2 {
|
||||
t.Error("counter != 2")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrRegisterFunctionalGaugeFloat64(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
NewRegisteredFunctionalGaugeFloat64("foo", r, func() float64 { return 47 })
|
||||
if g := GetOrRegisterGaugeFloat64("foo", r); 47 != g.Value() {
|
||||
t.Fatal(g)
|
||||
}
|
||||
}
|
87
vendor/github.com/rcrowley/go-metrics/gauge_test.go
generated
vendored
87
vendor/github.com/rcrowley/go-metrics/gauge_test.go
generated
vendored
|
@ -1,87 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func BenchmarkGuage(b *testing.B) {
|
||||
g := NewGauge()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
g.Update(int64(i))
|
||||
}
|
||||
}
|
||||
|
||||
// exercise race detector
|
||||
func TestGaugeConcurrency(t *testing.T) {
|
||||
rand.Seed(time.Now().Unix())
|
||||
g := NewGauge()
|
||||
wg := &sync.WaitGroup{}
|
||||
reps := 100
|
||||
for i := 0; i < reps; i++ {
|
||||
wg.Add(1)
|
||||
go func(g Gauge, wg *sync.WaitGroup) {
|
||||
g.Update(rand.Int63())
|
||||
wg.Done()
|
||||
}(g, wg)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestGauge(t *testing.T) {
|
||||
g := NewGauge()
|
||||
g.Update(int64(47))
|
||||
if v := g.Value(); 47 != v {
|
||||
t.Errorf("g.Value(): 47 != %v\n", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGaugeSnapshot(t *testing.T) {
|
||||
g := NewGauge()
|
||||
g.Update(int64(47))
|
||||
snapshot := g.Snapshot()
|
||||
g.Update(int64(0))
|
||||
if v := snapshot.Value(); 47 != v {
|
||||
t.Errorf("g.Value(): 47 != %v\n", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrRegisterGauge(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
NewRegisteredGauge("foo", r).Update(47)
|
||||
if g := GetOrRegisterGauge("foo", r); 47 != g.Value() {
|
||||
t.Fatal(g)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFunctionalGauge(t *testing.T) {
|
||||
var counter int64
|
||||
fg := NewFunctionalGauge(func() int64 {
|
||||
counter++
|
||||
return counter
|
||||
})
|
||||
fg.Value()
|
||||
fg.Value()
|
||||
if counter != 2 {
|
||||
t.Error("counter != 2")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrRegisterFunctionalGauge(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
NewRegisteredFunctionalGauge("foo", r, func() int64 { return 47 })
|
||||
if g := GetOrRegisterGauge("foo", r); 47 != g.Value() {
|
||||
t.Fatal(g)
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleGetOrRegisterGauge() {
|
||||
m := "server.bytes_sent"
|
||||
g := GetOrRegisterGauge(m, nil)
|
||||
g.Update(47)
|
||||
fmt.Println(g.Value()) // Output: 47
|
||||
}
|
22
vendor/github.com/rcrowley/go-metrics/graphite_test.go
generated
vendored
22
vendor/github.com/rcrowley/go-metrics/graphite_test.go
generated
vendored
|
@ -1,22 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
func ExampleGraphite() {
|
||||
addr, _ := net.ResolveTCPAddr("net", ":2003")
|
||||
go Graphite(DefaultRegistry, 1*time.Second, "some.prefix", addr)
|
||||
}
|
||||
|
||||
func ExampleGraphiteWithConfig() {
|
||||
addr, _ := net.ResolveTCPAddr("net", ":2003")
|
||||
go GraphiteWithConfig(GraphiteConfig{
|
||||
Addr: addr,
|
||||
Registry: DefaultRegistry,
|
||||
FlushInterval: 1 * time.Second,
|
||||
DurationUnit: time.Millisecond,
|
||||
Percentiles: []float64{0.5, 0.75, 0.99, 0.999},
|
||||
})
|
||||
}
|
95
vendor/github.com/rcrowley/go-metrics/histogram_test.go
generated
vendored
95
vendor/github.com/rcrowley/go-metrics/histogram_test.go
generated
vendored
|
@ -1,95 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import "testing"
|
||||
|
||||
func BenchmarkHistogram(b *testing.B) {
|
||||
h := NewHistogram(NewUniformSample(100))
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
h.Update(int64(i))
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrRegisterHistogram(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
s := NewUniformSample(100)
|
||||
NewRegisteredHistogram("foo", r, s).Update(47)
|
||||
if h := GetOrRegisterHistogram("foo", r, s); 1 != h.Count() {
|
||||
t.Fatal(h)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHistogram10000(t *testing.T) {
|
||||
h := NewHistogram(NewUniformSample(100000))
|
||||
for i := 1; i <= 10000; i++ {
|
||||
h.Update(int64(i))
|
||||
}
|
||||
testHistogram10000(t, h)
|
||||
}
|
||||
|
||||
func TestHistogramEmpty(t *testing.T) {
|
||||
h := NewHistogram(NewUniformSample(100))
|
||||
if count := h.Count(); 0 != count {
|
||||
t.Errorf("h.Count(): 0 != %v\n", count)
|
||||
}
|
||||
if min := h.Min(); 0 != min {
|
||||
t.Errorf("h.Min(): 0 != %v\n", min)
|
||||
}
|
||||
if max := h.Max(); 0 != max {
|
||||
t.Errorf("h.Max(): 0 != %v\n", max)
|
||||
}
|
||||
if mean := h.Mean(); 0.0 != mean {
|
||||
t.Errorf("h.Mean(): 0.0 != %v\n", mean)
|
||||
}
|
||||
if stdDev := h.StdDev(); 0.0 != stdDev {
|
||||
t.Errorf("h.StdDev(): 0.0 != %v\n", stdDev)
|
||||
}
|
||||
ps := h.Percentiles([]float64{0.5, 0.75, 0.99})
|
||||
if 0.0 != ps[0] {
|
||||
t.Errorf("median: 0.0 != %v\n", ps[0])
|
||||
}
|
||||
if 0.0 != ps[1] {
|
||||
t.Errorf("75th percentile: 0.0 != %v\n", ps[1])
|
||||
}
|
||||
if 0.0 != ps[2] {
|
||||
t.Errorf("99th percentile: 0.0 != %v\n", ps[2])
|
||||
}
|
||||
}
|
||||
|
||||
func TestHistogramSnapshot(t *testing.T) {
|
||||
h := NewHistogram(NewUniformSample(100000))
|
||||
for i := 1; i <= 10000; i++ {
|
||||
h.Update(int64(i))
|
||||
}
|
||||
snapshot := h.Snapshot()
|
||||
h.Update(0)
|
||||
testHistogram10000(t, snapshot)
|
||||
}
|
||||
|
||||
func testHistogram10000(t *testing.T, h Histogram) {
|
||||
if count := h.Count(); 10000 != count {
|
||||
t.Errorf("h.Count(): 10000 != %v\n", count)
|
||||
}
|
||||
if min := h.Min(); 1 != min {
|
||||
t.Errorf("h.Min(): 1 != %v\n", min)
|
||||
}
|
||||
if max := h.Max(); 10000 != max {
|
||||
t.Errorf("h.Max(): 10000 != %v\n", max)
|
||||
}
|
||||
if mean := h.Mean(); 5000.5 != mean {
|
||||
t.Errorf("h.Mean(): 5000.5 != %v\n", mean)
|
||||
}
|
||||
if stdDev := h.StdDev(); 2886.751331514372 != stdDev {
|
||||
t.Errorf("h.StdDev(): 2886.751331514372 != %v\n", stdDev)
|
||||
}
|
||||
ps := h.Percentiles([]float64{0.5, 0.75, 0.99})
|
||||
if 5000.5 != ps[0] {
|
||||
t.Errorf("median: 5000.5 != %v\n", ps[0])
|
||||
}
|
||||
if 7500.75 != ps[1] {
|
||||
t.Errorf("75th percentile: 7500.75 != %v\n", ps[1])
|
||||
}
|
||||
if 9900.99 != ps[2] {
|
||||
t.Errorf("99th percentile: 9900.99 != %v\n", ps[2])
|
||||
}
|
||||
}
|
28
vendor/github.com/rcrowley/go-metrics/json_test.go
generated
vendored
28
vendor/github.com/rcrowley/go-metrics/json_test.go
generated
vendored
|
@ -1,28 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRegistryMarshallJSON(t *testing.T) {
|
||||
b := &bytes.Buffer{}
|
||||
enc := json.NewEncoder(b)
|
||||
r := NewRegistry()
|
||||
r.Register("counter", NewCounter())
|
||||
enc.Encode(r)
|
||||
if s := b.String(); "{\"counter\":{\"count\":0}}\n" != s {
|
||||
t.Fatalf(s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegistryWriteJSONOnce(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
r.Register("counter", NewCounter())
|
||||
b := &bytes.Buffer{}
|
||||
WriteJSONOnce(r, b)
|
||||
if s := b.String(); s != "{\"counter\":{\"count\":0}}\n" {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
107
vendor/github.com/rcrowley/go-metrics/meter_test.go
generated
vendored
107
vendor/github.com/rcrowley/go-metrics/meter_test.go
generated
vendored
|
@ -1,107 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func BenchmarkMeter(b *testing.B) {
|
||||
m := NewMeter()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
m.Mark(1)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMeterParallel(b *testing.B) {
|
||||
m := NewMeter()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
m.Mark(1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// exercise race detector
|
||||
func TestMeterConcurrency(t *testing.T) {
|
||||
rand.Seed(time.Now().Unix())
|
||||
ma := meterArbiter{
|
||||
ticker: time.NewTicker(time.Millisecond),
|
||||
meters: make(map[*StandardMeter]struct{}),
|
||||
}
|
||||
m := newStandardMeter()
|
||||
ma.meters[m] = struct{}{}
|
||||
go ma.tick()
|
||||
wg := &sync.WaitGroup{}
|
||||
reps := 100
|
||||
for i := 0; i < reps; i++ {
|
||||
wg.Add(1)
|
||||
go func(m Meter, wg *sync.WaitGroup) {
|
||||
m.Mark(1)
|
||||
wg.Done()
|
||||
}(m, wg)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestGetOrRegisterMeter(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
NewRegisteredMeter("foo", r).Mark(47)
|
||||
if m := GetOrRegisterMeter("foo", r); 47 != m.Count() {
|
||||
t.Fatal(m)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMeterDecay(t *testing.T) {
|
||||
ma := meterArbiter{
|
||||
ticker: time.NewTicker(time.Millisecond),
|
||||
meters: make(map[*StandardMeter]struct{}),
|
||||
}
|
||||
m := newStandardMeter()
|
||||
ma.meters[m] = struct{}{}
|
||||
go ma.tick()
|
||||
m.Mark(1)
|
||||
rateMean := m.RateMean()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
if m.RateMean() >= rateMean {
|
||||
t.Error("m.RateMean() didn't decrease")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMeterNonzero(t *testing.T) {
|
||||
m := NewMeter()
|
||||
m.Mark(3)
|
||||
if count := m.Count(); 3 != count {
|
||||
t.Errorf("m.Count(): 3 != %v\n", count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMeterStop(t *testing.T) {
|
||||
l := len(arbiter.meters)
|
||||
m := NewMeter()
|
||||
if len(arbiter.meters) != l+1 {
|
||||
t.Errorf("arbiter.meters: %d != %d\n", l+1, len(arbiter.meters))
|
||||
}
|
||||
m.Stop()
|
||||
if len(arbiter.meters) != l {
|
||||
t.Errorf("arbiter.meters: %d != %d\n", l, len(arbiter.meters))
|
||||
}
|
||||
}
|
||||
|
||||
func TestMeterSnapshot(t *testing.T) {
|
||||
m := NewMeter()
|
||||
m.Mark(1)
|
||||
if snapshot := m.Snapshot(); m.RateMean() != snapshot.RateMean() {
|
||||
t.Fatal(snapshot)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMeterZero(t *testing.T) {
|
||||
m := NewMeter()
|
||||
if count := m.Count(); 0 != count {
|
||||
t.Errorf("m.Count(): 0 != %v\n", count)
|
||||
}
|
||||
}
|
124
vendor/github.com/rcrowley/go-metrics/metrics_test.go
generated
vendored
124
vendor/github.com/rcrowley/go-metrics/metrics_test.go
generated
vendored
|
@ -1,124 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const FANOUT = 128
|
||||
|
||||
// Stop the compiler from complaining during debugging.
|
||||
var (
|
||||
_ = ioutil.Discard
|
||||
_ = log.LstdFlags
|
||||
)
|
||||
|
||||
func BenchmarkMetrics(b *testing.B) {
|
||||
r := NewRegistry()
|
||||
c := NewRegisteredCounter("counter", r)
|
||||
g := NewRegisteredGauge("gauge", r)
|
||||
gf := NewRegisteredGaugeFloat64("gaugefloat64", r)
|
||||
h := NewRegisteredHistogram("histogram", r, NewUniformSample(100))
|
||||
m := NewRegisteredMeter("meter", r)
|
||||
t := NewRegisteredTimer("timer", r)
|
||||
RegisterDebugGCStats(r)
|
||||
RegisterRuntimeMemStats(r)
|
||||
b.ResetTimer()
|
||||
ch := make(chan bool)
|
||||
|
||||
wgD := &sync.WaitGroup{}
|
||||
/*
|
||||
wgD.Add(1)
|
||||
go func() {
|
||||
defer wgD.Done()
|
||||
//log.Println("go CaptureDebugGCStats")
|
||||
for {
|
||||
select {
|
||||
case <-ch:
|
||||
//log.Println("done CaptureDebugGCStats")
|
||||
return
|
||||
default:
|
||||
CaptureDebugGCStatsOnce(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
//*/
|
||||
|
||||
wgR := &sync.WaitGroup{}
|
||||
//*
|
||||
wgR.Add(1)
|
||||
go func() {
|
||||
defer wgR.Done()
|
||||
//log.Println("go CaptureRuntimeMemStats")
|
||||
for {
|
||||
select {
|
||||
case <-ch:
|
||||
//log.Println("done CaptureRuntimeMemStats")
|
||||
return
|
||||
default:
|
||||
CaptureRuntimeMemStatsOnce(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
//*/
|
||||
|
||||
wgW := &sync.WaitGroup{}
|
||||
/*
|
||||
wgW.Add(1)
|
||||
go func() {
|
||||
defer wgW.Done()
|
||||
//log.Println("go Write")
|
||||
for {
|
||||
select {
|
||||
case <-ch:
|
||||
//log.Println("done Write")
|
||||
return
|
||||
default:
|
||||
WriteOnce(r, ioutil.Discard)
|
||||
}
|
||||
}
|
||||
}()
|
||||
//*/
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(FANOUT)
|
||||
for i := 0; i < FANOUT; i++ {
|
||||
go func(i int) {
|
||||
defer wg.Done()
|
||||
//log.Println("go", i)
|
||||
for i := 0; i < b.N; i++ {
|
||||
c.Inc(1)
|
||||
g.Update(int64(i))
|
||||
gf.Update(float64(i))
|
||||
h.Update(int64(i))
|
||||
m.Mark(1)
|
||||
t.Update(1)
|
||||
}
|
||||
//log.Println("done", i)
|
||||
}(i)
|
||||
}
|
||||
wg.Wait()
|
||||
close(ch)
|
||||
wgD.Wait()
|
||||
wgR.Wait()
|
||||
wgW.Wait()
|
||||
}
|
||||
|
||||
func Example() {
|
||||
c := NewCounter()
|
||||
Register("money", c)
|
||||
c.Inc(17)
|
||||
|
||||
// Threadsafe registration
|
||||
t := GetOrRegisterTimer("db.get.latency", nil)
|
||||
t.Time(func() {})
|
||||
t.Update(1)
|
||||
|
||||
fmt.Println(c.Count())
|
||||
fmt.Println(t.Min())
|
||||
// Output: 17
|
||||
// 1
|
||||
}
|
21
vendor/github.com/rcrowley/go-metrics/opentsdb_test.go
generated
vendored
21
vendor/github.com/rcrowley/go-metrics/opentsdb_test.go
generated
vendored
|
@ -1,21 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
func ExampleOpenTSDB() {
|
||||
addr, _ := net.ResolveTCPAddr("net", ":2003")
|
||||
go OpenTSDB(DefaultRegistry, 1*time.Second, "some.prefix", addr)
|
||||
}
|
||||
|
||||
func ExampleOpenTSDBWithConfig() {
|
||||
addr, _ := net.ResolveTCPAddr("net", ":2003")
|
||||
go OpenTSDBWithConfig(OpenTSDBConfig{
|
||||
Addr: addr,
|
||||
Registry: DefaultRegistry,
|
||||
FlushInterval: 1 * time.Second,
|
||||
DurationUnit: time.Millisecond,
|
||||
})
|
||||
}
|
363
vendor/github.com/rcrowley/go-metrics/registry_test.go
generated
vendored
363
vendor/github.com/rcrowley/go-metrics/registry_test.go
generated
vendored
|
@ -1,363 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkRegistry(b *testing.B) {
|
||||
r := NewRegistry()
|
||||
r.Register("foo", NewCounter())
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
r.Each(func(string, interface{}) {})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRegistryParallel(b *testing.B) {
|
||||
r := NewRegistry()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
r.GetOrRegister("foo", NewCounter())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestRegistry(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
r.Register("foo", NewCounter())
|
||||
i := 0
|
||||
r.Each(func(name string, iface interface{}) {
|
||||
i++
|
||||
if "foo" != name {
|
||||
t.Fatal(name)
|
||||
}
|
||||
if _, ok := iface.(Counter); !ok {
|
||||
t.Fatal(iface)
|
||||
}
|
||||
})
|
||||
if 1 != i {
|
||||
t.Fatal(i)
|
||||
}
|
||||
r.Unregister("foo")
|
||||
i = 0
|
||||
r.Each(func(string, interface{}) { i++ })
|
||||
if 0 != i {
|
||||
t.Fatal(i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegistryDuplicate(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
if err := r.Register("foo", NewCounter()); nil != err {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := r.Register("foo", NewGauge()); nil == err {
|
||||
t.Fatal(err)
|
||||
}
|
||||
i := 0
|
||||
r.Each(func(name string, iface interface{}) {
|
||||
i++
|
||||
if _, ok := iface.(Counter); !ok {
|
||||
t.Fatal(iface)
|
||||
}
|
||||
})
|
||||
if 1 != i {
|
||||
t.Fatal(i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegistryGet(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
r.Register("foo", NewCounter())
|
||||
if count := r.Get("foo").(Counter).Count(); 0 != count {
|
||||
t.Fatal(count)
|
||||
}
|
||||
r.Get("foo").(Counter).Inc(1)
|
||||
if count := r.Get("foo").(Counter).Count(); 1 != count {
|
||||
t.Fatal(count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegistryGetOrRegister(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
|
||||
// First metric wins with GetOrRegister
|
||||
_ = r.GetOrRegister("foo", NewCounter())
|
||||
m := r.GetOrRegister("foo", NewGauge())
|
||||
if _, ok := m.(Counter); !ok {
|
||||
t.Fatal(m)
|
||||
}
|
||||
|
||||
i := 0
|
||||
r.Each(func(name string, iface interface{}) {
|
||||
i++
|
||||
if name != "foo" {
|
||||
t.Fatal(name)
|
||||
}
|
||||
if _, ok := iface.(Counter); !ok {
|
||||
t.Fatal(iface)
|
||||
}
|
||||
})
|
||||
if i != 1 {
|
||||
t.Fatal(i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegistryGetOrRegisterWithLazyInstantiation(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
|
||||
// First metric wins with GetOrRegister
|
||||
_ = r.GetOrRegister("foo", NewCounter)
|
||||
m := r.GetOrRegister("foo", NewGauge)
|
||||
if _, ok := m.(Counter); !ok {
|
||||
t.Fatal(m)
|
||||
}
|
||||
|
||||
i := 0
|
||||
r.Each(func(name string, iface interface{}) {
|
||||
i++
|
||||
if name != "foo" {
|
||||
t.Fatal(name)
|
||||
}
|
||||
if _, ok := iface.(Counter); !ok {
|
||||
t.Fatal(iface)
|
||||
}
|
||||
})
|
||||
if i != 1 {
|
||||
t.Fatal(i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegistryUnregister(t *testing.T) {
|
||||
l := len(arbiter.meters)
|
||||
r := NewRegistry()
|
||||
r.Register("foo", NewCounter())
|
||||
r.Register("bar", NewMeter())
|
||||
r.Register("baz", NewTimer())
|
||||
if len(arbiter.meters) != l+2 {
|
||||
t.Errorf("arbiter.meters: %d != %d\n", l+2, len(arbiter.meters))
|
||||
}
|
||||
r.Unregister("foo")
|
||||
r.Unregister("bar")
|
||||
r.Unregister("baz")
|
||||
if len(arbiter.meters) != l {
|
||||
t.Errorf("arbiter.meters: %d != %d\n", l+2, len(arbiter.meters))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrefixedChildRegistryGetOrRegister(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
pr := NewPrefixedChildRegistry(r, "prefix.")
|
||||
|
||||
_ = pr.GetOrRegister("foo", NewCounter())
|
||||
|
||||
i := 0
|
||||
r.Each(func(name string, m interface{}) {
|
||||
i++
|
||||
if name != "prefix.foo" {
|
||||
t.Fatal(name)
|
||||
}
|
||||
})
|
||||
if i != 1 {
|
||||
t.Fatal(i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrefixedRegistryGetOrRegister(t *testing.T) {
|
||||
r := NewPrefixedRegistry("prefix.")
|
||||
|
||||
_ = r.GetOrRegister("foo", NewCounter())
|
||||
|
||||
i := 0
|
||||
r.Each(func(name string, m interface{}) {
|
||||
i++
|
||||
if name != "prefix.foo" {
|
||||
t.Fatal(name)
|
||||
}
|
||||
})
|
||||
if i != 1 {
|
||||
t.Fatal(i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrefixedRegistryRegister(t *testing.T) {
|
||||
r := NewPrefixedRegistry("prefix.")
|
||||
err := r.Register("foo", NewCounter())
|
||||
c := NewCounter()
|
||||
Register("bar", c)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
i := 0
|
||||
r.Each(func(name string, m interface{}) {
|
||||
i++
|
||||
if name != "prefix.foo" {
|
||||
t.Fatal(name)
|
||||
}
|
||||
})
|
||||
if i != 1 {
|
||||
t.Fatal(i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrefixedRegistryUnregister(t *testing.T) {
|
||||
r := NewPrefixedRegistry("prefix.")
|
||||
|
||||
_ = r.Register("foo", NewCounter())
|
||||
|
||||
i := 0
|
||||
r.Each(func(name string, m interface{}) {
|
||||
i++
|
||||
if name != "prefix.foo" {
|
||||
t.Fatal(name)
|
||||
}
|
||||
})
|
||||
if i != 1 {
|
||||
t.Fatal(i)
|
||||
}
|
||||
|
||||
r.Unregister("foo")
|
||||
|
||||
i = 0
|
||||
r.Each(func(name string, m interface{}) {
|
||||
i++
|
||||
})
|
||||
|
||||
if i != 0 {
|
||||
t.Fatal(i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrefixedRegistryGet(t *testing.T) {
|
||||
pr := NewPrefixedRegistry("prefix.")
|
||||
name := "foo"
|
||||
pr.Register(name, NewCounter())
|
||||
|
||||
fooCounter := pr.Get(name)
|
||||
if fooCounter == nil {
|
||||
t.Fatal(name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrefixedChildRegistryGet(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
pr := NewPrefixedChildRegistry(r, "prefix.")
|
||||
name := "foo"
|
||||
pr.Register(name, NewCounter())
|
||||
fooCounter := pr.Get(name)
|
||||
if fooCounter == nil {
|
||||
t.Fatal(name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestChildPrefixedRegistryRegister(t *testing.T) {
|
||||
r := NewPrefixedChildRegistry(DefaultRegistry, "prefix.")
|
||||
err := r.Register("foo", NewCounter())
|
||||
c := NewCounter()
|
||||
Register("bar", c)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
i := 0
|
||||
r.Each(func(name string, m interface{}) {
|
||||
i++
|
||||
if name != "prefix.foo" {
|
||||
t.Fatal(name)
|
||||
}
|
||||
})
|
||||
if i != 1 {
|
||||
t.Fatal(i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestChildPrefixedRegistryOfChildRegister(t *testing.T) {
|
||||
r := NewPrefixedChildRegistry(NewRegistry(), "prefix.")
|
||||
r2 := NewPrefixedChildRegistry(r, "prefix2.")
|
||||
err := r.Register("foo2", NewCounter())
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
err = r2.Register("baz", NewCounter())
|
||||
c := NewCounter()
|
||||
Register("bars", c)
|
||||
|
||||
i := 0
|
||||
r2.Each(func(name string, m interface{}) {
|
||||
i++
|
||||
if name != "prefix.prefix2.baz" {
|
||||
//t.Fatal(name)
|
||||
}
|
||||
})
|
||||
if i != 1 {
|
||||
t.Fatal(i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWalkRegistries(t *testing.T) {
|
||||
r := NewPrefixedChildRegistry(NewRegistry(), "prefix.")
|
||||
r2 := NewPrefixedChildRegistry(r, "prefix2.")
|
||||
err := r.Register("foo2", NewCounter())
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
err = r2.Register("baz", NewCounter())
|
||||
c := NewCounter()
|
||||
Register("bars", c)
|
||||
|
||||
_, prefix := findPrefix(r2, "")
|
||||
if "prefix.prefix2." != prefix {
|
||||
t.Fatal(prefix)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConcurrentRegistryAccess(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
|
||||
counter := NewCounter()
|
||||
|
||||
signalChan := make(chan struct{})
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < 10; i++ {
|
||||
wg.Add(1)
|
||||
go func(dowork chan struct{}) {
|
||||
defer wg.Done()
|
||||
iface := r.GetOrRegister("foo", counter)
|
||||
retCounter, ok := iface.(Counter)
|
||||
if !ok {
|
||||
t.Fatal("Expected a Counter type")
|
||||
}
|
||||
if retCounter != counter {
|
||||
t.Fatal("Counter references don't match")
|
||||
}
|
||||
}(signalChan)
|
||||
}
|
||||
|
||||
close(signalChan) // Closing will cause all go routines to execute at the same time
|
||||
wg.Wait() // Wait for all go routines to do their work
|
||||
|
||||
// At the end of the test we should still only have a single "foo" Counter
|
||||
i := 0
|
||||
r.Each(func(name string, iface interface{}) {
|
||||
i++
|
||||
if "foo" != name {
|
||||
t.Fatal(name)
|
||||
}
|
||||
if _, ok := iface.(Counter); !ok {
|
||||
t.Fatal(iface)
|
||||
}
|
||||
})
|
||||
if 1 != i {
|
||||
t.Fatal(i)
|
||||
}
|
||||
r.Unregister("foo")
|
||||
i = 0
|
||||
r.Each(func(string, interface{}) { i++ })
|
||||
if 0 != i {
|
||||
t.Fatal(i)
|
||||
}
|
||||
}
|
88
vendor/github.com/rcrowley/go-metrics/runtime_test.go
generated
vendored
88
vendor/github.com/rcrowley/go-metrics/runtime_test.go
generated
vendored
|
@ -1,88 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func BenchmarkRuntimeMemStats(b *testing.B) {
|
||||
r := NewRegistry()
|
||||
RegisterRuntimeMemStats(r)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
CaptureRuntimeMemStatsOnce(r)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuntimeMemStats(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
RegisterRuntimeMemStats(r)
|
||||
CaptureRuntimeMemStatsOnce(r)
|
||||
zero := runtimeMetrics.MemStats.PauseNs.Count() // Get a "zero" since GC may have run before these tests.
|
||||
runtime.GC()
|
||||
CaptureRuntimeMemStatsOnce(r)
|
||||
if count := runtimeMetrics.MemStats.PauseNs.Count(); 1 != count-zero {
|
||||
t.Fatal(count - zero)
|
||||
}
|
||||
runtime.GC()
|
||||
runtime.GC()
|
||||
CaptureRuntimeMemStatsOnce(r)
|
||||
if count := runtimeMetrics.MemStats.PauseNs.Count(); 3 != count-zero {
|
||||
t.Fatal(count - zero)
|
||||
}
|
||||
for i := 0; i < 256; i++ {
|
||||
runtime.GC()
|
||||
}
|
||||
CaptureRuntimeMemStatsOnce(r)
|
||||
if count := runtimeMetrics.MemStats.PauseNs.Count(); 259 != count-zero {
|
||||
t.Fatal(count - zero)
|
||||
}
|
||||
for i := 0; i < 257; i++ {
|
||||
runtime.GC()
|
||||
}
|
||||
CaptureRuntimeMemStatsOnce(r)
|
||||
if count := runtimeMetrics.MemStats.PauseNs.Count(); 515 != count-zero { // We lost one because there were too many GCs between captures.
|
||||
t.Fatal(count - zero)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuntimeMemStatsNumThread(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
RegisterRuntimeMemStats(r)
|
||||
CaptureRuntimeMemStatsOnce(r)
|
||||
|
||||
if value := runtimeMetrics.NumThread.Value(); value < 1 {
|
||||
t.Fatalf("got NumThread: %d, wanted at least 1", value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuntimeMemStatsBlocking(t *testing.T) {
|
||||
if g := runtime.GOMAXPROCS(0); g < 2 {
|
||||
t.Skipf("skipping TestRuntimeMemStatsBlocking with GOMAXPROCS=%d\n", g)
|
||||
}
|
||||
ch := make(chan int)
|
||||
go testRuntimeMemStatsBlocking(ch)
|
||||
var memStats runtime.MemStats
|
||||
t0 := time.Now()
|
||||
runtime.ReadMemStats(&memStats)
|
||||
t1 := time.Now()
|
||||
t.Log("i++ during runtime.ReadMemStats:", <-ch)
|
||||
go testRuntimeMemStatsBlocking(ch)
|
||||
d := t1.Sub(t0)
|
||||
t.Log(d)
|
||||
time.Sleep(d)
|
||||
t.Log("i++ during time.Sleep:", <-ch)
|
||||
}
|
||||
|
||||
func testRuntimeMemStatsBlocking(ch chan int) {
|
||||
i := 0
|
||||
for {
|
||||
select {
|
||||
case ch <- i:
|
||||
return
|
||||
default:
|
||||
i++
|
||||
}
|
||||
}
|
||||
}
|
363
vendor/github.com/rcrowley/go-metrics/sample_test.go
generated
vendored
363
vendor/github.com/rcrowley/go-metrics/sample_test.go
generated
vendored
|
@ -1,363 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Benchmark{Compute,Copy}{1000,1000000} demonstrate that, even for relatively
|
||||
// expensive computations like Variance, the cost of copying the Sample, as
|
||||
// approximated by a make and copy, is much greater than the cost of the
|
||||
// computation for small samples and only slightly less for large samples.
|
||||
func BenchmarkCompute1000(b *testing.B) {
|
||||
s := make([]int64, 1000)
|
||||
for i := 0; i < len(s); i++ {
|
||||
s[i] = int64(i)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
SampleVariance(s)
|
||||
}
|
||||
}
|
||||
func BenchmarkCompute1000000(b *testing.B) {
|
||||
s := make([]int64, 1000000)
|
||||
for i := 0; i < len(s); i++ {
|
||||
s[i] = int64(i)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
SampleVariance(s)
|
||||
}
|
||||
}
|
||||
func BenchmarkCopy1000(b *testing.B) {
|
||||
s := make([]int64, 1000)
|
||||
for i := 0; i < len(s); i++ {
|
||||
s[i] = int64(i)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
sCopy := make([]int64, len(s))
|
||||
copy(sCopy, s)
|
||||
}
|
||||
}
|
||||
func BenchmarkCopy1000000(b *testing.B) {
|
||||
s := make([]int64, 1000000)
|
||||
for i := 0; i < len(s); i++ {
|
||||
s[i] = int64(i)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
sCopy := make([]int64, len(s))
|
||||
copy(sCopy, s)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkExpDecaySample257(b *testing.B) {
|
||||
benchmarkSample(b, NewExpDecaySample(257, 0.015))
|
||||
}
|
||||
|
||||
func BenchmarkExpDecaySample514(b *testing.B) {
|
||||
benchmarkSample(b, NewExpDecaySample(514, 0.015))
|
||||
}
|
||||
|
||||
func BenchmarkExpDecaySample1028(b *testing.B) {
|
||||
benchmarkSample(b, NewExpDecaySample(1028, 0.015))
|
||||
}
|
||||
|
||||
func BenchmarkUniformSample257(b *testing.B) {
|
||||
benchmarkSample(b, NewUniformSample(257))
|
||||
}
|
||||
|
||||
func BenchmarkUniformSample514(b *testing.B) {
|
||||
benchmarkSample(b, NewUniformSample(514))
|
||||
}
|
||||
|
||||
func BenchmarkUniformSample1028(b *testing.B) {
|
||||
benchmarkSample(b, NewUniformSample(1028))
|
||||
}
|
||||
|
||||
func TestExpDecaySample10(t *testing.T) {
|
||||
rand.Seed(1)
|
||||
s := NewExpDecaySample(100, 0.99)
|
||||
for i := 0; i < 10; i++ {
|
||||
s.Update(int64(i))
|
||||
}
|
||||
if size := s.Count(); 10 != size {
|
||||
t.Errorf("s.Count(): 10 != %v\n", size)
|
||||
}
|
||||
if size := s.Size(); 10 != size {
|
||||
t.Errorf("s.Size(): 10 != %v\n", size)
|
||||
}
|
||||
if l := len(s.Values()); 10 != l {
|
||||
t.Errorf("len(s.Values()): 10 != %v\n", l)
|
||||
}
|
||||
for _, v := range s.Values() {
|
||||
if v > 10 || v < 0 {
|
||||
t.Errorf("out of range [0, 10): %v\n", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpDecaySample100(t *testing.T) {
|
||||
rand.Seed(1)
|
||||
s := NewExpDecaySample(1000, 0.01)
|
||||
for i := 0; i < 100; i++ {
|
||||
s.Update(int64(i))
|
||||
}
|
||||
if size := s.Count(); 100 != size {
|
||||
t.Errorf("s.Count(): 100 != %v\n", size)
|
||||
}
|
||||
if size := s.Size(); 100 != size {
|
||||
t.Errorf("s.Size(): 100 != %v\n", size)
|
||||
}
|
||||
if l := len(s.Values()); 100 != l {
|
||||
t.Errorf("len(s.Values()): 100 != %v\n", l)
|
||||
}
|
||||
for _, v := range s.Values() {
|
||||
if v > 100 || v < 0 {
|
||||
t.Errorf("out of range [0, 100): %v\n", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpDecaySample1000(t *testing.T) {
|
||||
rand.Seed(1)
|
||||
s := NewExpDecaySample(100, 0.99)
|
||||
for i := 0; i < 1000; i++ {
|
||||
s.Update(int64(i))
|
||||
}
|
||||
if size := s.Count(); 1000 != size {
|
||||
t.Errorf("s.Count(): 1000 != %v\n", size)
|
||||
}
|
||||
if size := s.Size(); 100 != size {
|
||||
t.Errorf("s.Size(): 100 != %v\n", size)
|
||||
}
|
||||
if l := len(s.Values()); 100 != l {
|
||||
t.Errorf("len(s.Values()): 100 != %v\n", l)
|
||||
}
|
||||
for _, v := range s.Values() {
|
||||
if v > 1000 || v < 0 {
|
||||
t.Errorf("out of range [0, 1000): %v\n", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This test makes sure that the sample's priority is not amplified by using
|
||||
// nanosecond duration since start rather than second duration since start.
|
||||
// The priority becomes +Inf quickly after starting if this is done,
|
||||
// effectively freezing the set of samples until a rescale step happens.
|
||||
func TestExpDecaySampleNanosecondRegression(t *testing.T) {
|
||||
rand.Seed(1)
|
||||
s := NewExpDecaySample(100, 0.99)
|
||||
for i := 0; i < 100; i++ {
|
||||
s.Update(10)
|
||||
}
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
for i := 0; i < 100; i++ {
|
||||
s.Update(20)
|
||||
}
|
||||
v := s.Values()
|
||||
avg := float64(0)
|
||||
for i := 0; i < len(v); i++ {
|
||||
avg += float64(v[i])
|
||||
}
|
||||
avg /= float64(len(v))
|
||||
if avg > 16 || avg < 14 {
|
||||
t.Errorf("out of range [14, 16]: %v\n", avg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpDecaySampleRescale(t *testing.T) {
|
||||
s := NewExpDecaySample(2, 0.001).(*ExpDecaySample)
|
||||
s.update(time.Now(), 1)
|
||||
s.update(time.Now().Add(time.Hour+time.Microsecond), 1)
|
||||
for _, v := range s.values.Values() {
|
||||
if v.k == 0.0 {
|
||||
t.Fatal("v.k == 0.0")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpDecaySampleSnapshot(t *testing.T) {
|
||||
now := time.Now()
|
||||
rand.Seed(1)
|
||||
s := NewExpDecaySample(100, 0.99)
|
||||
for i := 1; i <= 10000; i++ {
|
||||
s.(*ExpDecaySample).update(now.Add(time.Duration(i)), int64(i))
|
||||
}
|
||||
snapshot := s.Snapshot()
|
||||
s.Update(1)
|
||||
testExpDecaySampleStatistics(t, snapshot)
|
||||
}
|
||||
|
||||
func TestExpDecaySampleStatistics(t *testing.T) {
|
||||
now := time.Now()
|
||||
rand.Seed(1)
|
||||
s := NewExpDecaySample(100, 0.99)
|
||||
for i := 1; i <= 10000; i++ {
|
||||
s.(*ExpDecaySample).update(now.Add(time.Duration(i)), int64(i))
|
||||
}
|
||||
testExpDecaySampleStatistics(t, s)
|
||||
}
|
||||
|
||||
func TestUniformSample(t *testing.T) {
|
||||
rand.Seed(1)
|
||||
s := NewUniformSample(100)
|
||||
for i := 0; i < 1000; i++ {
|
||||
s.Update(int64(i))
|
||||
}
|
||||
if size := s.Count(); 1000 != size {
|
||||
t.Errorf("s.Count(): 1000 != %v\n", size)
|
||||
}
|
||||
if size := s.Size(); 100 != size {
|
||||
t.Errorf("s.Size(): 100 != %v\n", size)
|
||||
}
|
||||
if l := len(s.Values()); 100 != l {
|
||||
t.Errorf("len(s.Values()): 100 != %v\n", l)
|
||||
}
|
||||
for _, v := range s.Values() {
|
||||
if v > 1000 || v < 0 {
|
||||
t.Errorf("out of range [0, 100): %v\n", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUniformSampleIncludesTail(t *testing.T) {
|
||||
rand.Seed(1)
|
||||
s := NewUniformSample(100)
|
||||
max := 100
|
||||
for i := 0; i < max; i++ {
|
||||
s.Update(int64(i))
|
||||
}
|
||||
v := s.Values()
|
||||
sum := 0
|
||||
exp := (max - 1) * max / 2
|
||||
for i := 0; i < len(v); i++ {
|
||||
sum += int(v[i])
|
||||
}
|
||||
if exp != sum {
|
||||
t.Errorf("sum: %v != %v\n", exp, sum)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUniformSampleSnapshot(t *testing.T) {
|
||||
s := NewUniformSample(100)
|
||||
for i := 1; i <= 10000; i++ {
|
||||
s.Update(int64(i))
|
||||
}
|
||||
snapshot := s.Snapshot()
|
||||
s.Update(1)
|
||||
testUniformSampleStatistics(t, snapshot)
|
||||
}
|
||||
|
||||
func TestUniformSampleStatistics(t *testing.T) {
|
||||
rand.Seed(1)
|
||||
s := NewUniformSample(100)
|
||||
for i := 1; i <= 10000; i++ {
|
||||
s.Update(int64(i))
|
||||
}
|
||||
testUniformSampleStatistics(t, s)
|
||||
}
|
||||
|
||||
func benchmarkSample(b *testing.B, s Sample) {
|
||||
var memStats runtime.MemStats
|
||||
runtime.ReadMemStats(&memStats)
|
||||
pauseTotalNs := memStats.PauseTotalNs
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
s.Update(1)
|
||||
}
|
||||
b.StopTimer()
|
||||
runtime.GC()
|
||||
runtime.ReadMemStats(&memStats)
|
||||
b.Logf("GC cost: %d ns/op", int(memStats.PauseTotalNs-pauseTotalNs)/b.N)
|
||||
}
|
||||
|
||||
func testExpDecaySampleStatistics(t *testing.T, s Sample) {
|
||||
if count := s.Count(); 10000 != count {
|
||||
t.Errorf("s.Count(): 10000 != %v\n", count)
|
||||
}
|
||||
if min := s.Min(); 107 != min {
|
||||
t.Errorf("s.Min(): 107 != %v\n", min)
|
||||
}
|
||||
if max := s.Max(); 10000 != max {
|
||||
t.Errorf("s.Max(): 10000 != %v\n", max)
|
||||
}
|
||||
if mean := s.Mean(); 4965.98 != mean {
|
||||
t.Errorf("s.Mean(): 4965.98 != %v\n", mean)
|
||||
}
|
||||
if stdDev := s.StdDev(); 2959.825156930727 != stdDev {
|
||||
t.Errorf("s.StdDev(): 2959.825156930727 != %v\n", stdDev)
|
||||
}
|
||||
ps := s.Percentiles([]float64{0.5, 0.75, 0.99})
|
||||
if 4615 != ps[0] {
|
||||
t.Errorf("median: 4615 != %v\n", ps[0])
|
||||
}
|
||||
if 7672 != ps[1] {
|
||||
t.Errorf("75th percentile: 7672 != %v\n", ps[1])
|
||||
}
|
||||
if 9998.99 != ps[2] {
|
||||
t.Errorf("99th percentile: 9998.99 != %v\n", ps[2])
|
||||
}
|
||||
}
|
||||
|
||||
func testUniformSampleStatistics(t *testing.T, s Sample) {
|
||||
if count := s.Count(); 10000 != count {
|
||||
t.Errorf("s.Count(): 10000 != %v\n", count)
|
||||
}
|
||||
if min := s.Min(); 37 != min {
|
||||
t.Errorf("s.Min(): 37 != %v\n", min)
|
||||
}
|
||||
if max := s.Max(); 9989 != max {
|
||||
t.Errorf("s.Max(): 9989 != %v\n", max)
|
||||
}
|
||||
if mean := s.Mean(); 4748.14 != mean {
|
||||
t.Errorf("s.Mean(): 4748.14 != %v\n", mean)
|
||||
}
|
||||
if stdDev := s.StdDev(); 2826.684117548333 != stdDev {
|
||||
t.Errorf("s.StdDev(): 2826.684117548333 != %v\n", stdDev)
|
||||
}
|
||||
ps := s.Percentiles([]float64{0.5, 0.75, 0.99})
|
||||
if 4599 != ps[0] {
|
||||
t.Errorf("median: 4599 != %v\n", ps[0])
|
||||
}
|
||||
if 7380.5 != ps[1] {
|
||||
t.Errorf("75th percentile: 7380.5 != %v\n", ps[1])
|
||||
}
|
||||
if 9986.429999999998 != ps[2] {
|
||||
t.Errorf("99th percentile: 9986.429999999998 != %v\n", ps[2])
|
||||
}
|
||||
}
|
||||
|
||||
// TestUniformSampleConcurrentUpdateCount would expose data race problems with
|
||||
// concurrent Update and Count calls on Sample when test is called with -race
|
||||
// argument
|
||||
func TestUniformSampleConcurrentUpdateCount(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping in short mode")
|
||||
}
|
||||
s := NewUniformSample(100)
|
||||
for i := 0; i < 100; i++ {
|
||||
s.Update(int64(i))
|
||||
}
|
||||
quit := make(chan struct{})
|
||||
go func() {
|
||||
t := time.NewTicker(10 * time.Millisecond)
|
||||
for {
|
||||
select {
|
||||
case <-t.C:
|
||||
s.Update(rand.Int63())
|
||||
case <-quit:
|
||||
t.Stop()
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
for i := 0; i < 1000; i++ {
|
||||
s.Count()
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
quit <- struct{}{}
|
||||
}
|
101
vendor/github.com/rcrowley/go-metrics/timer_test.go
generated
vendored
101
vendor/github.com/rcrowley/go-metrics/timer_test.go
generated
vendored
|
@ -1,101 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func BenchmarkTimer(b *testing.B) {
|
||||
tm := NewTimer()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
tm.Update(1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrRegisterTimer(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
NewRegisteredTimer("foo", r).Update(47)
|
||||
if tm := GetOrRegisterTimer("foo", r); 1 != tm.Count() {
|
||||
t.Fatal(tm)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimerExtremes(t *testing.T) {
|
||||
tm := NewTimer()
|
||||
tm.Update(math.MaxInt64)
|
||||
tm.Update(0)
|
||||
if stdDev := tm.StdDev(); 4.611686018427388e+18 != stdDev {
|
||||
t.Errorf("tm.StdDev(): 4.611686018427388e+18 != %v\n", stdDev)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimerStop(t *testing.T) {
|
||||
l := len(arbiter.meters)
|
||||
tm := NewTimer()
|
||||
if len(arbiter.meters) != l+1 {
|
||||
t.Errorf("arbiter.meters: %d != %d\n", l+1, len(arbiter.meters))
|
||||
}
|
||||
tm.Stop()
|
||||
if len(arbiter.meters) != l {
|
||||
t.Errorf("arbiter.meters: %d != %d\n", l, len(arbiter.meters))
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimerFunc(t *testing.T) {
|
||||
tm := NewTimer()
|
||||
tm.Time(func() { time.Sleep(50e6) })
|
||||
if max := tm.Max(); 45e6 > max || max > 55e6 {
|
||||
t.Errorf("tm.Max(): 45e6 > %v || %v > 55e6\n", max, max)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimerZero(t *testing.T) {
|
||||
tm := NewTimer()
|
||||
if count := tm.Count(); 0 != count {
|
||||
t.Errorf("tm.Count(): 0 != %v\n", count)
|
||||
}
|
||||
if min := tm.Min(); 0 != min {
|
||||
t.Errorf("tm.Min(): 0 != %v\n", min)
|
||||
}
|
||||
if max := tm.Max(); 0 != max {
|
||||
t.Errorf("tm.Max(): 0 != %v\n", max)
|
||||
}
|
||||
if mean := tm.Mean(); 0.0 != mean {
|
||||
t.Errorf("tm.Mean(): 0.0 != %v\n", mean)
|
||||
}
|
||||
if stdDev := tm.StdDev(); 0.0 != stdDev {
|
||||
t.Errorf("tm.StdDev(): 0.0 != %v\n", stdDev)
|
||||
}
|
||||
ps := tm.Percentiles([]float64{0.5, 0.75, 0.99})
|
||||
if 0.0 != ps[0] {
|
||||
t.Errorf("median: 0.0 != %v\n", ps[0])
|
||||
}
|
||||
if 0.0 != ps[1] {
|
||||
t.Errorf("75th percentile: 0.0 != %v\n", ps[1])
|
||||
}
|
||||
if 0.0 != ps[2] {
|
||||
t.Errorf("99th percentile: 0.0 != %v\n", ps[2])
|
||||
}
|
||||
if rate1 := tm.Rate1(); 0.0 != rate1 {
|
||||
t.Errorf("tm.Rate1(): 0.0 != %v\n", rate1)
|
||||
}
|
||||
if rate5 := tm.Rate5(); 0.0 != rate5 {
|
||||
t.Errorf("tm.Rate5(): 0.0 != %v\n", rate5)
|
||||
}
|
||||
if rate15 := tm.Rate15(); 0.0 != rate15 {
|
||||
t.Errorf("tm.Rate15(): 0.0 != %v\n", rate15)
|
||||
}
|
||||
if rateMean := tm.RateMean(); 0.0 != rateMean {
|
||||
t.Errorf("tm.RateMean(): 0.0 != %v\n", rateMean)
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleGetOrRegisterTimer() {
|
||||
m := "account.create.latency"
|
||||
t := GetOrRegisterTimer(m, nil)
|
||||
t.Update(47)
|
||||
fmt.Println(t.Max()) // Output: 47
|
||||
}
|
22
vendor/github.com/rcrowley/go-metrics/writer_test.go
generated
vendored
22
vendor/github.com/rcrowley/go-metrics/writer_test.go
generated
vendored
|
@ -1,22 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMetricsSorting(t *testing.T) {
|
||||
var namedMetrics = namedMetricSlice{
|
||||
{name: "zzz"},
|
||||
{name: "bbb"},
|
||||
{name: "fff"},
|
||||
{name: "ggg"},
|
||||
}
|
||||
|
||||
sort.Sort(namedMetrics)
|
||||
for i, name := range []string{"bbb", "fff", "ggg", "zzz"} {
|
||||
if namedMetrics[i].name != name {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue