client: centralize client initialization - #11085
Conversation
Signed-off-by: disksing <i@disksing.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughClient construction paths now share ChangesClient construction
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Signed-off-by: disksing <i@disksing.com>
|
/retest |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #11085 +/- ##
==========================================
+ Coverage 79.17% 79.30% +0.12%
==========================================
Files 541 541
Lines 76487 76588 +101
==========================================
+ Hits 60558 60736 +178
+ Misses 11629 11574 -55
+ Partials 4300 4278 -22
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Signed-off-by: disksing <i@disksing.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@client/client_test.go`:
- Around line 124-138: The public-constructor tests around
TestNewClientWithKeyspaceInvalidTLSConfig and the following TLS case should pass
testClientURL instead of nil and assert the TLS-specific ErrCryptoX509KeyPair
with ErrorAs, while retaining the nil-client assertion, so the tests prove TLS
validation fails before keyspace or service-discovery errors.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: dd14908f-ac96-4763-bb8b-f75de6175243
📒 Files selected for processing (1)
client/client_test.go
|
/retest |
Signed-off-by: disksing <i@disksing.com>
|
addressed the review: pass testClientURL and assert the TLS-specific ErrCryptoX509KeyPair error with ErrorIs |
|
/test pull-unit-test-next-gen-3 |
4 similar comments
|
/test pull-unit-test-next-gen-3 |
|
/test pull-unit-test-next-gen-3 |
|
/test pull-unit-test-next-gen-3 |
|
/test pull-unit-test-next-gen-3 |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Pull request overview
This PR refactors the PD client constructors by extracting the common “base client state” initialization (TLS config, derived context + cancel, innerClient fields, and option injection) into a single internal helper, reducing duplication between the fixed-keyspace-ID and keyspace-name initialization paths.
Changes:
- Introduces an internal
createClient(...) (*client, error)helper to build shared client state without performing service-discovery initialization. - Updates the fixed-keyspace-ID constructor path to reuse
createClientand then callinner.init(nil)as before. - Adds unit tests to verify shared initialization state, option propagation, context cancellation propagation, and invalid TLS handling.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| client/client.go | Extracts shared client setup into createClient and updates constructors to reuse it while preserving existing init behavior. |
| client/client_test.go | Adds tests covering shared initialization state, options/context propagation, and invalid TLS error behavior across constructors. |
What problem does this PR solve?
Issue Number: ref #10989
The fixed-keyspace-ID and keyspace-name client constructors duplicate TLS, context,
innerClient, and option initialization. Adding another initialization path on top of this duplication would make it easier for constructor behavior to drift.What is changed and how does it work?
This PR:
innerClient, and client option initialization;inner.init(nil);Check List
Tests
Code changes
Side effects
Related changes
Release note
Summary by CodeRabbit
Bug Fixes
Tests