diff --git a/scrape/scrape_test.go b/scrape/scrape_test.go index ee8bfcef67..d28bd4ed18 100644 --- a/scrape/scrape_test.go +++ b/scrape/scrape_test.go @@ -36,6 +36,7 @@ import ( "github.com/gogo/protobuf/proto" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "github.com/grafana/regexp" "github.com/prometheus/client_golang/prometheus" prom_testutil "github.com/prometheus/client_golang/prometheus/testutil" @@ -1992,7 +1993,16 @@ func TestScrapeLoopAppend(t *testing.T) { func requireEqual(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) { t.Helper() testutil.RequireEqualWithOptions(t, expected, actual, - []cmp.Option{cmp.Comparer(equalFloatSamples), cmp.AllowUnexported(histogramSample{})}, + []cmp.Option{ + cmp.Comparer(equalFloatSamples), + cmp.AllowUnexported(histogramSample{}), + // StaleNaN samples are generated by iterating over a map, which means that the order + // of samples might be different on every test run. Sort series by label to avoid + // test failures because of that. + cmpopts.SortSlices(func(a, b floatSample) int { + return labels.Compare(a.metric, b.metric) + }), + }, msgAndArgs...) }