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

request with context #57

Closed
wants to merge 4 commits into from

Conversation

xjewer
Copy link
Contributor

@xjewer xjewer commented Nov 29, 2016

With context you can to cancel request when it goes longer than necessary https://godoc.org/context#WithTimeout

import "context" works only >= go1.7, so i divided PushWithCtx method along with build tags !go1.7 and go1.7 into the distinct files with "net/context" and "context" respectively

@coveralls
Copy link

coveralls commented Nov 29, 2016

Coverage Status

Coverage increased (+0.2%) to 89.822% when pulling c2d3389 on xjewer:feature_request_with_context into 734432d on sideshow:master.

@xjewer xjewer force-pushed the feature_request_with_context branch from 3176f9f to 9593f63 Compare November 29, 2016 14:35
@coveralls
Copy link

coveralls commented Nov 29, 2016

Coverage Status

Coverage increased (+0.2%) to 89.822% when pulling 3176f9f on xjewer:feature_request_with_context into 734432d on sideshow:master.

@coveralls
Copy link

coveralls commented Nov 29, 2016

Coverage Status

Coverage increased (+0.2%) to 89.822% when pulling 9593f63 on xjewer:feature_request_with_context into 734432d on sideshow:master.

@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage increased (+0.2%) to 89.822% when pulling b2dabee on xjewer:feature_request_with_context into 734432d on sideshow:master.

@xjewer xjewer force-pushed the feature_request_with_context branch from b2dabee to 16b818e Compare November 30, 2016 08:06
@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage increased (+0.9%) to 90.521% when pulling 16b818e on xjewer:feature_request_with_context into 734432d on sideshow:master.

@xjewer
Copy link
Contributor Author

xjewer commented Nov 30, 2016

/cc @sideshow

@sideshow
Copy link
Owner

sideshow commented Jan 4, 2017

@xjewer this looks really good, Thanks for the PR

@@ -0,0 +1,50 @@
// +build go1.7
Copy link

@nordicdyno nordicdyno Jan 14, 2017

Choose a reason for hiding this comment

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

I think it's better to use !go1.6 here for Go >=1.8 compatibility. Anyway Go < 1.6 is not supported by this lib

Copy link

Choose a reason for hiding this comment

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

This is okay. "from Go version 1.7 onward" https://golang.org/pkg/go/build/

Though I don't know if it's needed.

@xjewer
Copy link
Contributor Author

xjewer commented Feb 3, 2017

@xjewer this looks really good, Thanks for the PR

So, what about this PR? Would you merge it or not? @sideshow

Copy link

@nathany nathany left a comment

Choose a reason for hiding this comment

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

I think it makes sense to support context. @sideshow do you agree?

Maybe this could be done in a cleaner way though (see below)

// gateway, or an error if something goes wrong.
//
// Context with deadline allows to close long request when context timeout exceed. It can be nil, for back compatibility
func (c *Client) PushWithCtx(n *Notification, ctx context.Context) (*Response, error) {
Copy link

Choose a reason for hiding this comment

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

There should be a way to minimize the duplication between the Go 1.6 and Go 1.7+ versions of this.

context.Context is an interface with the same definition in both packages, so they are interchangeable.

https://golang.org/pkg/context/#Context
https://godoc.org/golang.org/x/net/context#Context

I'm not sure the best way to do this, but even redefining the Context interface locally should allow either one to be passed in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure, that it costs the time to try to reduce a duplication in this part of code

Copy link

Choose a reason for hiding this comment

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

The problem with the duplication is that future changes need to made in both places. If they are not, the code could diverge in behaviour between Go versions. If there isn't any other option, good tests and continuous integration on multiple Go versions can help.

I await a verdict/suggestions from @sideshow.

Copy link
Owner

@sideshow sideshow Feb 15, 2017

Choose a reason for hiding this comment

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

I agree @nathany there we should look to remove the duplication given the fact that Context is part of the standard library now. @xjewer I can help if needed

client_test.go Outdated
@@ -16,6 +16,7 @@ import (
apns "github.com/sideshow/apns2"
"github.com/sideshow/apns2/certificate"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
Copy link

Choose a reason for hiding this comment

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

It would be good to see two versions of the context tests in separate files with appropriate build tags, just to ensure that it works with either package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -93,31 +90,10 @@ func (c *Client) Production() *Client {
// transparently before sending the notification. It will return a Response
// indicating whether the notification was accepted or rejected by the APNs
// gateway, or an error if something goes wrong.
//
// It wraps PushWithCtx for back compatibility.
func (c *Client) Push(n *Notification) (*Response, error) {
Copy link

Choose a reason for hiding this comment

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

@sideshow How important is API stability for this project? Do you want to keep the no-context version around?

Copy link
Owner

Choose a reason for hiding this comment

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

I think its pretty important to keep this old version around @nathany just so we don't break other projects that depend on it

@coveralls
Copy link

coveralls commented Feb 7, 2017

Coverage Status

Coverage increased (+0.8%) to 90.499% when pulling 2e8e495 on xjewer:feature_request_with_context into 19ab0d4 on sideshow:master.

Copy link
Owner

@sideshow sideshow left a comment

Choose a reason for hiding this comment

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

@nathany thanks for looking at this
@xjewer Sorry for taking so long to review, I was on holiday. I think the whole thing looks awesome, would love if we could remove the duplication as @nathany suggested between the Go 1.6 and Go 1.7+ if possible before merging.

// gateway, or an error if something goes wrong.
//
// Context with deadline allows to close long request when context timeout exceed. It can be nil, for back compatibility
func (c *Client) PushWithCtx(n *Notification, ctx context.Context) (*Response, error) {
Copy link
Owner

@sideshow sideshow Feb 15, 2017

Choose a reason for hiding this comment

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

I agree @nathany there we should look to remove the duplication given the fact that Context is part of the standard library now. @xjewer I can help if needed

"golang.org/x/net/context"
)

func TestClient_PushWithCtx_WithTimeout(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

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

Any chance we could change this to TestClientPushWithCtxWithTimeout just for consistency

@@ -93,31 +90,10 @@ func (c *Client) Production() *Client {
// transparently before sending the notification. It will return a Response
// indicating whether the notification was accepted or rejected by the APNs
// gateway, or an error if something goes wrong.
//
// It wraps PushWithCtx for back compatibility.
func (c *Client) Push(n *Notification) (*Response, error) {
Copy link
Owner

Choose a reason for hiding this comment

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

I think its pretty important to keep this old version around @nathany just so we don't break other projects that depend on it

@sideshow sideshow mentioned this pull request Apr 9, 2017
@sideshow
Copy link
Owner

@xjewer Thanks for this PR. @nathany thanks for the review.

I have rebased and changed a few things here #81 and would like your feedback.

I am closing this one but please feel free to weigh in on the new PR.

@sideshow sideshow closed this Apr 13, 2017
@xjewer xjewer deleted the feature_request_with_context branch April 24, 2017 07:15
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.

5 participants