(t *testing.T)
| 110 | } |
| 111 | |
| 112 | func TestTimerConditionalTiming(t *testing.T) { |
| 113 | var ( |
| 114 | his = NewHistogram(HistogramOpts{ |
| 115 | Name: "test_histogram", |
| 116 | }) |
| 117 | timeMe = true |
| 118 | m = &dto.Metric{} |
| 119 | ) |
| 120 | |
| 121 | timedFunc := func() { |
| 122 | timer := NewTimer(ObserverFunc(func(v float64) { |
| 123 | if timeMe { |
| 124 | his.Observe(v) |
| 125 | } |
| 126 | })) |
| 127 | defer timer.ObserveDuration() |
| 128 | } |
| 129 | |
| 130 | timedFunc() // This will time. |
| 131 | his.Write(m) |
| 132 | if want, got := uint64(1), m.GetHistogram().GetSampleCount(); want != got { |
| 133 | t.Errorf("want %d observations for histogram, got %d", want, got) |
| 134 | } |
| 135 | |
| 136 | timeMe = false |
| 137 | timedFunc() // This will not time again. |
| 138 | m.Reset() |
| 139 | his.Write(m) |
| 140 | if want, got := uint64(1), m.GetHistogram().GetSampleCount(); want != got { |
| 141 | t.Errorf("want %d observations for histogram, got %d", want, got) |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | func TestTimerByOutcome(t *testing.T) { |
| 146 | var ( |
nothing calls this directly
no test coverage detected