Skip to content
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

Refactor rpc utils test #13214

Merged
merged 9 commits into from
Oct 18, 2023
Merged

Refactor rpc utils test #13214

merged 9 commits into from
Oct 18, 2023

Conversation

gzhao9
Copy link
Contributor

@gzhao9 gzhao9 commented Oct 16, 2023

What is the purpose of the change

Similarly, to #13153, I noticed that in RpcUtilsTest, there is also a duplicate creation of the mock.

The Invoker was duplicated to create the mock object 10 times, in 10 test cases.
I used a similar approach refactoring to increase code readability.

Brief changelog

I refactored the code to introduce two methods: CreateMockInvoker(URL url) and CreateMockInvoker(). I've used these methods in 10 test cases to reduce the repetitive creation of the Invoker mock.

Additional questions.

I also noticed that this pattern appears in different test files for different packages, do you prefer to use shared utility classes or define these methods in each file?

Verifying this change

Checklist

  • Make sure there is a GitHub_issue field for the change (usually before you start working on it). Trivial changes like typos do not require a GitHub issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Check if is necessary to patch to Dubbo 3 if you are work on Dubbo 2.7
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Add some description to dubbo-website project if you are requesting to add a feature.
  • GitHub Actions works fine on your own branch.
  • If this contribution is large, please follow the Software Donation Guide.

Refactoring prevents RpcUtilsTest from creating mocks for invoker and repeating stubs. A method called creatmockinvoker is created. Set the url that needs to be returned as an argument to creatmockinvoker. Create invoker's mock object inside the method and stub it.
@codecov-commenter
Copy link

Codecov Report

Merging #13214 (9b18e3e) into 3.2 (a4a3fd7) will increase coverage by 0.00%.
The diff coverage is n/a.

@@            Coverage Diff            @@
##                3.2   #13214   +/-   ##
=========================================
  Coverage     69.44%   69.45%           
  Complexity        2        2           
=========================================
  Files          1649     1649           
  Lines         68725    68725           
  Branches      10014    10014           
=========================================
+ Hits          47728    47733    +5     
+ Misses        16405    16399    -6     
- Partials       4592     4593    +1     

see 36 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Co-authored-by: Albumen Kevin <jhq0812@gmail.com>
Copy link
Member

@AlbumenJ AlbumenJ left a comment

Choose a reason for hiding this comment

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

Also fix in your code

@gzhao9 gzhao9 requested a review from AlbumenJ October 17, 2023 09:38
@sonarcloud
Copy link

sonarcloud bot commented Oct 17, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@AlbumenJ AlbumenJ merged commit 3f07e68 into apache:3.2 Oct 18, 2023
14 checks passed
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.

None yet

3 participants