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

NocillaUnexpectedRequest seems to jam NSURLSession queue #103

Open
mjholgate opened this issue Jan 9, 2015 · 2 comments
Open

NocillaUnexpectedRequest seems to jam NSURLSession queue #103

mjholgate opened this issue Jan 9, 2015 · 2 comments

Comments

@mjholgate
Copy link
Contributor

I'm a bit confused about how the NocillaUnexpectedRequest exception is supposed to work. Is the idea that it should halt the execution of the entire test suite, or rather that it should just fail an individual test?

The reason I ask is that I am migrating my project from ASIHTTPRequest to NSURLSession, and I noticed some strange problems.

ASIHTTPRequest was silently swallowing the NocillaUnexpectedRequest exceptions, so they were never seen, although I suspect I was getting an error returned from the HTTP request. It didn't matter in my tests though, as those particular tests didn't rely on the result of the unstubbed request.

However, with NSURLSession, I found that once the exception fired, no further HTTP requests could be made, and simply timed out thus causing later tests to fail. I think what may be happening is that it ended up crashing the NSOperationQueue that was being used to executing the requests by NSURLSession.

I added a nasty hack (#102) to force the exception to be raised in the main thread to make it visible, however, this obviously halted the entire test suite.

My question is, is this a bug? What is the intended behaviour of a NocillaUnexpectedRequest exception being raised?

@jonah-williams
Copy link

I ran into the same issue when adding Nocilla to an app which uses NSURLSession via Alamofire. At a minimum these exceptions are not visible as test failures or logs. In addition I see intermittent failures where it looks like the exception can halt other requests from being processed on that operation queue.

I remember Nocilla's exceptions cleanly failing tests the last time I used it but I can't say for sure if the difference is due to iOS 8 or NSURLSession.

PR #108 seems like a useful improvement to me. However that still does not necessarily surface unexpected requests, it depends on how the app under test responds to failed requests.

For reference, exceptions in operation queues: ConcurrencyProgrammingGuide

@jonah-williams
Copy link

I've found that at a minimum wrapping https://github.com/luisobo/Nocilla/blob/master/Nocilla/LSNocilla.m#L79 in a dispatch_async(dispatch_get_main_queue(), ^{...} block is an improvement over the current behavior. That at least halts and fails the test suite (though potentially after the test which triggered the unexpected request). As is I'm seeing large numbers of tests fail in confusing ways when the NSURLSession's operation queue dies due to the exception.

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

No branches or pull requests

2 participants