From 48fd1ab04bc4e6e644a7dc4a870e1f34c0427183 Mon Sep 17 00:00:00 2001 From: Ivy Gooch Date: Mon, 16 Oct 2023 23:46:15 +0000 Subject: [PATCH] Adds sorting by name if values are equal to match the same sorting logic as the allocation cache This should prevent the occasional edge case of equal gameserver available capacity in the gameserverallocation cache e2e test --- test/e2e/gameserverallocation_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/e2e/gameserverallocation_test.go b/test/e2e/gameserverallocation_test.go index 616cedc965..fe6f18fe30 100644 --- a/test/e2e/gameserverallocation_test.go +++ b/test/e2e/gameserverallocation_test.go @@ -548,12 +548,18 @@ func TestCounterGameServerAllocationSorting(t *testing.T) { _, err := framework.AgonesClient.AgonesV1().GameServers(framework.Namespace).Update(ctx, gsCopy, metav1.UpdateOptions{}) require.NoError(t, err) } - // GameServers names sorted by available capacity, ascending. + // GameServers names sorted by available capacity, ascending. If available capacity is equal sort + // by name (as in pkg/gameserverallocations/allocation_cache.go) sortedGs := make([]string, 0, len(gameServers)) for gsName := range gameServers { sortedGs = append(sortedGs, gsName) } - sort.Slice(sortedGs, func(i, j int) bool { return gameServers[sortedGs[i]] < gameServers[sortedGs[j]] }) + sort.Slice(sortedGs, func(i, j int) bool { + if gameServers[sortedGs[i]] != gameServers[sortedGs[j]] { + return gameServers[sortedGs[i]] < gameServers[sortedGs[j]] + } + return sortedGs[i] < sortedGs[j] + }) fleetSelector := metav1.LabelSelector{MatchLabels: map[string]string{agonesv1.FleetNameLabel: flt.ObjectMeta.Name}} ready := agonesv1.GameServerStateReady