Skip to content

Conversation

@richie-king
Copy link
Contributor

@richie-king richie-king commented Nov 29, 2025

Proposed changes

Problem: Unit tests currently use context.TODO() and context.Background(), which can potentially lead to goroutine leaks and resource cleanup issues because these contexts are not automatically canceled when a test completes.

Solution: Replaced usage of context.TODO() and context.Background() with t.Context() in unit tests. This ensures that contexts are automatically canceled when tests complete and aligns the test suite with modern Go 1.24+ testing practices.

Testing: Ran all unit tests to ensure they pass with the new context handling.
Closes #3157

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the contributing guidelines.
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

Release notes

If this PR introduces a change that affects users and needs to be mentioned in the release notes,
please add a brief note that summarizes the change.

Refactored unit tests to use t.Context() instead of context.TODO() or context.Background() to prevent potential goroutine leaks.

@nginx-bot
Copy link

nginx-bot bot commented Nov 29, 2025

Hi @richie-king! Welcome to the project! 🎉

Thanks for opening this pull request!
Be sure to check out our Contributing Guidelines while you wait for someone on the team to review this.

@nginx-bot nginx-bot bot added the community label Nov 29, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 29, 2025

✅ All required contributors have signed the F5 CLA for this PR. Thank you!
Posted by the CLA Assistant Lite bot.

@github-actions github-actions bot added the tests Pull requests that update tests label Nov 29, 2025
@richie-king
Copy link
Contributor Author

richie-king commented Nov 29, 2025

🎉 Thank you for your contribution! It appears you have not yet signed the F5 Contributor License Agreement (CLA), which is required for your changes to be incorporated into an F5 Open Source Software (OSS) project. Please kindly read the F5 CLA and reply on a new comment with the following text to agree:

I have hereby read the F5 CLA and agree to its terms

You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

I have hereby read the F5 CLA and agree to its terms

@richie-king
Copy link
Contributor Author

recheck

@richie-king
Copy link
Contributor Author

I have hereby read the F5 CLA and agree to its terms

@richie-king
Copy link
Contributor Author

recheck

@richie-king richie-king changed the title test: replace context.TODO and context.Background to t.Context in uni… Test: replace context.TODO and context.Background to t.Context in uni… Nov 29, 2025
Copy link
Contributor

@bjee19 bjee19 left a comment

Choose a reason for hiding this comment

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

Hey @richie-king, thanks for this contribution! The changes are looking pretty good, however it looks like the PR is failing a pipeline regarding some lint issues, do you think you could address those?

@sjberman
Copy link
Collaborator

sjberman commented Dec 1, 2025

I'm surprised there are only 17 files that needed updating.

@richie-king
Copy link
Contributor Author

Hey @richie-king, thanks for this contribution! The changes are looking pretty good, however it looks like the PR is failing a pipeline regarding some lint issues, do you think you could address those?

Sure, I will. I feel good about making CI pass

@richie-king
Copy link
Contributor Author

I'm surprised there are only 17 files that needed updating.

I've checked all the test files. All the unit tests are included, except for the BDD tests, which do not use the T object.

@richie-king richie-king force-pushed the test/replace-to-t-context branch from 3c93131 to 40f8633 Compare December 2, 2025 13:46
@sjberman
Copy link
Collaborator

sjberman commented Dec 2, 2025

Some pipeline failures we're seeing on forks, not related to the PR. I'm looking into it.

@bjee19
Copy link
Contributor

bjee19 commented Dec 16, 2025

We're still in progress on fixing our issue related to the pipeline issues. Once that gets resolved this should be close to merging, thanks for your patience.

@sjberman
Copy link
Collaborator

@richie-king I think we've fixed the pipeline issue at this point. If you wouldn't mind rebasing and fixing the conflicts, we'll get this merged soon!

@richie-king
Copy link
Contributor Author

@richie-king I think we've fixed the pipeline issue at this point. If you wouldn't mind rebasing and fixing the conflicts, we'll get this merged soon!

sure, I will make it happen ASAP

@richie-king richie-king requested a review from a team as a code owner December 21, 2025 10:28
@github-actions github-actions bot added documentation Improvements or additions to documentation helm-chart Relates to helm chart and removed tests Pull requests that update tests labels Dec 21, 2025
@richie-king richie-king force-pushed the test/replace-to-t-context branch from ba67f79 to 4c96b71 Compare December 21, 2025 11:05
@github-actions github-actions bot added tests Pull requests that update tests and removed documentation Improvements or additions to documentation helm-chart Relates to helm chart labels Dec 21, 2025
@richie-king richie-king force-pushed the test/replace-to-t-context branch from 4c96b71 to 2bc4815 Compare December 21, 2025 11:31
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Dec 21, 2025
@richie-king richie-king force-pushed the test/replace-to-t-context branch from 2bc4815 to 80cbd7d Compare December 21, 2025 11:31
Signed-off-by: richie <mychenforeverl@gmail.com>
@richie-king richie-king force-pushed the test/replace-to-t-context branch from 80cbd7d to 886c88a Compare December 21, 2025 11:57
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Dec 21, 2025
@sjberman sjberman merged commit 6013b9e into nginx:main Dec 22, 2025
59 checks passed
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in NGINX Gateway Fabric Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community tests Pull requests that update tests

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Update unit tests to use new test Context

4 participants