From 66ba4bcf959df66841f67254f3399991c2ed5216 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Fri, 10 Jan 2025 07:27:22 +0100 Subject: [PATCH] sorting for deterministic Signed-off-by: Andres Taylor --- go/test/vschemawrapper/vschema_wrapper.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/go/test/vschemawrapper/vschema_wrapper.go b/go/test/vschemawrapper/vschema_wrapper.go index 8c072d01e0e..27219c6a255 100644 --- a/go/test/vschemawrapper/vschema_wrapper.go +++ b/go/test/vschemawrapper/vschema_wrapper.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + "sort" "strings" "vitess.io/vitess/go/mysql/collations" @@ -300,11 +301,19 @@ func (vw *VSchemaWrapper) AnyKeyspace() (*vindexes.Keyspace, error) { return ks.Keyspace, nil } - for _, ks := range vw.V.Keyspaces { - return ks.Keyspace, nil + size := len(vw.V.Keyspaces) + if size == 0 { + return nil, errors.New("no keyspace found in vschema") + } + + // Find the first keyspace in the map alphabetically to get deterministic results + keys := make([]string, size) + for key := range vw.V.Keyspaces { + keys = append(keys, key) } + sort.Strings(keys) - return nil, errors.New("no keyspace found in vschema") + return vw.V.Keyspaces[keys[0]].Keyspace, nil } func (vw *VSchemaWrapper) FirstSortedKeyspace() (*vindexes.Keyspace, error) {