Skip to content

Commit

Permalink
Fix flaky fuzz tests with count_values (#6474)
Browse files Browse the repository at this point in the history
Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]>
  • Loading branch information
harry671003 authored Jan 3, 2025
1 parent b7c08b9 commit c685cf4
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions integration/query_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,46 @@ var comparer = cmp.Comparer(func(x, y model.Value) bool {
const fraction = 1.e-10 // 0.00000001%
return cmp.Equal(l, r, cmpopts.EquateNaNs(), cmpopts.EquateApprox(fraction, epsilon))
}
// count_values returns a metrics with one label {"value": "1.012321"}
compareValueMetrics := func(l, r model.Metric) (valueMetric bool, equals bool) {
lLabels := model.LabelSet(l).Clone()
rLabels := model.LabelSet(r).Clone()
var (
lVal, rVal model.LabelValue
lFloat, rFloat float64
ok bool
err error
)

if lVal, ok = lLabels["value"]; !ok {
return false, false
}

if rVal, ok = rLabels["value"]; !ok {
return false, false
}

if lFloat, err = strconv.ParseFloat(string(lVal), 64); err != nil {
return false, false
}
if rFloat, err = strconv.ParseFloat(string(rVal), 64); err != nil {
return false, false
}

// Exclude the value label in comparison.
delete(lLabels, "value")
delete(rLabels, "value")

if !lLabels.Equal(rLabels) {
return false, false
}

return true, compareFloats(lFloat, rFloat)
}
compareMetrics := func(l, r model.Metric) bool {
if valueMetric, equals := compareValueMetrics(l, r); valueMetric {
return equals
}
return l.Equal(r)
}

Expand Down

0 comments on commit c685cf4

Please sign in to comment.