From 21bedae095ae18cf1c9891c7ef62411c6fbf4564 Mon Sep 17 00:00:00 2001 From: yeya24 Date: Sun, 7 Dec 2025 19:24:20 -0800 Subject: [PATCH] fix thanos query fuzz tests due to Inf and NaN Signed-off-by: yeya24 --- integration/query_fuzz_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/integration/query_fuzz_test.go b/integration/query_fuzz_test.go index 71c38335522..e338e6acda7 100644 --- a/integration/query_fuzz_test.go +++ b/integration/query_fuzz_test.go @@ -5,6 +5,7 @@ package integration import ( "context" "fmt" + "math" "math/rand" "os" "path" @@ -933,6 +934,23 @@ var comparer = cmp.Comparer(func(x, y model.Value) bool { return false } compareFloats := func(l, r float64) bool { + // Treat NaN as equal to +Inf and -Inf to reduce flakiness when comparing + // results between different engines (e.g., Thanos engine might return NaN + // while another engine returns +Inf or -Inf). + lIsNaN := math.IsNaN(l) + rIsNaN := math.IsNaN(r) + lIsInf := math.IsInf(l, 0) // 0 means check for both +Inf and -Inf + rIsInf := math.IsInf(r, 0) + + // If both are NaN, they're equal + if lIsNaN && rIsNaN { + return true + } + // If one is NaN and the other is Inf (either +Inf or -Inf), treat as equal + if (lIsNaN && rIsInf) || (lIsInf && rIsNaN) { + return true + } + const epsilon = 1e-6 const fraction = 1.e-10 // 0.00000001% return cmp.Equal(l, r, cmpopts.EquateNaNs(), cmpopts.EquateApprox(fraction, epsilon))