(t *testing.T)
| 68 | } |
| 69 | |
| 70 | func 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 | |
| 102 | func ctrVal(t *testing.T, ctr prometheus.Counter) float64 { |
| 103 | t.Helper() |
nothing calls this directly
no test coverage detected