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

feat: add mutex to make Client thread-safe #827

Merged
merged 5 commits into from
Sep 2, 2024

Conversation

tttturtle-russ
Copy link

@tttturtle-russ tttturtle-russ commented Aug 27, 2024

Refer to #812 for more info.

closes #812

@jeevatkm
Copy link
Member

@tttturtle-russ The PR has many changes, which will take some time to review; I will get back to you. Thanks.

@tttturtle-russ
Copy link
Author

@jeevatkm Sure. If there is any problem just let me know.

Copy link
Member

@jeevatkm jeevatkm left a comment

Choose a reason for hiding this comment

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

@tttturtle-russ Thanks for creating for Resty v3 on branch main.

  • Please look at the individual comment and address it
  • PR level review comment: Please use the newly created getter methods on all test files (where applicable) instead of direct internal variable access.

client.go Outdated
Comment on lines 808 to 823
// client.SetError(&error{})
// // OR
Copy link
Member

Choose a reason for hiding this comment

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

@tttturtle-russ, please do not modify it; keep it as-is.

client.go Outdated
// // OR
// client.SetError(Error{})
// client.SetError(error{})
Copy link
Member

Choose a reason for hiding this comment

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

@tttturtle-russ, please do not modify it; keep it as-is.

client.go Outdated
@@ -689,86 +839,167 @@ func (c *Client) SetRedirectPolicy(policies ...interface{}) *Client {
}
return nil // looks good, go ahead
}

c.lock.Unlock()
Copy link
Member

Choose a reason for hiding this comment

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

@tttturtle-russ Any reason you didn't use defer c.lock.Unlock() next to lock line on 842?

context_test.go Outdated
Copy link
Member

Choose a reason for hiding this comment

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

@tttturtle-russ, is there any reason to modify the log lines on this file to change the case?

Copy link
Author

Choose a reason for hiding this comment

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

It's due to the global rename. Sorry for that.

example_test.go Outdated
@@ -154,7 +154,7 @@ func Example_put() {
Tags: []string{"article", "sample", "resty"},
}).
SetAuthToken("C6A79608-782F-4ED0-A11D-BD82FAD829CD").
SetError(&Error{}). // or SetError(Error{}).
SetError(&Error{}). // or SetError(error{}).
Copy link
Member

Choose a reason for hiding this comment

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

@tttturtle-russ The comment syntax does not need to be modified. If there is any reason, please don't hesitate to let me know.

request.go Outdated
@@ -333,7 +333,7 @@ func (r *Request) SetResult(res interface{}) *Request {
return r
}

// SetError method is to register the request `Error` object for automatic unmarshalling for the request,
// SetError method is to register the request `error` object for automatic unmarshalling for the request,
Copy link
Member

Choose a reason for hiding this comment

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

@tttturtle-russ This is incorrect; please revert this line.

request_test.go Outdated
Copy link
Member

Choose a reason for hiding this comment

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

@tttturtle-russ There is no need to modify the log lines in the file.

response.go Outdated
Copy link
Member

Choose a reason for hiding this comment

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

@tttturtle-russ There is no need to modify the log lines in the file.

resty_test.go Outdated
Copy link
Member

Choose a reason for hiding this comment

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

@tttturtle-russ There is no need to modify the log lines in the file.

retry.go Outdated
@@ -178,7 +178,7 @@ func sleepDuration(resp *Response, min, max time.Duration, attempt int) (time.Du
return jitterBackoff(min, max, attempt), nil
}

retryAfterFunc := resp.Request.client.RetryAfter
retryAfterFunc := resp.Request.client.retryAfter
Copy link
Member

Choose a reason for hiding this comment

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

@tttturtle-russ Please use the newly created getter method instead of direct internal field access.

retryAfterFunc := resp.Request.client.RetryAfter()

@tttturtle-russ
Copy link
Author

@jeevatkm Thanks for your review. I will revise them.

Copy link
Member

@jeevatkm jeevatkm left a comment

Choose a reason for hiding this comment

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

@tttturtle-russ Code updates looks good, can you please focus on test failures and test coverage improvements?

@tttturtle-russ
Copy link
Author

@jeevatkm I have fix the CI error and pushed a new commit.

Copy link

codecov bot commented Aug 31, 2024

Codecov Report

Attention: Patch coverage is 91.11111% with 28 lines in your changes missing coverage. Please review.

Project coverage is 95.53%. Comparing base (e6db160) to head (b425198).
Report is 16 commits behind head on main.

Files with missing lines Patch % Lines
client.go 89.66% 28 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #827      +/-   ##
==========================================
- Coverage   96.55%   95.53%   -1.02%     
==========================================
  Files          11       11              
  Lines        1682     1925     +243     
==========================================
+ Hits         1624     1839     +215     
- Misses         37       65      +28     
  Partials       21       21              

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

@jeevatkm
Copy link
Member

@tttturtle-russ Thanks for fixing the test cases.

Please have a look and take care of test case coverage.
https://github.com/go-resty/resty/pull/827/checks?check_run_id=29514869266

@tttturtle-russ
Copy link
Author

@jeevatkm Thanks for reviewing. I fixed the test case coverage and found a duplicated method. I remove it in the newest commit and now the code cov should be good.

@jeevatkm
Copy link
Member

jeevatkm commented Sep 1, 2024

Thanks, @tttturtle-russ, for improving test cases. Can you please check the code conflicts?

@tttturtle-russ
Copy link
Author

@jeevatkm I've resolved the conflict. I see a new public field in Client struct and I will write a new method for it.

@jeevatkm
Copy link
Member

jeevatkm commented Sep 2, 2024

@tttturtle-russ Lets do that in a separate PR. For now, let's get this PR finished and merged.

@jeevatkm
Copy link
Member

jeevatkm commented Sep 2, 2024

@tttturtle-russ There is Code format issue, maybe you can add that public field covered.

@tttturtle-russ
Copy link
Author

@jeevatkm Sure

@tttturtle-russ
Copy link
Author

@jeevatkm Everything should be fine now.

@jeevatkm
Copy link
Member

jeevatkm commented Sep 2, 2024

@tttturtle-russ The TestGenerateExecutedCurl failure started after I merged from branch v2 to branch main. It needs to investigate why it's failing.

Copy link
Member

@jeevatkm jeevatkm left a comment

Choose a reason for hiding this comment

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

@tttturtle-russ Thanks for your PR.

@jeevatkm jeevatkm merged commit f8a7343 into go-resty:main Sep 2, 2024
0 of 2 checks passed
@tttturtle-russ
Copy link
Author

@tttturtle-russ The TestGenerateExecutedCurl failure started after I merged from branch v2 to branch main. It needs to investigate why it's failing.

@jeevatkm Actually it works well from my side.

@jeevatkm
Copy link
Member

jeevatkm commented Sep 2, 2024

@tttturtle-russ What do you mean it works? Can you try this command at your end?

go test ./... -race -coverprofile=coverage.out -covermode=atomic -coverpkg=./...

You can also see failure in the tab Checks.

@tttturtle-russ
Copy link
Author

@jeevatkm I am sorry, it's not OK :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Client: Add Read-Write Mutex to struct to make all the client properties thread-safe
2 participants