timer_test.go 586 B

12345678910111213141516171819202122232425
  1. package metrics
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/prometheus/client_golang/prometheus"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestEnd(t *testing.T) {
  9. m := prometheus.NewHistogramVec(
  10. prometheus.HistogramOpts{
  11. Namespace: "TestCallLatencyWithoutMeasurement",
  12. Name: "Latency",
  13. Buckets: prometheus.LinearBuckets(0, 50, 100),
  14. },
  15. []string{"key"},
  16. )
  17. timer := NewTimer(m, time.Millisecond, "key")
  18. assert.Equal(t, time.Duration(0), timer.End("dne"))
  19. timer.Start("test")
  20. assert.NotEqual(t, time.Duration(0), timer.End("test"))
  21. }