MCPcopy
hub / github.com/grafana/tempo / TestPublish

Function TestPublish

pkg/hedgedmetrics/metrics_test.go:70–100  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

68}
69
70func TestPublish(t *testing.T) {
71 ctr := prometheus.NewCounter(prometheus.CounterOpts{Name: test.RandomString()})
72 stats := &MockStatsProvider{}
73
74 publishWithDuration(stats, ctr, 10*time.Millisecond)
75
76 require.Equal(t, 0.0, ctrVal(t, ctr))
77
78 // Set initial stats values
79 stats.SetStats(5, 5)
80 time.Sleep(30 * time.Millisecond)
81 require.Equal(t, 0.0, ctrVal(t, ctr))
82
83 stats.SetStats(15, 10)
84 time.Sleep(30 * time.Millisecond)
85 require.Equal(t, 5.0, ctrVal(t, ctr))
86
87 stats.SetStats(28, 20)
88 time.Sleep(30 * time.Millisecond)
89 require.Equal(t, 8.0, ctrVal(t, ctr))
90
91 stats.SetStats(38, 25)
92 time.Sleep(30 * time.Millisecond)
93 require.Equal(t, 13.0, ctrVal(t, ctr))
94
95 time.Sleep(30 * time.Millisecond)
96
97 // counter doesn't increase if stats stay same
98 time.Sleep(30 * time.Millisecond)
99 require.Equal(t, 13.0, ctrVal(t, ctr))
100}
101
102func ctrVal(t *testing.T, ctr prometheus.Counter) float64 {
103 t.Helper()

Callers

nothing calls this directly

Calls 7

SetStatsMethod · 0.95
RandomStringFunction · 0.92
publishWithDurationFunction · 0.85
ctrValFunction · 0.85
NewCounterMethod · 0.65
SleepMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected