diff --git a/pkg/gameserversets/controller_test.go b/pkg/gameserversets/controller_test.go index 8e16a62eaa..078b5c0df9 100644 --- a/pkg/gameserversets/controller_test.go +++ b/pkg/gameserversets/controller_test.go @@ -183,7 +183,9 @@ func TestComputeReconciliationAction(t *testing.T) { } 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) + 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") @@ -192,13 +194,31 @@ func TestComputeReconciliationAction(t *testing.T) { 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}} + t.Run("test distributed scale down", func(t *testing.T) { + gsSet := &v1alpha1.GameServerSet{Spec: v1alpha1.GameServerSetSpec{Replicas: 2, Scheduling: v1alpha1.Distributed}} + now := metav1.Now() + + list := []*v1alpha1.GameServer{ + {ObjectMeta: metav1.ObjectMeta{Name: "gs1", + CreationTimestamp: metav1.Time{Time: now.Add(10 * time.Second)}}, Status: v1alpha1.GameServerStatus{State: v1alpha1.GameServerStateReady}}, + {ObjectMeta: metav1.ObjectMeta{Name: "gs2", + CreationTimestamp: now}, Status: v1alpha1.GameServerStatus{State: v1alpha1.GameServerStateReady}}, + {ObjectMeta: metav1.ObjectMeta{Name: "gs3", + CreationTimestamp: metav1.Time{Time: now.Add(40 * time.Second)}}, Status: v1alpha1.GameServerStatus{State: v1alpha1.GameServerStateReady}}, + {ObjectMeta: metav1.ObjectMeta{Name: "gs4", + CreationTimestamp: metav1.Time{Time: now.Add(30 * time.Second)}}, Status: v1alpha1.GameServerStatus{State: v1alpha1.GameServerStateReady}}, + } + + toAdd, toDelete, isPartial := computeReconciliationAction(gsSet, list, map[string]gameservers.NodeCount{}, + int(gsSet.Spec.Replicas), 1000, 1000, 1000) - toAdd, toDelete, isPartial := computeReconciliationAction(gsSet, ) - })*/ + assert.Empty(t, toAdd) + assert.False(t, isPartial, "shouldn't be partial") + + assert.Len(t, toDelete, 2) + assert.Equal(t, "gs2", toDelete[0].ObjectMeta.Name) + assert.Equal(t, "gs1", toDelete[1].ObjectMeta.Name) + }) } func TestComputeStatus(t *testing.T) {