Skip to content

Commit 75d6f56

Browse files
committed
add len to tests, it's too hard to estimate at a glance
1 parent fca356f commit 75d6f56

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

common/metrics/structured/histograms_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func TestHistogramValues(t *testing.T) {
1212
t.Run("default_1ms_to_10m", func(t *testing.T) {
13-
checkHistogram(t, Default1ms10m,
13+
checkHistogram(t, Default1ms10m, 81,
1414
`
1515
[0s]
1616
[1ms 1.189207ms 1.414213ms 1.681792ms]
@@ -36,7 +36,7 @@ func TestHistogramValues(t *testing.T) {
3636
`)
3737
})
3838
t.Run("high_1ms_to_24h", func(t *testing.T) {
39-
checkHistogram(t, High1ms24h,
39+
checkHistogram(t, High1ms24h, 113,
4040
`
4141
[0s]
4242
[1ms 1.189207ms 1.414213ms 1.681792ms]
@@ -70,7 +70,7 @@ func TestHistogramValues(t *testing.T) {
7070
`)
7171
})
7272
t.Run("mid_1ms_24h", func(t *testing.T) {
73-
checkHistogram(t, Mid1ms24h, `
73+
checkHistogram(t, Mid1ms24h, 57, `
7474
[0s]
7575
[1ms 1.414213ms]
7676
[2ms 2.828427ms]
@@ -112,7 +112,7 @@ func TestHistogramValues(t *testing.T) {
112112
// if this turns out to be expensive in Prometheus / etc, it's easy
113113
// enough to start the histogram at 8, and dual-emit a non-exponential
114114
// histogram for lower values.
115-
checkHistogram(t, Mid1To32k, `
115+
checkHistogram(t, Mid1To32k, 65, `
116116
[0]
117117
[1 1 1 1]
118118
[2 2 2 3]
@@ -133,7 +133,7 @@ func TestHistogramValues(t *testing.T) {
133133
`)
134134
})
135135
t.Run("low_cardinality_1ms_10s", func(t *testing.T) {
136-
checkHistogram(t, Low1ms10s, `
136+
checkHistogram(t, Low1ms10s, 33, `
137137
[0s]
138138
[1ms 1.414213ms]
139139
[2ms 2.828427ms]
@@ -156,7 +156,7 @@ func TestHistogramValues(t *testing.T) {
156156
}
157157

158158
// most histograms should pass this check, but fuzzy comparison is fine if needed for extreme cases.
159-
func checkHistogram[T any](t *testing.T, h histogrammy[T], expected string) {
159+
func checkHistogram[T any](t *testing.T, h histogrammy[T], length int, expected string) {
160160
var buf strings.Builder
161161
h.print(func(s string, a ...any) {
162162
str := fmt.Sprintf(s, a...)
@@ -167,6 +167,8 @@ func checkHistogram[T any](t *testing.T, h histogrammy[T], expected string) {
167167
t.Error("histogram definition changed, update the test if this is intended")
168168
}
169169

170+
assert.Equal(t, length, h.len(), "wrong number of buckets")
171+
170172
buckets := h.buckets()
171173
assert.EqualValues(t, 0, buckets[0], "first bucket should always be zero")
172174
for i := 1; i < len(buckets); i += h.width() {

0 commit comments

Comments
 (0)