Skip to content

Commit

Permalink
Refactor test cases using shared runTest function
Browse files Browse the repository at this point in the history
  • Loading branch information
bjee19 committed Apr 26, 2024
1 parent 16a12d2 commit 7e60a18
Showing 1 changed file with 21 additions and 39 deletions.
60 changes: 21 additions & 39 deletions tests/suite/graceful_recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e60a18

Please sign in to comment.