|
| 1 | +// Copyright (c) 2026 Uber Technologies, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package metrics |
| 16 | + |
| 17 | +import ( |
| 18 | + "errors" |
| 19 | + "testing" |
| 20 | + "time" |
| 21 | + |
| 22 | + "github.com/stretchr/testify/assert" |
| 23 | + "github.com/uber-go/tally" |
| 24 | +) |
| 25 | + |
| 26 | +func TestRecordRequestSuccess(t *testing.T) { |
| 27 | + s := tally.NewTestScope("", nil) |
| 28 | + RecordRequest(New(s), OpGetTargetGraph, 5*time.Millisecond, nil) |
| 29 | + |
| 30 | + assert.Equal(t, int64(1), counterValue(t, s, OpGetTargetGraph+"."+Requests, map[string]string{ |
| 31 | + TagResult: string(ResultSuccess), |
| 32 | + })) |
| 33 | + assert.Equal(t, 1, histogramDurationSamples(t, s, OpGetTargetGraph+"."+TotalDuration, map[string]string{})) |
| 34 | +} |
| 35 | + |
| 36 | +func TestRecordRequestFailure(t *testing.T) { |
| 37 | + s := tally.NewTestScope("", nil) |
| 38 | + RecordRequest(New(s), OpGetTargetGraph, time.Millisecond, errors.New("boom")) |
| 39 | + |
| 40 | + assert.Equal(t, int64(1), counterValue(t, s, OpGetTargetGraph+"."+Requests, map[string]string{ |
| 41 | + TagResult: string(ResultFail), |
| 42 | + })) |
| 43 | +} |
0 commit comments