From 7e60a18188ac0e737f2405e8302292e584ac1f4f Mon Sep 17 00:00:00 2001 From: Benjamin Jee Date: Fri, 26 Apr 2024 12:18:42 -0700 Subject: [PATCH] Refactor test cases using shared runTest function --- tests/suite/graceful_recovery_test.go | 60 ++++++++++----------------- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/tests/suite/graceful_recovery_test.go b/tests/suite/graceful_recovery_test.go index 448ef1dd7..304f2c073 100644 --- a/tests/suite/graceful_recovery_test.go +++ b/tests/suite/graceful_recovery_test.go @@ -56,57 +56,39 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("nfr", "graceful-recov }) It("recovers when NGF container is restarted", func() { - podNames, err := framework.GetReadyNGFPodNames(k8sClient, ngfNamespace, releaseName, timeoutConfig.GetTimeout) - Expect(err).ToNot(HaveOccurred()) - Expect(podNames).ToNot(BeEmpty()) - - leaseName, err := getLeaderElectionLeaseHolderName() - Expect(err).ToNot(HaveOccurred()) - - restartContainer(ngfContainerName) - - checkContainerLogsForErrors(podNames[0]) - - Expect(waitForLeaderLeaseToChange(leaseName)).ToNot(HaveOccurred()) - - Expect(waitForWorkingTraffic()).ToNot(HaveOccurred()) - - Expect(resourceManager.DeleteFromFiles(files, ns.Name)).To(Succeed()) - - Expect(waitForFailingTraffic()).ToNot(HaveOccurred()) - - Expect(resourceManager.ApplyFromFiles(files, ns.Name)).To(Succeed()) - Expect(resourceManager.WaitForAppsToBeReady(ns.Name)).To(Succeed()) - - Expect(waitForWorkingTraffic()).ToNot(HaveOccurred()) + runTest(ngfContainerName, files, ns) }) It("recovers when nginx container is restarted", func() { - podNames, err := framework.GetReadyNGFPodNames(k8sClient, ngfNamespace, releaseName, timeoutConfig.GetTimeout) - Expect(err).ToNot(HaveOccurred()) - Expect(podNames).ToNot(BeEmpty()) + runTest(nginxContainerName, files, ns) + }) +}) - leaseName, err := getLeaderElectionLeaseHolderName() - Expect(err).ToNot(HaveOccurred()) +func runTest(containerName string, files []string, ns *core.Namespace) { + podNames, err := framework.GetReadyNGFPodNames(k8sClient, ngfNamespace, releaseName, timeoutConfig.GetTimeout) + Expect(err).ToNot(HaveOccurred()) + Expect(podNames).ToNot(BeEmpty()) - restartContainer(nginxContainerName) + leaseName, err := getLeaderElectionLeaseHolderName() + Expect(err).ToNot(HaveOccurred()) - checkContainerLogsForErrors(podNames[0]) + restartContainer(containerName) - Expect(waitForLeaderLeaseToChange(leaseName)).ToNot(HaveOccurred()) + checkContainerLogsForErrors(podNames[0]) - Expect(waitForWorkingTraffic()).ToNot(HaveOccurred()) + Expect(waitForLeaderLeaseToChange(leaseName)).ToNot(HaveOccurred()) - Expect(resourceManager.DeleteFromFiles(files, ns.Name)).To(Succeed()) + Expect(waitForWorkingTraffic()).ToNot(HaveOccurred()) - Expect(waitForFailingTraffic()).ToNot(HaveOccurred()) + Expect(resourceManager.DeleteFromFiles(files, ns.Name)).To(Succeed()) - Expect(resourceManager.ApplyFromFiles(files, ns.Name)).To(Succeed()) - Expect(resourceManager.WaitForAppsToBeReady(ns.Name)).To(Succeed()) + Expect(waitForFailingTraffic()).ToNot(HaveOccurred()) - Expect(waitForWorkingTraffic()).ToNot(HaveOccurred()) - }) -}) + Expect(resourceManager.ApplyFromFiles(files, ns.Name)).To(Succeed()) + Expect(resourceManager.WaitForAppsToBeReady(ns.Name)).To(Succeed()) + + Expect(waitForWorkingTraffic()).ToNot(HaveOccurred()) +} func restartContainer(containerName string) { var jobScript string