Skip to content

Graceful recovery test improvements #3628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tests/framework/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func Get(
if err != nil {
return 0, "", err
}

defer resp.Body.Close()

body := new(bytes.Buffer)
Expand Down
15 changes: 6 additions & 9 deletions tests/suite/graceful_recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

// Since this test involves restarting of the test node, it is recommended to be run separate from other tests
// such that any issues in this test do not interfere with other tests.
var _ = Describe("Graceful Recovery test", Ordered, Label("graceful-recovery"), func() {
var _ = Describe("Graceful Recovery test", Ordered, FlakeAttempts(2), Label("graceful-recovery"), func() {
var (
files = []string{
"graceful-recovery/cafe.yaml",
Expand Down Expand Up @@ -120,13 +120,13 @@
return names, nil
}

runNodeDebuggerJob := func(nginxPodName, jobScript string) (*v1.Job, error) {
runNodeDebuggerJob := func(nginxPodName string) (*v1.Job, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.GetTimeout)
defer cancel()

var nginxPod core.Pod
if err := k8sClient.Get(ctx, types.NamespacedName{Namespace: ns.Name, Name: nginxPodName}, &nginxPod); err != nil {
return nil, fmt.Errorf("error retrieving NGF Pod: %w", err)
return nil, fmt.Errorf("error retrieving nginx Pod: %w", err)
}

b, err := resourceManager.GetFileContents("graceful-recovery/node-debugger-job.yaml")
Expand All @@ -146,7 +146,6 @@
len(job.Spec.Template.Spec.Containers),
)
}
job.Spec.Template.Spec.Containers[0].Args = []string{jobScript}
job.Namespace = ns.Name

if err = resourceManager.Apply([]client.Object{job}); err != nil {
Expand All @@ -157,13 +156,11 @@
}

restartNginxContainer := func(nginxPodName, namespace, containerName string) {
jobScript := "PID=$(pgrep -f \"nginx-agent\") && kill -9 $PID"

restartCount, err := getContainerRestartCount(nginxPodName, namespace, containerName)
Expect(err).ToNot(HaveOccurred())

cleanUpPortForward()
job, err := runNodeDebuggerJob(nginxPodName, jobScript)
job, err := runNodeDebuggerJob(nginxPodName)
Expect(err).ToNot(HaveOccurred())

Eventually(
Expand Down Expand Up @@ -513,7 +510,7 @@

It("recovers when node is restarted abruptly", func() {
if *plusEnabled {
Skip(fmt.Sprintf("Skipping test when using NGINX Plus due to known issue:" +

Check notice on line 513 in tests/suite/graceful_recovery_test.go

View workflow job for this annotation

GitHub Actions / Functional tests (plus, v1.25.16) / Run Tests

It 07/16/25 15:36:52.477

Check notice on line 513 in tests/suite/graceful_recovery_test.go

View workflow job for this annotation

GitHub Actions / Functional tests (plus, v1.33.1) / Run Tests

It 07/16/25 15:36:28.779
" https://github.com/nginx/nginx-gateway-fabric/issues/3248"))
}
runRestartNodeAbruptlyTest(teaURL, coffeeURL, files, &ns)
Expand All @@ -524,11 +521,11 @@
status, body, err := framework.Get(appURL, address, timeoutConfig.RequestTimeout, nil, nil)

if status != http.StatusOK {
return errors.New("http status was not 200")
return fmt.Errorf("http status was not 200, got %d: %w", status, err)
}

if !strings.Contains(body, responseBodyMessage) {
return errors.New("expected response body to contain correct body message")
return fmt.Errorf("expected response body to contain correct body message, got: %s", body)
}

return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
- name: node-debugger-container
image: ubuntu:24.04
command: ["/bin/bash", "-c"]
args: ["to be replaced by the test"]
args: ["pkill -x \"nginx-agent\""]
securityContext:
privileged: true
volumeMounts:
Expand Down
Loading