Skip to content

Commit

Permalink
Changes autoscaler tests to look for allocated and ready replicas
Browse files Browse the repository at this point in the history
instead of replicas
  • Loading branch information
igooch committed Oct 16, 2023
1 parent a4eedef commit 662a3e0
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions test/e2e/fleetautoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,12 +822,6 @@ func TestCounterAutoscaler(t *testing.T) {
Policy: autoscalingv1.FleetAutoscalerPolicy{
Type: autoscalingv1.CounterPolicyType,
},
Sync: &autoscalingv1.FleetAutoscalerSync{
Type: autoscalingv1.FixedIntervalSyncType,
FixedInterval: autoscalingv1.FixedIntervalSync{
Seconds: 30,
},
},
},
}
f(&fas.Spec.Policy)
Expand Down Expand Up @@ -977,12 +971,6 @@ func TestCounterAutoscalerAllocated(t *testing.T) {
Policy: autoscalingv1.FleetAutoscalerPolicy{
Type: autoscalingv1.CounterPolicyType,
},
Sync: &autoscalingv1.FleetAutoscalerSync{
Type: autoscalingv1.FixedIntervalSyncType,
FixedInterval: autoscalingv1.FixedIntervalSync{
Seconds: 30,
},
},
},
}
f(&fas.Spec.Policy)
Expand All @@ -997,9 +985,9 @@ func TestCounterAutoscalerAllocated(t *testing.T) {
}}}

testCases := map[string]struct {
fas *autoscalingv1.FleetAutoscaler
wantAllocatedGs int32 // Must be >= 0 && <= 3
wantReadyGs int32
fas *autoscalingv1.FleetAutoscaler
wantAllocatedGs int32 // Must be >= 0 && <= 3
wantReadyGs int32
}{
"Scale Down Buffer Percent": {
fas: counterFas(func(fap *autoscalingv1.FleetAutoscalerPolicy) {
Expand All @@ -1010,8 +998,8 @@ func TestCounterAutoscalerAllocated(t *testing.T) {
MaxCapacity: 100,
}
}),
wantAllocatedGs: 0,
wantReadyGs: 1,
wantAllocatedGs: 0,
wantReadyGs: 1,
},
"Scale Up Buffer Percent": {
fas: counterFas(func(fap *autoscalingv1.FleetAutoscalerPolicy) {
Expand All @@ -1022,15 +1010,16 @@ func TestCounterAutoscalerAllocated(t *testing.T) {
MaxCapacity: 100,
}
}),
wantAllocatedGs: 3,
wantReadyGs: 2,
wantAllocatedGs: 3,
wantReadyGs: 2,
},
}
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
// Allocate game servers, as Buffer Percent scales up (or down) based on allocated aggregate capacity
for i := int32(0); i < testCase.wantAllocatedGs; i++ {
framework.AgonesClient.AllocationV1().GameServerAllocations(flt.ObjectMeta.Namespace).Create(ctx, gsa.DeepCopy(), metav1.CreateOptions{})
_, err := framework.AgonesClient.AllocationV1().GameServerAllocations(flt.ObjectMeta.Namespace).Create(ctx, gsa.DeepCopy(), metav1.CreateOptions{})
require.NoError(t, err)
}
framework.AssertFleetCondition(t, flt, func(entry *logrus.Entry, fleet *agonesv1.Fleet) bool {
log.WithField("fleet", fmt.Sprintf("%+v", fleet.Status)).Info("Checking for game server allocations")
Expand Down Expand Up @@ -1061,7 +1050,9 @@ func TestCounterAutoscalerAllocated(t *testing.T) {

// Return to starting 3 ready replicas
framework.ScaleFleet(t, log, flt, flt.Spec.Replicas)
framework.AssertFleetCondition(t, flt, e2e.FleetReadyCount(flt.Spec.Replicas))
framework.AssertFleetCondition(t, flt, func(log *logrus.Entry, fleet *agonesv1.Fleet) bool {
return fleet.Status.AllocatedReplicas == 0 && fleet.Status.ReadyReplicas == flt.Spec.Replicas
})
})
}
}

0 comments on commit 662a3e0

Please sign in to comment.