docs: correct context-cancellation claim on non-blocking SetProviderWithContext#515
docs: correct context-cancellation claim on non-blocking SetProviderWithContext#515sueun-dev wants to merge 1 commit into
Conversation
…ithContext SetProviderWithContext and SetNamedProviderWithContext said they return an error if the context is cancelled during setup. They don't: both call api().SetProvider(ctx, provider), which returns synchronously only when the provider is nil or is already bound to a different API instance. The context is passed to the background initNew goroutine and never checked synchronously, so a cancelled context with a valid provider returns nil. Only the ...AndWait variants honor cancellation, via the select on ctx.Done() in SetProviderAndWait, and their docs already say so. The non-blocking behavior is intended: TestContextAwareInitialization's "async initialization returns immediately" subtest asserts SetProviderWithContext returns immediately without error, so this corrects the comment rather than the code. Added a subtest covering the cancelled-context case so the contract does not silently flip back. Signed-off-by: Sueun Cho <sueun.dev@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughDoc comments and tests for context-aware provider initialization were updated to reflect that cancelled contexts do not make the async provider setup APIs return errors. ChangesContext-aware initialization semantics
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~4 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #515 +/- ##
=======================================
Coverage 86.45% 86.45%
=======================================
Files 22 22
Lines 2119 2119
=======================================
Hits 1832 1832
Misses 242 242
Partials 45 45
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The godoc on
SetProviderWithContextandSetNamedProviderWithContextsays:The context-cancellation half isn't true. Both call
api().SetProvider(ctx, provider), which returns synchronously only when the provider is nil (errNilDefaultProvider/errNilProvider) or is already bound to a different API instance (bindProvider, spec 1.8.4). The context is handed to the backgroundinitNewgoroutine and never checked synchronously, so a cancelled context with a valid provider returns nil. Only the...AndWaitvariants honor cancellation, via theselectonctx.Done()inSetProviderAndWait, and their docs already say so.The non-blocking behavior looks intended:
TestContextAwareInitialization's "async initialization returns immediately" subtest assertsSetProviderWithContextreturns immediately without error, andExampleSetProviderWithContextshows the provider continuing to initialize in the background. So this corrects the comment rather than the code.With a cancelled context and a valid provider, both functions return nil today:
I added a subtest under
TestContextAwareInitializationcovering that, so the contract doesn't silently flip back.go test --short -tags testtools -race ./openfeature/...passes;gofmtandgo vetare clean.