From 4f20388bd778f5780caaea576c23f9bf9e6f6718 Mon Sep 17 00:00:00 2001 From: Mark Mandel Date: Wed, 23 Jan 2019 19:51:32 -0800 Subject: [PATCH] Fixes for flaky e2e tests. Some more fixes for the flaky e2e tests. --- test/e2e/fleetautoscaler_test.go | 18 ++++++++++++++---- test/e2e/framework/framework.go | 18 +++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/test/e2e/fleetautoscaler_test.go b/test/e2e/fleetautoscaler_test.go index fb1f66281d..ccd8e124e8 100644 --- a/test/e2e/fleetautoscaler_test.go +++ b/test/e2e/fleetautoscaler_test.go @@ -16,6 +16,8 @@ package e2e import ( "fmt" + k8serrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/util/wait" "math/rand" "testing" "time" @@ -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 @@ -416,7 +416,17 @@ 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)) + } + + // 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) if assert.Nil(t, err) { diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index b5906148ea..8eda8394dd 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -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