From 62ed0250c3baf709699f68ad579d9ca42f1088c4 Mon Sep 17 00:00:00 2001 From: "Chris S. Kim" Date: Wed, 27 Jul 2022 11:06:20 -0400 Subject: [PATCH] Sort slice of ServiceNames deterministically --- agent/consul/state/peering.go | 4 +++- agent/proxycfg-glue/exported_peered_services_test.go | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/agent/consul/state/peering.go b/agent/consul/state/peering.go index a3529cbda6..4bf19de69a 100644 --- a/agent/consul/state/peering.go +++ b/agent/consul/state/peering.go @@ -353,7 +353,9 @@ func (s *Store) ExportedServicesForAllPeersByName(ws memdb.WatchSet, entMeta acl } m := list.ListAllDiscoveryChains() if len(m) > 0 { - out[peering.Name] = maps.SliceOfKeys(m) + sns := maps.SliceOfKeys[structs.ServiceName, structs.ExportedDiscoveryChainInfo](m) + sort.Sort(structs.ServiceList(sns)) + out[peering.Name] = sns } } diff --git a/agent/proxycfg-glue/exported_peered_services_test.go b/agent/proxycfg-glue/exported_peered_services_test.go index f0b41d9f30..552519bb17 100644 --- a/agent/proxycfg-glue/exported_peered_services_test.go +++ b/agent/proxycfg-glue/exported_peered_services_test.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/consul/agent/proxycfg" "github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/proto/pbpeering" + "github.com/hashicorp/consul/sdk/testutil" ) func TestServerExportedPeeredServices(t *testing.T) { @@ -59,7 +60,7 @@ func TestServerExportedPeeredServices(t *testing.T) { }) require.NoError(t, dataSource.Notify(ctx, &structs.DCSpecificRequest{}, "", eventCh)) - t.Run("initial state", func(t *testing.T) { + testutil.RunStep(t, "initial state", func(t *testing.T) { result := getEventResult[*structs.IndexedExportedServiceList](t, eventCh) require.Equal(t, map[string]structs.ServiceList{ @@ -69,7 +70,7 @@ func TestServerExportedPeeredServices(t *testing.T) { ) }) - t.Run("update exported services", func(t *testing.T) { + testutil.RunStep(t, "update exported services", func(t *testing.T) { require.NoError(t, store.EnsureConfigEntry(nextIndex(), &structs.ExportedServicesConfigEntry{ Name: "default", Services: []structs.ExportedService{