Skip to content

Commit

Permalink
Fixes for flaky e2e tests.
Browse files Browse the repository at this point in the history
Some more fixes for the flaky e2e tests.
  • Loading branch information
markmandel committed Jan 24, 2019
1 parent 625728e commit 534d2f3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
30 changes: 20 additions & 10 deletions test/e2e/fleetautoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ import (
"github.com/stretchr/testify/assert"
admregv1b "k8s.io/api/admissionregistration/v1beta1"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/wait"
)

var deletePropagationForeground = metav1.DeletePropagationForeground
Expand Down Expand Up @@ -246,11 +248,9 @@ func TestAutoscalerWebhook(t *testing.T) {
// if we could not create the webhook pod, there is no point going further
assert.FailNow(t, "Failed creating webhook pod, aborting TestAutoscalerWebhook")
}
svc.ObjectMeta.Name = ""
svc.ObjectMeta.GenerateName = "test-service-"

// since we're using statically-named service, perform a best-effort delete of a previous service
framework.KubeClient.CoreV1().Services(defaultNs).Delete(svc.ObjectMeta.Name, waitForDeletion) // nolint:errcheck

svc, err = framework.KubeClient.CoreV1().Services(defaultNs).Create(svc)
if assert.Nil(t, err) {
defer framework.KubeClient.CoreV1().Services(defaultNs).Delete(svc.ObjectMeta.Name, nil) // nolint:errcheck
Expand Down Expand Up @@ -388,7 +388,7 @@ func TestTlsWebhook(t *testing.T) {
secr.Data[corev1.TLSPrivateKeyKey] = []byte(webhookKey)

secrets := framework.KubeClient.CoreV1().Secrets(defaultNs)
secr, err := secrets.Create(secr)
secr, err := secrets.Create(secr.DeepCopy())
if assert.Nil(t, err) {
defer secrets.Delete(secr.ObjectMeta.Name, nil) // nolint:errcheck
}
Expand All @@ -407,7 +407,7 @@ func TestTlsWebhook(t *testing.T) {
Name: "secret-volume",
MountPath: "/home/service/certs",
}}
pod, err = framework.KubeClient.CoreV1().Pods(defaultNs).Create(pod)
pod, err = framework.KubeClient.CoreV1().Pods(defaultNs).Create(pod.DeepCopy())
if assert.Nil(t, err) {
defer framework.KubeClient.CoreV1().Pods(defaultNs).Delete(pod.ObjectMeta.Name, nil) // nolint:errcheck
} else {
Expand All @@ -416,9 +416,19 @@ func TestTlsWebhook(t *testing.T) {
}

// since we're using statically-named service, perform a best-effort delete of a previous service
framework.KubeClient.CoreV1().Services(defaultNs).Delete(svc.ObjectMeta.Name, waitForDeletion) // nolint:errcheck
err = framework.KubeClient.CoreV1().Services(defaultNs).Delete(svc.ObjectMeta.Name, waitForDeletion)
if err != nil {
assert.True(t, k8serrors.IsNotFound(err))
}

svc, err = framework.KubeClient.CoreV1().Services(defaultNs).Create(svc)
// making sure the service is really gone.
err = wait.PollImmediate(2*time.Second, time.Minute, func() (bool, error) {
_, err := framework.KubeClient.CoreV1().Services(defaultNs).Get(svc.ObjectMeta.Name, metav1.GetOptions{})
return k8serrors.IsNotFound(err), nil
})
assert.Nil(t, err)

svc, err = framework.KubeClient.CoreV1().Services(defaultNs).Create(svc.DeepCopy())
if assert.Nil(t, err) {
defer framework.KubeClient.CoreV1().Services(defaultNs).Delete(svc.ObjectMeta.Name, nil) // nolint:errcheck
} else {
Expand All @@ -431,7 +441,7 @@ func TestTlsWebhook(t *testing.T) {
flt := defaultFleet()
initialReplicasCount := int32(1)
flt.Spec.Replicas = initialReplicasCount
flt, err = fleets.Create(flt)
flt, err = fleets.Create(flt.DeepCopy())
if assert.Nil(t, err) {
defer fleets.Delete(flt.ObjectMeta.Name, nil) // nolint:errcheck
}
Expand All @@ -453,15 +463,15 @@ func TestTlsWebhook(t *testing.T) {
},
CABundle: []byte(caPem),
}
fas, err = fleetautoscalers.Create(fas)
fas, err = fleetautoscalers.Create(fas.DeepCopy())
if assert.Nil(t, err) {
defer fleetautoscalers.Delete(fas.ObjectMeta.Name, nil) // nolint:errcheck
} else {
// if we could not create the autoscaler, their is no point going further
assert.FailNow(t, "Failed creating autoscaler, aborting TestTlsWebhook")
}
fa := getAllocation(flt)
fa, err = alpha1.FleetAllocations(defaultNs).Create(fa)
fa, err = alpha1.FleetAllocations(defaultNs).Create(fa.DeepCopy())
assert.Nil(t, err)
assert.Equal(t, v1alpha1.GameServerStateAllocated, fa.Status.GameServer.Status.State)
err = framework.WaitForFleetCondition(flt, func(fleet *v1alpha1.Fleet) bool {
Expand Down
18 changes: 13 additions & 5 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,31 @@ func (f *Framework) WaitForFleetGameServersCondition(flt *v1alpha1.Fleet, cond f
// CleanUp Delete all Agones resources in a given namespace
func (f *Framework) CleanUp(ns string) error {
logrus.Info("Done. Cleaning up now.")
err := f.AgonesClient.StableV1alpha1().Fleets(ns).DeleteCollection(&metav1.DeleteOptions{}, metav1.ListOptions{})
alpha1 := f.AgonesClient.StableV1alpha1()
do := &metav1.DeleteOptions{}
options := metav1.ListOptions{}
err := alpha1.Fleets(ns).DeleteCollection(do, options)
if err != nil {
return err
}

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

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

return f.AgonesClient.StableV1alpha1().GameServers(ns).
DeleteCollection(&metav1.DeleteOptions{}, metav1.ListOptions{})
err = alpha1.FleetAutoscalers(ns).DeleteCollection(do, options)
if err != nil {
return err
}

return alpha1.GameServers(ns).
DeleteCollection(do, options)
}

// PingGameServer pings a gameserver and returns its reply
Expand Down

0 comments on commit 534d2f3

Please sign in to comment.