Skip to content

fix(testing): make test provider context-aware for goroutine#470

Draft
erka wants to merge 4 commits intomainfrom
rd/testing-context
Draft

fix(testing): make test provider context-aware for goroutine#470
erka wants to merge 4 commits intomainfrom
rd/testing-context

Conversation

@erka
Copy link
Member

@erka erka commented Feb 4, 2026

This PR

Signed-off-by: Roman Dmytrenko <rdmytrenko@gmail.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @erka, 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 refines the TestProvider in the OpenFeature Go SDK to correctly manage test contexts across goroutines. By making the provider context-aware and integrating with Go's context package, it resolves potential issues where flag evaluations in concurrent operations might fail to retrieve the correct test-specific flag configurations. This change improves the reliability and usability of the testing framework for asynchronous and concurrent test scenarios.

Highlights

  • Context-aware TestProvider: The TestProvider has been enhanced to be context-aware, allowing it to correctly identify the test scope even when flag evaluations occur in different goroutines.
  • UsingFlags returns Context: The TestProvider.UsingFlags method now returns a context.Context which should be used for flag evaluations within goroutines to ensure proper test context propagation.
  • Automatic Cleanup Integration: The TestProvider now integrates with testing.TB.Cleanup, automatically cleaning up the provider at the end of a test, reducing boilerplate.
  • Documentation Update: The README.md has been updated with new documentation and code examples demonstrating how to use the context-aware TestProvider for tests involving goroutines.
  • New Test Cases: New test cases have been added to testprovider_test.go to validate the context-aware behavior of the TestProvider in concurrent scenarios, such as HTTP handlers and multiple goroutines.
Changelog
  • README.md
    • Added a new section with code examples explaining how to use TestProvider.UsingFlags with goroutines for context-aware flag evaluations.
    • Introduced contextAwareTest struct in documentation for demonstrating context propagation.
    • Performed minor formatting adjustments to tables and spacing.
  • openfeature/testing/testprovider.go
    • Changed testNameKey to a contextKey type for improved type safety when storing in context.Context.
    • Modified TestProvider.UsingFlags to return a context.Context containing the test name.
    • Introduced testFrameworkWithContext interface to allow testing.T to provide a context for UsingFlags.
    • Implemented automatic cleanup for TestProvider by integrating with testing.TB.Cleanup.
    • Updated all Evaluation methods to pass the context.Context to getProvider.
    • Modified getProvider to prioritize retrieving the test name from the provided context.Context before falling back to goroutine-local storage.
  • openfeature/testing/testprovider_test.go
    • Added new imports for net/http, net/http/httptest, sync, time, assert, and require.
    • Introduced TestServeWithAnotherGoroutine with two sub-tests to verify context propagation in concurrent HTTP handler and multiple goroutine scenarios.
Activity
  • The pull request introduces a fix to make the test provider context-aware, specifically for scenarios involving goroutines.
  • The core changes involve modifying the TestProvider to return and utilize context.Context for test name resolution.
  • Documentation has been updated to guide users on how to leverage this new context-aware functionality.
  • New tests have been added to validate the fix and demonstrate correct usage in concurrent environments.
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.

@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.33%. Comparing base (f6d6d76) to head (c01a6ff).

Files with missing lines Patch % Lines
openfeature/testing/testprovider.go 90.90% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #470   +/-   ##
=======================================
  Coverage   83.32%   83.33%           
=======================================
  Files          27       27           
  Lines        2111     2124   +13     
=======================================
+ Hits         1759     1770   +11     
- Misses        304      305    +1     
- Partials       48       49    +1     
Flag Coverage Δ
e2e 83.33% <90.90%> (+<0.01%) ⬆️
unit 83.33% <90.90%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@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 makes the TestProvider context-aware, which is a great improvement for writing tests with goroutines. The implementation correctly uses context.Context to pass test-specific data, and maintains backward compatibility with the previous goroutine-local storage mechanism. The addition of automatic cleanup via t.Cleanup is also a nice touch for usability. I have a couple of suggestions to improve the documentation and fix a minor typo.

erka and others added 2 commits February 4, 2026 00:29
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Roman Dmytrenko <rdmytrenko@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Roman Dmytrenko <rdmytrenko@gmail.com>
Signed-off-by: Roman Dmytrenko <rdmytrenko@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant