Skip to content

Commit

Permalink
Adds sorting by name if values are equal to match the same sorting lo…
Browse files Browse the repository at this point in the history
…gic as the allocation cache

This should prevent the occasional edge case of equal gameserver available capacity in the gameserverallocation cache e2e test
  • Loading branch information
igooch committed Oct 16, 2023
1 parent 8459859 commit 48fd1ab
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions test/e2e/gameserverallocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 48fd1ab

Please sign in to comment.