Skip to content

Commit cd9a4d1

Browse files
committed
Update graceful recovery test
1 parent f7feb19 commit cd9a4d1

File tree

2 files changed

+59
-73
lines changed

2 files changed

+59
-73
lines changed

tests/suite/graceful_recovery_test.go

Lines changed: 59 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,26 @@ const (
2828
ngfContainerName = "nginx-gateway"
2929
)
3030

31-
// Since checkNGFContainerLogsForErrors may experience interference from previous tests (as explained in the function
32-
// documentation), this test is recommended to be run separate from other tests.
31+
// Since this test involves restarting of the test node, it is recommended to be run separate from other tests
32+
// such that any issues in this test do not interfere with other tests.
3333
var _ = Describe("Graceful Recovery test", Ordered, Label("graceful-recovery"), func() {
34-
files := []string{
35-
"graceful-recovery/cafe.yaml",
36-
"graceful-recovery/cafe-secret.yaml",
37-
"graceful-recovery/gateway.yaml",
38-
"graceful-recovery/cafe-routes.yaml",
39-
}
34+
var (
35+
files = []string{
36+
"graceful-recovery/cafe.yaml",
37+
"graceful-recovery/cafe-secret.yaml",
38+
"graceful-recovery/gateway.yaml",
39+
"graceful-recovery/cafe-routes.yaml",
40+
}
4041

41-
var ns core.Namespace
42+
ns core.Namespace
4243

43-
baseHTTPURL := "http://cafe.example.com"
44-
baseHTTPSURL := "https://cafe.example.com"
45-
teaURL := baseHTTPSURL + "/tea"
46-
coffeeURL := baseHTTPURL + "/coffee"
44+
baseHTTPURL = "http://cafe.example.com"
45+
baseHTTPSURL = "https://cafe.example.com"
46+
teaURL = baseHTTPSURL + "/tea"
47+
coffeeURL = baseHTTPURL + "/coffee"
48+
49+
activeNGFPodName, activeNginxPodName string
50+
)
4751

4852
checkForWorkingTraffic := func(teaURL, coffeeURL string) error {
4953
if err := expectRequestToSucceed(teaURL, address, "URI: /tea"); err != nil {
@@ -216,8 +220,9 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("graceful-recovery"),
216220

217221
nginxPodName := nginxPodNames[0]
218222
Expect(nginxPodName).ToNot(BeEmpty())
223+
activeNginxPodName = nginxPodName
219224

220-
setUpPortForward(nginxPodNames[0], ns.Name)
225+
setUpPortForward(activeNginxPodName, ns.Name)
221226

222227
Eventually(
223228
func() error {
@@ -291,9 +296,16 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("graceful-recovery"),
291296
WithPolling(500 * time.Millisecond).
292297
MustPassRepeatedly(20).
293298
Should(BeTrue())
299+
newNGFPodName := podNames[0]
294300

295-
ngfPodName := podNames[0]
296-
Expect(ngfPodName).ToNot(BeEmpty())
301+
// expected behavior is when node is drained, new pods will be created. when the node is
302+
// abruptly restarted, new pods are not created.
303+
if drain {
304+
Expect(newNGFPodName).ToNot(Equal(activeNGFPodName))
305+
activeNGFPodName = newNGFPodName
306+
} else {
307+
Expect(newNGFPodName).To(Equal(activeNGFPodName))
308+
}
297309

298310
var nginxPodNames []string
299311
Eventually(
@@ -305,21 +317,23 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("graceful-recovery"),
305317
WithPolling(500 * time.Millisecond).
306318
MustPassRepeatedly(20).
307319
Should(BeTrue())
320+
newNginxPodName := nginxPodNames[0]
308321

309-
nginxPodName := nginxPodNames[0]
310-
Expect(nginxPodName).ToNot(BeEmpty())
322+
if drain {
323+
Expect(newNginxPodName).ToNot(Equal(activeNginxPodName))
324+
activeNginxPodName = newNginxPodName
325+
} else {
326+
Expect(newNginxPodName).To(Equal(activeNginxPodName))
327+
}
311328

312-
setUpPortForward(nginxPodName, ns.Name)
329+
setUpPortForward(activeNginxPodName, ns.Name)
313330

331+
// sets activeNginxPodName to new pod
314332
checkNGFFunctionality(teaURL, coffeeURL, files, ns)
315333

316-
checkNGFContainerLogsForErrors(ngfPodName)
334+
checkNGFContainerLogsForErrors(activeNGFPodName)
317335

318-
nginxPodNames, err = framework.GetReadyNginxPodNames(k8sClient, ns.Name, timeoutConfig.GetTimeout)
319-
Expect(err).ToNot(HaveOccurred())
320-
Expect(nginxPodNames).To(HaveLen(1))
321-
322-
if errorLogs := getUnexpectedNginxErrorLogs(nginxPodNames[0], ns.Name); errorLogs != "" {
336+
if errorLogs := getUnexpectedNginxErrorLogs(activeNginxPodName, ns.Name); errorLogs != "" {
323337
Skip(fmt.Sprintf("NGINX has unexpected error logs: \n%s", errorLogs))
324338
}
325339
}
@@ -367,19 +381,13 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("graceful-recovery"),
367381
return nil
368382
}
369383

370-
BeforeEach(func() {
371-
// this test is unique in that it will check the entire log of both ngf and nginx containers
372-
// for any errors, so in order to avoid errors generated in previous tests we will uninstall
373-
// NGF installed at the suite level, then re-deploy our own. We will also uninstall and re-install
374-
// NGF between each graceful-recovery test for the same reason.
375-
teardown(releaseName)
376-
377-
setup(getDefaultSetupCfg())
378-
384+
BeforeAll(func() {
379385
podNames, err := framework.GetReadyNGFPodNames(k8sClient, ngfNamespace, releaseName, timeoutConfig.GetTimeout)
380386
Expect(err).ToNot(HaveOccurred())
381387
Expect(podNames).To(HaveLen(1))
382388

389+
activeNGFPodName = podNames[0]
390+
383391
ns = core.Namespace{
384392
ObjectMeta: metav1.ObjectMeta{
385393
Name: "graceful-recovery",
@@ -394,7 +402,9 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("graceful-recovery"),
394402
Expect(err).ToNot(HaveOccurred())
395403
Expect(nginxPodNames).To(HaveLen(1))
396404

397-
setUpPortForward(nginxPodNames[0], ns.Name)
405+
activeNginxPodName = nginxPodNames[0]
406+
407+
setUpPortForward(activeNginxPodName, ns.Name)
398408

399409
if portFwdPort != 0 {
400410
coffeeURL = fmt.Sprintf("%s:%d/coffee", baseHTTPURL, portFwdPort)
@@ -412,58 +422,37 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("graceful-recovery"),
412422
Should(Succeed())
413423
})
414424

415-
AfterEach(func() {
425+
AfterAll(func() {
416426
cleanUpPortForward()
417427
Expect(resourceManager.DeleteFromFiles(files, ns.Name)).To(Succeed())
418428
Expect(resourceManager.DeleteNamespace(ns.Name)).To(Succeed())
419429
})
420430

421431
It("recovers when nginx container is restarted", func() {
422-
nginxPodNames, err := framework.GetReadyNginxPodNames(k8sClient, ns.Name, timeoutConfig.GetTimeout)
423-
Expect(err).ToNot(HaveOccurred())
424-
Expect(nginxPodNames).To(HaveLen(1))
425-
426-
nginxPodName := nginxPodNames[0]
427-
428-
restartNginxContainer(nginxPodName, ns.Name, nginxContainerName)
432+
restartNginxContainer(activeNginxPodName, ns.Name, nginxContainerName)
429433

430-
nginxPodNames, err = framework.GetReadyNginxPodNames(k8sClient, ns.Name, timeoutConfig.GetTimeout)
434+
nginxPodNames, err := framework.GetReadyNginxPodNames(k8sClient, ns.Name, timeoutConfig.GetTimeout)
431435
Expect(err).ToNot(HaveOccurred())
432436
Expect(nginxPodNames).To(HaveLen(1))
437+
activeNginxPodName = nginxPodNames[0]
433438

434-
setUpPortForward(nginxPodNames[0], ns.Name)
439+
setUpPortForward(activeNginxPodName, ns.Name)
435440

441+
// sets activeNginxPodName to new pod
436442
checkNGFFunctionality(teaURL, coffeeURL, files, &ns)
437443

438-
ngfPodNames, err := framework.GetReadyNGFPodNames(k8sClient, ngfNamespace, releaseName, timeoutConfig.GetTimeout)
439-
Expect(err).ToNot(HaveOccurred())
440-
Expect(ngfPodNames).To(HaveLen(1))
444+
checkNGFContainerLogsForErrors(activeNGFPodName)
441445

442-
nginxPodNames, err = framework.GetReadyNginxPodNames(k8sClient, ns.Name, timeoutConfig.GetTimeout)
443-
Expect(err).ToNot(HaveOccurred())
444-
Expect(nginxPodNames).To(HaveLen(1))
445-
446-
checkNGFContainerLogsForErrors(ngfPodNames[0])
447-
448-
if errorLogs := getUnexpectedNginxErrorLogs(nginxPodNames[0], ns.Name); errorLogs != "" {
446+
if errorLogs := getUnexpectedNginxErrorLogs(activeNginxPodName, ns.Name); errorLogs != "" {
449447
Skip(fmt.Sprintf("NGINX has unexpected error logs: \n%s", errorLogs))
450448
}
451449
})
452450

453451
It("recovers when NGF Pod is restarted", func() {
454-
startingNGFPodNames, err := framework.GetReadyNGFPodNames(
455-
k8sClient,
456-
ngfNamespace,
457-
releaseName,
458-
timeoutConfig.GetTimeout,
459-
)
460-
Expect(err).ToNot(HaveOccurred())
461-
Expect(startingNGFPodNames).To(HaveLen(1))
462-
463452
leaseName, err := getLeaderElectionLeaseHolderName()
464453
Expect(err).ToNot(HaveOccurred())
465454

466-
ngfPod, err := resourceManager.GetPod(ngfNamespace, startingNGFPodNames[0])
455+
ngfPod, err := resourceManager.GetPod(ngfNamespace, activeNGFPodName)
467456
Expect(err).ToNot(HaveOccurred())
468457

469458
ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.DeleteTimeout)
@@ -490,7 +479,8 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("graceful-recovery"),
490479
newNGFPodName := newNGFPodNames[0]
491480
Expect(newNGFPodName).ToNot(BeEmpty())
492481

493-
Expect(newNGFPodName).ToNot(Equal(startingNGFPodNames[0]))
482+
Expect(newNGFPodName).ToNot(Equal(activeNGFPodName))
483+
activeNGFPodName = newNGFPodName
494484

495485
Eventually(
496486
func() error {
@@ -500,15 +490,12 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("graceful-recovery"),
500490
WithPolling(500 * time.Millisecond).
501491
Should(Succeed())
502492

493+
// sets activeNginxPodName to new pod
503494
checkNGFFunctionality(teaURL, coffeeURL, files, &ns)
504495

505-
checkNGFContainerLogsForErrors(newNGFPodName)
506-
507-
nginxPodNames, err := framework.GetReadyNginxPodNames(k8sClient, ns.Name, timeoutConfig.GetTimeout)
508-
Expect(err).ToNot(HaveOccurred())
509-
Expect(nginxPodNames).To(HaveLen(1))
496+
checkNGFContainerLogsForErrors(activeNGFPodName)
510497

511-
if errorLogs := getUnexpectedNginxErrorLogs(nginxPodNames[0], ns.Name); errorLogs != "" {
498+
if errorLogs := getUnexpectedNginxErrorLogs(activeNginxPodName, ns.Name); errorLogs != "" {
512499
Skip(fmt.Sprintf("NGINX has unexpected error logs: \n%s", errorLogs))
513500
}
514501
})

tests/suite/system_suite_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ var _ = BeforeSuite(func() {
323323
"telemetry", // - running telemetry test (NGF will be deployed as part of the test)
324324
"scale", // - running scale test (this test will deploy its own version)
325325
"reconfiguration", // - running reconfiguration test (test will deploy its own instances)
326-
"graceful-recovery", // - running graceful-recovery test (test will deploy its own instances)
327326
}
328327
for _, s := range skipSubstrings {
329328
if strings.Contains(labelFilter, s) {

0 commit comments

Comments
 (0)