diff --git a/test/e2e/density.go b/test/e2e/density.go index de730afe234..19ae69f6468 100644 --- a/test/e2e/density.go +++ b/test/e2e/density.go @@ -86,6 +86,13 @@ var _ = Describe("Density", func() { expectNoError(err) minionCount = len(minions.Items) Expect(minionCount).NotTo(BeZero()) + + // Terminating a namespace (deleting the remaining objects from it - which + // generally means events) can affect the current run. Thus we wait for all + // terminating namespace to be finally deleted before starting this test. + err = deleteTestingNS(c) + expectNoError(err) + nsForTesting, err := createTestingNS("density", c) ns = nsForTesting.Name expectNoError(err) diff --git a/test/e2e/load.go b/test/e2e/load.go index dc3b30ac36d..68cbf331463 100644 --- a/test/e2e/load.go +++ b/test/e2e/load.go @@ -63,6 +63,13 @@ var _ = Describe("Load capacity", func() { expectNoError(err) nodeCount = len(nodes.Items) Expect(nodeCount).NotTo(BeZero()) + + // Terminating a namespace (deleting the remaining objects from it - which + // generally means events) can affect the current run. Thus we wait for all + // terminating namespace to be finally deleted before starting this test. + err = deleteTestingNS(c) + expectNoError(err) + nsForTesting, err := createTestingNS("load", c) ns = nsForTesting.Name expectNoError(err) diff --git a/test/e2e/util.go b/test/e2e/util.go index b87823472c1..5c90169fc2c 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -376,6 +376,32 @@ func createTestingNS(baseName string, c *client.Client) (*api.Namespace, error) return got, nil } +// deleteTestingNS checks whether all e2e based existing namespaces are in the Terminating state +// and waits until they are finally deleted. +func deleteTestingNS(c *client.Client) error { + Logf("Waiting for terminating namespaces to be deleted...") + for start := time.Now(); time.Since(start) < 30*time.Minute; time.Sleep(15 * time.Second) { + namespaces, err := c.Namespaces().List(labels.Everything(), fields.Everything()) + if err != nil { + Logf("Listing namespaces failed: %v", err) + continue + } + terminating := 0 + for _, ns := range namespaces.Items { + if strings.HasPrefix(ns.ObjectMeta.Name, "e2e-tests-") { + if ns.Status.Phase == api.NamespaceActive { + return fmt.Errorf("Namespace %s is active", ns) + } + terminating++ + } + } + if terminating == 0 { + return nil + } + } + return fmt.Errorf("Waiting for terminating namespaces to be deleted timed out") +} + func waitForPodRunningInNamespace(c *client.Client, podName string, namespace string) error { return waitForPodCondition(c, namespace, podName, "running", podStartTimeout, func(pod *api.Pod) (bool, error) { if pod.Status.Phase == api.PodRunning {