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

fix autoscaler cleanup on tests failure #474

Merged
merged 2 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions test/e2e/fleetautoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ func TestAutoscalerStressCreate(t *testing.T) {
r := rand.New(rand.NewSource(1783))

fleetautoscalers := alpha1.FleetAutoscalers(defaultNs)
for i := 0; i < 30; i++ {

for i := 0; i < 5; i++ {
fas := defaultFleetAutoscaler(flt)
bufferSize := r.Int31n(5)
minReplicas := r.Int31n(5)
Expand All @@ -141,33 +142,35 @@ func TestAutoscalerStressCreate(t *testing.T) {
fas.Spec.Policy.Buffer.MinReplicas <= fas.Spec.Policy.Buffer.MaxReplicas &&
(fas.Spec.Policy.Buffer.MinReplicas == 0 || fas.Spec.Policy.Buffer.MinReplicas >= bufferSize)

fas, err := fleetautoscalers.Create(fas)
if err == nil {
assert.True(t, valid,
fmt.Sprintf("FleetAutoscaler created even if the parameters are NOT valid: %d %d %d",
bufferSize,
fas.Spec.Policy.Buffer.MinReplicas,
fas.Spec.Policy.Buffer.MaxReplicas))

expectedReplicas := bufferSize
if expectedReplicas < fas.Spec.Policy.Buffer.MinReplicas {
expectedReplicas = fas.Spec.Policy.Buffer.MinReplicas
}
if expectedReplicas > fas.Spec.Policy.Buffer.MaxReplicas {
expectedReplicas = fas.Spec.Policy.Buffer.MaxReplicas
// create a closure to have defered delete func called on each loop iteration.
func() {
fas, err := fleetautoscalers.Create(fas)
if err == nil {
defer fleetautoscalers.Delete(fas.ObjectMeta.Name, nil) // nolint:errcheck
assert.True(t, valid,
fmt.Sprintf("FleetAutoscaler created even if the parameters are NOT valid: %d %d %d",
bufferSize,
fas.Spec.Policy.Buffer.MinReplicas,
fas.Spec.Policy.Buffer.MaxReplicas))

expectedReplicas := bufferSize
if expectedReplicas < fas.Spec.Policy.Buffer.MinReplicas {
expectedReplicas = fas.Spec.Policy.Buffer.MinReplicas
}
if expectedReplicas > fas.Spec.Policy.Buffer.MaxReplicas {
expectedReplicas = fas.Spec.Policy.Buffer.MaxReplicas
}
// the fleet autoscaler should scale the fleet now to expectedReplicas
err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(expectedReplicas))
assert.Nil(t, err, fmt.Sprintf("fleet did not sync with autoscaler, expected %d ready replicas", expectedReplicas))
} else {
assert.False(t, valid,
fmt.Sprintf("FleetAutoscaler NOT created even if the parameters are valid: %d %d %d (%s)",
bufferSize,
minReplicas,
maxReplicas, err))
}
// the fleet autoscaler should scale the fleet now to expectedReplicas
err = framework.WaitForFleetCondition(flt, e2e.FleetReadyCount(expectedReplicas))
assert.Nil(t, err, fmt.Sprintf("fleet did not sync with autoscaler, expected %d ready replicas", expectedReplicas))

fleetautoscalers.Delete(fas.ObjectMeta.Name, nil) // nolint:errcheck
} else {
assert.False(t, valid,
fmt.Sprintf("FleetAutoscaler NOT created even if the parameters are valid: %d %d %d",
bufferSize,
minReplicas,
maxReplicas))
}
}()
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ func (f *Framework) CleanUp(ns string) error {
return err
}

err = f.AgonesClient.StableV1alpha1().FleetAllocations(ns).DeleteCollection(&metav1.DeleteOptions{}, metav1.ListOptions{})
if err != nil {
return err
}

return f.AgonesClient.StableV1alpha1().GameServers(ns).
DeleteCollection(&metav1.DeleteOptions{}, metav1.ListOptions{})
}
Expand Down