-
Notifications
You must be signed in to change notification settings - Fork 45
feat: TestProvider for easy, parallel-safe testing #295
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
feat: TestProvider for easy, parallel-safe testing #295
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #295 +/- ##
==========================================
- Coverage 81.89% 81.45% -0.44%
==========================================
Files 10 11 +1
Lines 1215 1262 +47
==========================================
+ Hits 995 1028 +33
- Misses 199 210 +11
- Partials 21 24 +3 ☔ View full report in Codecov by Sentry. |
209bd88
to
853d9f4
Compare
pkg/openfeaturetest/testprovider.go
Outdated
@@ -0,0 +1,104 @@ | |||
package openfeaturetest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we need to come up with a better place for this ? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the question is, if we want this to be part of the sdk or rather put this as a separate package in the sdk-contrib - like we did in java for the junit extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then to me this sounds like contrib would be the better place. @toddbaert ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there's no external deps, I think we should include this in the SDK.
pkg/openfeaturetest/testprovider.go
Outdated
return value | ||
} | ||
|
||
func getGoroutineID() uint64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not perfect but does the trick of getting the current gid from the runtime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@warber to be honest it is a very hacky way of dealing with that. Maybe we can think of a more elegant solution since the go routine id is intentionally not available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@warber to be honest it is a very hacky way of dealing with that. Maybe we can think of a more elegant solution since the go routine id is intentionally not available.
I agree it's hacky, however, there are multiple relatively popular packages that use this same mechanism, and we are only using it for testing. I would not advocate for including this in production code, but I think it's acceptable to dodge our singleton issue for tests, and include it only in a testing package.
IMO this is a net improvement. I'm open to other solutions but at the end of the day, we need some transparent piece of data (at least an id) to propagate from the test to the production code; I'm not aware of any other alternative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I can agree with that
Added simple version of a "TestAware" provider that is managing a TestName=>FeatureProvider map and knows which feature provider to delegate the methods calls for a given test. Signed-off-by: Bernd Warmuth <bernd.warmuth@dynatrace.com>
853d9f4
to
356940d
Compare
pkg/openfeaturetest/testprovider.go
Outdated
// `SetProvider` method. | ||
type TestAwareProvider struct { | ||
openfeature.NoopProvider | ||
providers *sync.Map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only current issue with this approach is cleaning up this map. It would be great if we could have some ergonomic mechanism to REMOVE things from this map, eventually. Perhaps something a user could clean-up with a defer
statement in whatever scope they need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve of this approach. This is my only blocker.
Signed-off-by: Bernd Warmuth <bernd.warmuth@dynatrace.com>
@warber Looks good, I have proposed one more additional ergonomic change I'd like your opinion on. Fundamentally it works the exact same way, it just changes the API a bit so that users are thinking in terms of flags for a test scope, not a provider for a test scope: warber#1 If you agree, I think we should just add a quick blurb about this in the README and then merge. |
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
b78ffd7
to
9c5de09
Compare
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Co-authored-by: Michael Beemer <beeme1mr@users.noreply.github.com> Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
This PR
Related Issues
Fixes: #293