From bf1f4e4a246d1094eb9bf44b48b8793fb1df9413 Mon Sep 17 00:00:00 2001 From: Bjoern Rabenstein Date: Fri, 3 May 2019 22:25:32 +0200 Subject: [PATCH] Make TestCounterAddLarge more robust The previous `float64(math.MaxUint64 + 1)` is too close to `float64(math.MaxUint64)` to actually overflow as indended. The counter code is actually converting forward and backward and compare the original and twice-converted value. On most platform, this will create a deviation and thus trigger the expected behavior. By sheer "luck", one might end up with the same value and thus still use the uint64 representation. Which is OK within the precision we can expect. But it breaks the test. With this change, the next representable floating point value greater than the floating point value used to represent math.MaxUint64 is used. Signed-off-by: Bjoern Rabenstein --- prometheus/counter_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prometheus/counter_test.go b/prometheus/counter_test.go index 5062f51..fd98fb1 100644 --- a/prometheus/counter_test.go +++ b/prometheus/counter_test.go @@ -172,7 +172,7 @@ func TestCounterAddLarge(t *testing.T) { }).(*counter) // large overflows the underlying type and should therefore be stored in valBits. - large := float64(math.MaxUint64 + 1) + large := math.Nextafter(float64(math.MaxUint64), 1e20) counter.Add(large) if expected, got := large, math.Float64frombits(counter.valBits); expected != got { t.Errorf("valBits expected %f, got %f.", expected, got)