Skip to content

Comments

fix :DumpTestContextIfFailed never captures context because defer CleanupTestContext fires first#5054

Open
katara-Jayprakash wants to merge 3 commits intovolcano-sh:masterfrom
katara-Jayprakash:bug-6
Open

fix :DumpTestContextIfFailed never captures context because defer CleanupTestContext fires first#5054
katara-Jayprakash wants to merge 3 commits intovolcano-sh:masterfrom
katara-Jayprakash:bug-6

Conversation

@katara-Jayprakash
Copy link
Member

What type of PR is this?

i'm calling it bug fixing pr

What this PR does / why we need it:

this pr try to fixed the bug where DumpTestContextIfFailed never captured context because CleanupTestContext was firing first due to Go's defer mechanism.

Which issue(s) this PR fixes:

the pr is part of #5048 and fixes the bug-6

Fixes #
#5048

Special notes for your reviewer:

@hajnalmt thanx for giving the so much brief about issue in description

Does this PR introduce a user-facing change?

none


Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Copilot AI review requested due to automatic review settings February 22, 2026 14:10
@volcano-sh-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign hwdef for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@gemini-code-assist
Copy link

Summary of Changes

Hello @katara-Jayprakash, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the e2e test infrastructure where test context dumps were failing to provide useful information upon test failure. The problem stemmed from the defer keyword causing cleanup functions to execute before the failure context could be captured. By centralizing the test context initialization and cleanup registration to BeforeEach and DeferCleanup blocks, the change ensures that the test environment is correctly set up and torn down, allowing for accurate context dumping when tests fail.

Highlights

  • Bug Fix: Resolved an issue where DumpTestContextIfFailed was unable to capture test context on failure because CleanupTestContext was executed prematurely due to Go's defer mechanism.
  • Test Context Management Refactor: Refactored e2e test suites to initialize testCtx in a BeforeEach block and register CleanupTestContext using DeferCleanup, ensuring proper context lifecycle management across all tests.
  • Code Cleanup: Removed redundant testCtx initialization and cleanup calls from individual It blocks within several e2e test files, streamlining test setup.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • test/e2e/jobseq/job_error_handling.go
    • Moved testCtx initialization and cleanup to a BeforeEach block.
    • Replaced defer e2eutil.CleanupTestContext(testCtx) with DeferCleanup(e2eutil.CleanupTestContext, testCtx).
  • test/e2e/jobseq/job_plugins.go
    • Moved testCtx initialization and cleanup to a BeforeEach block.
    • Replaced defer e2eutil.CleanupTestContext(testCtx) with DeferCleanup(e2eutil.CleanupTestContext, testCtx).
  • test/e2e/jobseq/mpi.go
    • Moved testCtx initialization and cleanup to a BeforeEach block.
    • Replaced defer e2eutil.CleanupTestContext(testCtx) with DeferCleanup(e2eutil.CleanupTestContext, testCtx).
  • test/e2e/jobseq/mpi_plugin.go
    • Moved testCtx initialization and cleanup to a BeforeEach block.
    • Replaced defer e2eutil.CleanupTestContext(testCtx) with DeferCleanup(e2eutil.CleanupTestContext, testCtx).
  • test/e2e/jobseq/pytorch_plugin.go
    • Moved testCtx initialization and cleanup to a BeforeEach block.
    • Replaced defer e2eutil.CleanupTestContext(testCtx) with DeferCleanup(e2eutil.CleanupTestContext, testCtx).
  • test/e2e/jobseq/queue.go
    • Replaced defer e2eutil.CleanupTestContext(testCtx) with DeferCleanup(e2eutil.CleanupTestContext, testCtx).
  • test/e2e/jobseq/queue_job_status.go
    • Moved testCtx initialization and cleanup to a BeforeEach block.
    • Replaced defer e2eutil.CleanupTestContext(testCtx) with DeferCleanup(e2eutil.CleanupTestContext, testCtx).
  • test/e2e/jobseq/ray_plugin.go
    • Moved testCtx initialization and cleanup to a BeforeEach block.
    • Replaced defer e2eutil.CleanupTestContext(testCtx) with DeferCleanup(e2eutil.CleanupTestContext, testCtx).
  • test/e2e/jobseq/tensorflow.go
    • Moved testCtx initialization and cleanup to a BeforeEach block.
    • Replaced defer e2eutil.CleanupTestContext(testCtx) with DeferCleanup(e2eutil.CleanupTestContext, testCtx).
  • test/e2e/jobseq/tensorflow_plugin.go
    • Moved testCtx initialization and cleanup to a BeforeEach block.
    • Replaced defer e2eutil.CleanupTestContext(testCtx) with DeferCleanup(e2eutil.CleanupTestContext, testCtx).
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@volcano-sh-bot volcano-sh-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 22, 2026
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses a bug where DumpTestContextIfFailed would not capture the test context on failure. This was due to defer CleanupTestContext executing before the JustAfterEach block in Ginkgo tests. The fix, which involves moving test context initialization to BeforeEach blocks and using DeferCleanup, has been applied consistently across numerous E2E test files.

While the overall approach is sound, I've identified a significant issue in test/e2e/jobseq/job_error_handling.go that introduces a resource leak. One test case re-initializes the test context within an It block, which orphans the context created in BeforeEach. I've provided a detailed comment with a recommended refactoring to resolve this. Apart from this concern, the changes effectively fix the intended bug.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Bug #6 from issue #5048, where DumpTestContextIfFailed never captured test context because CleanupTestContext was firing first due to Go's defer mechanism executing in LIFO order before Ginkgo's JustAfterEach hooks.

Changes:

  • Replaced defer e2eutil.CleanupTestContext(testCtx) with DeferCleanup(e2eutil.CleanupTestContext, testCtx) in test lifecycle setup
  • Moved test context initialization from inside It blocks to BeforeEach blocks where applicable
  • Ensured proper execution order: BeforeEach → It → JustAfterEach → DeferCleanup

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/e2e/jobseq/tensorflow_plugin.go Moved testCtx init to BeforeEach with DeferCleanup
test/e2e/jobseq/tensorflow.go Moved testCtx init to BeforeEach with DeferCleanup
test/e2e/jobseq/ray_plugin.go Moved testCtx init to BeforeEach with DeferCleanup
test/e2e/jobseq/queue_job_status.go Moved testCtx init to BeforeEach with DeferCleanup, removed duplicate inits from It blocks
test/e2e/jobseq/queue.go Replaced defer with DeferCleanup in It blocks (special case with per-test options)
test/e2e/jobseq/pytorch_plugin.go Moved testCtx init to BeforeEach with DeferCleanup
test/e2e/jobseq/mpi_plugin.go Moved testCtx init to BeforeEach with DeferCleanup
test/e2e/jobseq/mpi.go Moved testCtx init to BeforeEach with DeferCleanup
test/e2e/jobseq/job_plugins.go Moved testCtx init to BeforeEach with DeferCleanup, removed duplicate inits from It blocks
test/e2e/jobseq/job_error_handling.go Moved testCtx init to BeforeEach with DeferCleanup, removed duplicate inits from most It blocks, kept one special case with custom options

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@katara-Jayprakash
Copy link
Member Author

/cc @hajnalmt fixed sir

@volcano-sh-bot
Copy link
Contributor

@katara-Jayprakash: GitHub didn't allow me to request PR reviews from the following users: fixed, sir.

Note that only volcano-sh members and repo collaborators can review this PR, and authors cannot review their own PRs.

Details

In response to this:

/cc @hajnalmt fixed sir

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants