Skip to content

Commit c685cf4

Browse files
authored
Fix flaky fuzz tests with count_values (#6474)
Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]>
1 parent b7c08b9 commit c685cf4

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

integration/query_fuzz_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,46 @@ var comparer = cmp.Comparer(func(x, y model.Value) bool {
801801
const fraction = 1.e-10 // 0.00000001%
802802
return cmp.Equal(l, r, cmpopts.EquateNaNs(), cmpopts.EquateApprox(fraction, epsilon))
803803
}
804+
// count_values returns a metrics with one label {"value": "1.012321"}
805+
compareValueMetrics := func(l, r model.Metric) (valueMetric bool, equals bool) {
806+
lLabels := model.LabelSet(l).Clone()
807+
rLabels := model.LabelSet(r).Clone()
808+
var (
809+
lVal, rVal model.LabelValue
810+
lFloat, rFloat float64
811+
ok bool
812+
err error
813+
)
814+
815+
if lVal, ok = lLabels["value"]; !ok {
816+
return false, false
817+
}
818+
819+
if rVal, ok = rLabels["value"]; !ok {
820+
return false, false
821+
}
822+
823+
if lFloat, err = strconv.ParseFloat(string(lVal), 64); err != nil {
824+
return false, false
825+
}
826+
if rFloat, err = strconv.ParseFloat(string(rVal), 64); err != nil {
827+
return false, false
828+
}
829+
830+
// Exclude the value label in comparison.
831+
delete(lLabels, "value")
832+
delete(rLabels, "value")
833+
834+
if !lLabels.Equal(rLabels) {
835+
return false, false
836+
}
837+
838+
return true, compareFloats(lFloat, rFloat)
839+
}
804840
compareMetrics := func(l, r model.Metric) bool {
841+
if valueMetric, equals := compareValueMetrics(l, r); valueMetric {
842+
return equals
843+
}
805844
return l.Equal(r)
806845
}
807846

0 commit comments

Comments
 (0)