From 552203da3b1d1a0626ca504ef55d7c25b1d60084 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Wed, 6 Dec 2023 19:55:56 +0100 Subject: [PATCH] walk: sort slices for reproducibility --- walk.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/walk.go b/walk.go index 0757fe8..305c134 100644 --- a/walk.go +++ b/walk.go @@ -4,6 +4,7 @@ import ( "fmt" "math/rand" "sort" + "strings" "time" "github.com/prometheus/prometheus/model/labels" @@ -244,6 +245,7 @@ func (s *PromQLSmith) walkCall(valueTypes ...parser.ValueType) parser.Expr { } } } + sort.Slice(funcs, func(i, j int) bool { return strings.Compare(funcs[i].Name, funcs[j].Name) < 0 }) expr.Func = funcs[s.rnd.Intn(len(funcs))] s.walkFuncArgs(expr) return expr @@ -383,6 +385,7 @@ func exprsFromValueTypes(valueTypes []parser.ValueType) []ExprType { for expr := range set { res = append(res, expr) } + sort.Slice(res, func(i, j int) bool { return res[i] < res[j] }) return res } @@ -407,6 +410,7 @@ func keepValueTypes(input []parser.ValueType, keep []parser.ValueType) []parser. out = append(out, vt) } } + sort.Slice(out, func(i, j int) bool { return out[i] < out[j] }) return out }