Skip to content

Commit a692c49

Browse files
committed
mtypes: Add test to reproduce 0 divide error
This can be seen when the input doesn't have any summary metrics, as in this minimal example: $ ./mtypes < /dev/null -avalanche-flags-for-adjusted-series 10 ./mtypes < /dev/null -avalanche-flags-for-adjusted-series 10 Metric Type Metric Families Series (adjusted) Series (adjusted) % Average Buckets/Objectives --- --- --- --- --- * 0 0 (0) 100.000000 (100.000000) - Avalanche flags for the similar distribution to get to the adjusted series goal of: 10 panic: runtime error: integer divide by zero goroutine 1 [running]: main.computeAvalancheFlags(0x8a55a0?, {0x0, 0x0, 0x0, 0x0, 0x0}, 0xc0001239b0) [...]/avalanche/cmd/mtypes/main.go:127 +0xcbd main.main() [...]/avalanche/cmd/mtypes/main.go:81 +0x5c5 Add a test to repro it. Signed-off-by: Craig Ringer <[email protected]>
1 parent 278b90c commit a692c49

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cmd/mtypes/main_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,14 @@ func TestComputeAvalancheFlags(t *testing.T) {
11321132
"--metric-interval=0",
11331133
},
11341134
},
1135+
{
1136+
testName: "noInput",
1137+
avalancheFlagsForTotal: 1000,
1138+
statistics: map[dto.MetricType]stats{},
1139+
total: stats{},
1140+
expectedSum: 84,
1141+
expectedFlags: []string{},
1142+
},
11351143
} {
11361144
t.Run(tc.testName, func(t *testing.T) {
11371145
avalancheFlags, adjustedSum := computeAvalancheFlags(tc.avalancheFlagsForTotal, tc.total, tc.statistics)

0 commit comments

Comments
 (0)