If PacketsSent is 0 we end up doing zero division when calculating packet loss in pinger.Statistics() which ends up reporting as NaN. This can be problematic if one were to take the pinger.Statistics struct and marshal it into json, which will end up failing altogether due to having a value of NaN. Ref: https://github.com/golang/go/issues/3480
Running the test I added in this branch without any other code change highlights this problem:
$ go test -v ./... -run ^TestStatisticsZeroDivision$
? github.com/prometheus-community/pro-bing/cmd/ping [no test files]
=== RUN TestStatisticsZeroDivision
ping_test.go:492: Expected 0, got NaN
--- FAIL: TestStatisticsZeroDivision (0.00s)
FAIL
FAIL github.com/prometheus-community/pro-bing 0.512s
FAIL
If
PacketsSent
is 0 we end up doing zero division when calculating packet loss inpinger.Statistics()
which ends up reporting asNaN
. This can be problematic if one were to take thepinger.Statistics
struct and marshal it into json, which will end up failing altogether due to having a value ofNaN
. Ref: https://github.com/golang/go/issues/3480Running the test I added in this branch without any other code change highlights this problem: