Skip to content

Commit f57a7c9

Browse files
authored
fix thanos query fuzz tests due to Inf and NaN (#7144)
Signed-off-by: yeya24 <[email protected]>
1 parent 56bc703 commit f57a7c9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

integration/query_fuzz_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package integration
55
import (
66
"context"
77
"fmt"
8+
"math"
89
"math/rand"
910
"os"
1011
"path"
@@ -933,6 +934,23 @@ var comparer = cmp.Comparer(func(x, y model.Value) bool {
933934
return false
934935
}
935936
compareFloats := func(l, r float64) bool {
937+
// Treat NaN as equal to +Inf and -Inf to reduce flakiness when comparing
938+
// results between different engines (e.g., Thanos engine might return NaN
939+
// while another engine returns +Inf or -Inf).
940+
lIsNaN := math.IsNaN(l)
941+
rIsNaN := math.IsNaN(r)
942+
lIsInf := math.IsInf(l, 0) // 0 means check for both +Inf and -Inf
943+
rIsInf := math.IsInf(r, 0)
944+
945+
// If both are NaN, they're equal
946+
if lIsNaN && rIsNaN {
947+
return true
948+
}
949+
// If one is NaN and the other is Inf (either +Inf or -Inf), treat as equal
950+
if (lIsNaN && rIsInf) || (lIsInf && rIsNaN) {
951+
return true
952+
}
953+
936954
const epsilon = 1e-6
937955
const fraction = 1.e-10 // 0.00000001%
938956
return cmp.Equal(l, r, cmpopts.EquateNaNs(), cmpopts.EquateApprox(fraction, epsilon))

0 commit comments

Comments
 (0)