From 88b69cdd0e6edb7ffc27791782fa248e81b051c6 Mon Sep 17 00:00:00 2001 From: Onsi Fakhouri Date: Tue, 6 Jun 2023 19:07:06 -0600 Subject: [PATCH] Fix flaky persistent volumes e2e test Fixes issue 115945 by moving the cleanup code in AfterEach into DeferCleanup. Cleanup stanzas are now paired with their setup stanzas within the body of the BeforeEach and are now guarenteed to run in the correct order. Prior to this there was no guarantee that the goroutine to recycle unbound PVs had finished before the AfterEach began. --- test/e2e/storage/persistent_volumes-local.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/e2e/storage/persistent_volumes-local.go b/test/e2e/storage/persistent_volumes-local.go index 0c2675bd281..32853f288bf 100644 --- a/test/e2e/storage/persistent_volumes-local.go +++ b/test/e2e/storage/persistent_volumes-local.go @@ -463,6 +463,8 @@ var _ = utils.SIGDescribe("PersistentVolumes-local ", func() { ginkgo.BeforeEach(func(ctx context.Context) { setupStorageClass(ctx, config, &waitMode) + ginkgo.DeferCleanup(cleanupStorageClass, config) + for i, node := range config.nodes { ginkgo.By(fmt.Sprintf("Setting up %d local volumes on node %q", volsPerNode, node.Name)) allLocalVolumes[node.Name] = setupLocalVolumes(ctx, config, volType, &config.nodes[i], volsPerNode) @@ -476,6 +478,13 @@ var _ = utils.SIGDescribe("PersistentVolumes-local ", func() { framework.ExpectNoError(err) } } + ginkgo.DeferCleanup(func(ctx context.Context) { + ginkgo.By("Clean all PVs") + for nodeName, localVolumes := range allLocalVolumes { + ginkgo.By(fmt.Sprintf("Cleaning up %d local volumes on node %q", len(localVolumes), nodeName)) + cleanupLocalVolumes(ctx, config, localVolumes) + } + }) ginkgo.By("Start a goroutine to recycle unbound PVs") backgroundCtx, cancel := context.WithCancel(context.Background()) var wg sync.WaitGroup @@ -532,15 +541,6 @@ var _ = utils.SIGDescribe("PersistentVolumes-local ", func() { }() }) - ginkgo.AfterEach(func(ctx context.Context) { - ginkgo.By("Clean all PVs") - for nodeName, localVolumes := range allLocalVolumes { - ginkgo.By(fmt.Sprintf("Cleaning up %d local volumes on node %q", len(localVolumes), nodeName)) - cleanupLocalVolumes(ctx, config, localVolumes) - } - cleanupStorageClass(ctx, config) - }) - ginkgo.It("should be able to process many pods and reuse local volumes", func(ctx context.Context) { var ( podsLock sync.Mutex