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.
This commit is contained in:
Onsi Fakhouri 2023-06-06 19:07:06 -06:00
parent 7ef5ec499d
commit 88b69cdd0e

View File

@ -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