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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP exponential backoff for node/go clients #89

Merged
merged 2 commits into from Nov 4, 2016
Merged

Conversation

rgarcia
Copy link
Member

@rgarcia rgarcia commented Nov 4, 2016

also first node client test

currently this branch just contains direct modifications to the generated client code. I will autogenerate the code after I get the 馃憤 from @cozmo and @kvigen.

Copy link
Contributor

@cozmo cozmo left a comment

Choose a reason for hiding this comment

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

Some random nits around the JS client but it's looking real nice.

@@ -13,6 +13,28 @@ function serializeQueryString(data) {
return data;
}

const defaultRetryPolicy = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want to export this right?

Copy link
Contributor

Choose a reason for hiding this comment

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

module.exports.RetryPolicies = {defaultRetryPolicy};?

Copy link
Member Author

Choose a reason for hiding this comment

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

馃憤 58eee55

}
resolver(body);
});
const retryPolicy = this.retryPolicy || options.retryPolicy || defaultRetryPolicy;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can I pass null as a retryPolicy? I feel like in the current model I can't.

Copy link
Contributor

Choose a reason for hiding this comment

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

But that is something I would assume I'd be able to do.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm assuming by null you're trying to communicate "no retries"? If so, I think I'd rather export a NoRetryPolicy that you can pass (this is what I do with the Go client)

Copy link
Member Author

Choose a reason for hiding this comment

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

check this out 3e5d27b

let requestCount = 0;
let requestTimes = [];
const scope = nock("http://localhost:8000")
.get("/v1/books")
Copy link
Contributor

Choose a reason for hiding this comment

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

indents look a little funky here.

@@ -0,0 +1,35 @@
const assert = require("assert");
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests look real nice - can we make them run as part of make test in the wag repo?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, will set that up once this is all auto-generated. Right now it'll all get overwritten in CI

Copy link
Contributor

Choose a reason for hiding this comment

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

we're still thinking of writing some tests where we don't mock the server along with these, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I think we should eventually write some full E2E tests, but I'm not sure the best way to structure them...


module.exports.RetryPolicies = {
Default: defaultRetryPolicy,
No: noRetryPolicy,
Copy link
Contributor

Choose a reason for hiding this comment

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

s/no/none/?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@kvigen kvigen left a comment

Choose a reason for hiding this comment

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

i like the RetryPolicy interface. had some minor comments, but overall looks good

if r.Method == "POST" || r.Method == "PATCH" {
return resp, err
// Retry will retry non-POST, non-PATCH requests that 5XX.
// TODO: It does not currently retry any errors returned by net/http.Client's `Do`.
Copy link
Contributor

Choose a reason for hiding this comment

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

fyi, here's the Go transport retrying I mentioned https://github.com/golang/go/blob/master/src/net/http/transport.go#L403-L450

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

the rest of the retry logic there is pretty cryptic to me... do you understand what it's doing?

Copy link
Contributor

Choose a reason for hiding this comment

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

only kind of. i'm still digging through the Go http library. will let you know if i understand it better as i read more

@@ -93,7 +95,10 @@ func TestDefaultClientRetries(t *testing.T) {
c := client.New(testServer.URL)
_, err := c.GetBooks(context.Background(), &models.GetBooksInput{})
assert.NoError(t, err)
assert.Equal(t, 2, controller.getCount)
backoff := controller.getTimes[1].Sub(controller.getTimes[0])
if backoff < 90*time.Millisecond || backoff > 110*time.Millisecond {
Copy link
Contributor

Choose a reason for hiding this comment

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

i recently learned about https://github.com/stretchr/testify/blob/master/assert/assertions.go#L722-L727 which makes this assert a little nicer

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -93,7 +95,10 @@ func TestDefaultClientRetries(t *testing.T) {
c := client.New(testServer.URL)
_, err := c.GetBooks(context.Background(), &models.GetBooksInput{})
assert.NoError(t, err)
assert.Equal(t, 2, controller.getCount)
backoff := controller.getTimes[1].Sub(controller.getTimes[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

should we add a test for more than one retry?

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -0,0 +1,35 @@
const assert = require("assert");
Copy link
Contributor

Choose a reason for hiding this comment

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

we're still thinking of writing some tests where we don't mock the server along with these, right?

@kvigen kvigen assigned rgarcia and unassigned kvigen Nov 4, 2016
@rgarcia rgarcia force-pushed the exponential-backoff branch 3 times, most recently from 1298537 to d37c7bc Compare November 4, 2016 19:41
@rgarcia rgarcia force-pushed the exponential-backoff branch 2 times, most recently from cb475d7 to 7327252 Compare November 4, 2016 20:11
@rgarcia
Copy link
Member Author

rgarcia commented Nov 4, 2016

@cozmo finished auto generating everything and moved the js tests to their own directory--want to give it a final review?

@@ -0,0 +1,5 @@
ca = null
//registry.npmjs.org/:_authToken=${npm_auth_token}
Copy link
Contributor

Choose a reason for hiding this comment

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

Only minor comment is I'd love to s/npm_auth_token/npm_token/ to be more consistent with the npm changes I made to the 60 repos over the last week.

Copy link
Member Author

Choose a reason for hiding this comment

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

@cozmo
Copy link
Contributor

cozmo commented Nov 4, 2016

@rgarcia Left one minor comment but otherwise LGTM.

@rgarcia rgarcia merged commit a1611c1 into master Nov 4, 2016
@rgarcia rgarcia deleted the exponential-backoff branch November 4, 2016 21:25
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