Skip to content

Commit

Permalink
Some more tests
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
markmandel committed Mar 12, 2019
1 parent e55ee80 commit 5cd2dc3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/gameserversets/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func computeReconciliationAction(gsSet *v1alpha1.GameServerSet, list []*v1alpha1
if gsSet.Spec.Scheduling == v1alpha1.Packed {
potentialDeletions = sortGameServersByLeastFullNodes(potentialDeletions, counts)
} else {
// TODO: sortGameServersByNewFirst
potentialDeletions = sortGameServersByNewFirst(potentialDeletions)
}

toDelete = append(toDelete, potentialDeletions[0:deleteCount]...)
Expand Down
26 changes: 20 additions & 6 deletions pkg/gameserversets/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,28 @@ func TestComputeReconciliationAction(t *testing.T) {
})
}

/*
TODO: make these tests work
t.Run("test packed scale down", func(t *testing.T) {
gsSet := &v1alpha1.GameServerSet{Spec: v1alpha1.GameServerSetSpec{Scheduling: v1alpha1.Packed}}
t.Run("test packed scale down", func(t *testing.T) {
gsSet := &v1alpha1.GameServerSet{Spec: v1alpha1.GameServerSetSpec{Replicas: 2, Scheduling: v1alpha1.Packed}}

toAdd, toDelete, isPartial := computeReconciliationAction(gsSet, )
})
list := []*v1alpha1.GameServer{
{ObjectMeta: metav1.ObjectMeta{Name: "gs1"}, Status: v1alpha1.GameServerStatus{State: v1alpha1.GameServerStateReady, NodeName: "node3"}},
{ObjectMeta: metav1.ObjectMeta{Name: "gs2"}, Status: v1alpha1.GameServerStatus{State: v1alpha1.GameServerStateReady, NodeName: "node1"}},
{ObjectMeta: metav1.ObjectMeta{Name: "gs3"}, Status: v1alpha1.GameServerStatus{State: v1alpha1.GameServerStateReady, NodeName: "node3"}},
{ObjectMeta: metav1.ObjectMeta{Name: "gs4"}, Status: v1alpha1.GameServerStatus{State: v1alpha1.GameServerStateReady, NodeName: ""}},
}

counts := map[string]gameservers.NodeCount{"node1": {Ready: 1}, "node3": {Ready: 2}}
toAdd, toDelete, isPartial := computeReconciliationAction(gsSet, list, counts, int(gsSet.Spec.Replicas), 1000, 1000, 1000)
assert.Empty(t, toAdd)
assert.False(t, isPartial, "shouldn't be partial")

assert.Len(t, toDelete, 2)
assert.Equal(t, "gs4", toDelete[0].ObjectMeta.Name)
assert.Equal(t, "gs2", toDelete[1].ObjectMeta.Name)
})

//TODO: make these tests work
/*
t.Run("test distributed scale down", func(t *testing.T) {
gsSet := &v1alpha1.GameServerSet{Spec: v1alpha1.GameServerSetSpec{Scheduling: v1alpha1.Packed}}
Expand Down

0 comments on commit 5cd2dc3

Please sign in to comment.