Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes flaky TestCounterGameServerAllocationSorting #3440

Merged
merged 1 commit into from
Oct 19, 2023

Conversation

igooch
Copy link
Collaborator

@igooch igooch commented Oct 19, 2023

What type of PR is this?

/kind cleanup

What this PR does / Why we need it:

This e2e test was occasionally flaking because the behavior it was meant to test (sorting by Counter Priority) comes after sorting by the number of gameservers on the node.

// ListSortedGameServers returns a list of the cached gameservers
// sorted by most allocated to least.
func (c *AllocationCache) ListSortedGameServers(gsa *allocationv1.GameServerAllocation) []*agonesv1.GameServer {
list := c.getGameServers()
if list == nil {
return []*agonesv1.GameServer{}
}
counts := c.counter.Counts()
sort.Slice(list, func(i, j int) bool {
gs1 := list[i]
gs2 := list[j]
// Search Allocated GameServers first.
if gs1.Status.State != gs2.Status.State {
return gs1.Status.State == agonesv1.GameServerStateAllocated
}
c1, ok := counts[gs1.Status.NodeName]
if !ok {
return false
}
c2, ok := counts[gs2.Status.NodeName]
if !ok {
return true
}
if c1.Allocated > c2.Allocated {
return true
}
if c1.Allocated < c2.Allocated {
return false
}
// prefer nodes that have the most Ready gameservers on them - they are most likely to be
// completely filled and least likely target for scale down.
if c1.Ready < c2.Ready {
return false
}
if c1.Ready > c2.Ready {
return true
}
// if player tracking is enabled, prefer game servers with the least amount of room left
if runtime.FeatureEnabled(runtime.FeaturePlayerAllocationFilter) {
if gs1.Status.Players != nil && gs2.Status.Players != nil {
cap1 := gs1.Status.Players.Capacity - gs1.Status.Players.Count
cap2 := gs2.Status.Players.Capacity - gs2.Status.Players.Count
// if they are equal, pass the comparison through.
if cap1 < cap2 {
return true
} else if cap2 < cap1 {
return false
}
}
}
// if we end up here, then break the tie with Counter or List Priority.
if runtime.FeatureEnabled(runtime.FeatureCountsAndLists) && (gsa != nil) {
for _, priority := range gsa.Spec.Priorities {
res := compareGameServers(&priority, gs1, gs2)
switch priority.Order {
case agonesv1.GameServerPriorityAscending:
if res == -1 {
return true
}
if res == 1 {
return false
}
case agonesv1.GameServerPriorityDescending:
if res == -1 {
return false
}
if res == 1 {
return true
}
}
}
}
// finally sort lexicographically, so we have a stable order
return gs1.GetObjectMeta().GetName() < gs2.GetObjectMeta().GetName()
})
return list
}

During e2e tests there may be gameservers from different tests scheduled onto the same node, so the number of game servers on the node are not always equal. We already test this sorting behavior in unit testing, so we are dropping this e2e test.

Which issue(s) this PR fixes:

Working on #2716

Special notes for your reviewer:

@github-actions github-actions bot added the kind/cleanup Refactoring code, fixing up documentation, etc label Oct 19, 2023
Copy link
Member

@markmandel markmandel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Better to test this kind of thing in Unit Tests (which we have).

@markmandel markmandel enabled auto-merge (squash) October 19, 2023 20:17
@google-oss-prow
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gongmax, igooch, markmandel

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 1719bbed-9588-4d16-a65a-601c33186c75

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/3440/head:pr_3440 && git checkout pr_3440
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.36.0-dev-6d387cd-amd64

@markmandel markmandel merged commit 05c97b3 into googleforgames:main Oct 19, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved kind/cleanup Refactoring code, fixing up documentation, etc lgtm size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants