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

Resume alamofire request only and only if it hasn't been started previously #167

Merged
merged 3 commits into from
Jan 25, 2017

Conversation

piv199
Copy link

@piv199 piv199 commented Jan 12, 2017

fixes #163

Tested in the example with starts immediately true || false, now it's working as expected... So no second call for alamofire request resume method.

@pcantrell
Copy link
Member

Awesome! Thank you for taking this on.

I’ll add a couple of minor project style consistency things in the review notes.

It would be great to get regression tests for this. It’s subtle enough — and easy enough to mess up — that it’s worth covering.

I take it that if alamofireRequest.task, then resume() is the correct action to take? If I’m following that correctly, your ?? solution is a nice bit of concise ingenuity. When does nil task even happen, and how is it different from suspended? This question has a bearing on how the specs would be structured.

@@ -56,7 +56,9 @@ internal struct AlamofireRequestNetworking: RequestNetworking, SessionTaskContai
init(_ alamofireRequest: Alamofire.Request)
{
self.alamofireRequest = alamofireRequest
alamofireRequest.resume() // in case manager.startRequestsImmediately is false
if case .suspended = self.alamofireRequest.task?.state ?? .suspended {
Copy link
Member

Choose a reason for hiding this comment

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

This project never uses superfluous self.

@@ -56,7 +56,9 @@ internal struct AlamofireRequestNetworking: RequestNetworking, SessionTaskContai
init(_ alamofireRequest: Alamofire.Request)
{
self.alamofireRequest = alamofireRequest
alamofireRequest.resume() // in case manager.startRequestsImmediately is false
if case .suspended = self.alamofireRequest.task?.state ?? .suspended {
alamofireRequest.resume() // in case manager.startRequestsImmediately is false
Copy link
Member

Choose a reason for hiding this comment

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

I know the brace & indentation conventions of the project are weird, but please do follow them. Brace rules are at the end of the README, or you can just look around the project for examples.

@piv199
Copy link
Author

piv199 commented Jan 13, 2017

It would be great to get regression tests for this. It’s subtle enough — and easy enough to mess up — that it’s worth covering.

I' not familiar with tests you have, also I haven't found siesta+alamofire tests at all...

When does nil task even happen, and how is it different from suspended?

As for Alamofire sources, task should not be nil. When we initializing the Request object we pass there a task (that could be nil). So possibly, if something went wrong while creating a URLSessionTask object than nil will be passed to Alamofire.Request. Actually resume has guard for checking on task existense - it means that we could not resume task that is nil.

@pcantrell
Copy link
Member

pcantrell commented Jan 14, 2017

I haven't found siesta+alamofire tests at all...

The existing tests rerun a large subset of the tests serval times on CI using four different networking provider/setting combinations, making sure that all the different underlying providers result in the same Siesta behavior.

We could add a fifth provider to that suite with startRequestsImmediately = false, and maybe that would be a good sanity check, but that doesn’t actually catch the original problem your PR fixes! The reason is that the existing strategy only tests Siesta behavior via the provider, but the bug you found affects underlying Alamofire behavior not exposed through Siesta. So this bug calls for a new regression test in a new file.

I' not familiar with tests you have

If you give me push access to your pull request, I can drop the test in the right place.

@piv199
Copy link
Author

piv199 commented Jan 14, 2017

@pcantrell This option is selected

  • Allow edits from maintainers.

@pcantrell
Copy link
Member

I dug into this a bit, and decided that the substantial amount of code it would take to test the fix simply isn’t justified. Sorry for the long delay on accepting this, @piv199, and thanks again so much for chasing the issue down!

Did you file an issue with Alamofire about the redundant notification? It really does seem like that’s a bug.

@pcantrell pcantrell merged commit 3e274b9 into bustoutsolutions:master Jan 25, 2017
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.

NetworkActivityIndicatorManager + Siesta stucks forever
2 participants