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

LSNocilla.sharedInstance().stop() Not working #136

Open
fcruzsbtv opened this issue Feb 25, 2016 · 5 comments
Open

LSNocilla.sharedInstance().stop() Not working #136

fcruzsbtv opened this issue Feb 25, 2016 · 5 comments

Comments

@fcruzsbtv
Copy link

I have a multiple test set, one of them uses nocilla so I execute LSNocilla.sharedInstance().start() when it begin and stop it at the end, but when the other test that needs actual internet runs I keep getting "NocillaUnexpectedRequest', reason: 'An unexpected HTTP request was fired.'"

@andrewkboyd
Copy link
Collaborator

I don't know what you mean by 'multiple test set'

Please provide sample code that reproduces the issue/more detail. I don't know how to look into it based on the info you have provided.

@stepanhruda
Copy link
Collaborator

Just ran into and debugged this issue. The problem happens if you create a new URL session when Nocilla is running, then stop Nocilla and continue using the session.

Nocilla swizzles the URL protocols on the default configuration – it cleans them up from the default configuration, but when creating a new session they are likely transferred to the session object, so any session objects created continue intercepting requests.

https://github.com/luisobo/Nocilla/blob/master/Nocilla/Hooks/NSURLSession/LSNSURLSessionHook.m

@nmarkovic04
Copy link

Yep, just ran into this problem that @stepanhruda described.

  1. Test runs fine, expectation is fulfilled.
  2. In -tearDown, LSNocilla.sharedInstance().stop() is called.
  3. The request that is called as a result of the stubbed request gets intercepted after .calling .stop().

e.g. We stub /user/login to return 200 OK. Works fine, but sync data gets called as a result of successful login. We can stub that request too, but it makes no difference since it gets called after .stop(). In other words, at the moment when - (LSStubResponse *)responseForRequest:(id<LSHTTPRequest>)actualRequest { is called, (lldb) po self.started returns NO, and self.requests has 0 elements so it will always throw the exception.

@rohan-panchal
Copy link

I'm experiencing this too.

Right now i just fixed it by using an instance of the network client rather than the shared singleton.

But reproduction steps are the same.

@Wooder
Copy link

Wooder commented Dec 29, 2016

I'm experiencing this too.

I "fixed" it with this workaround (calling the stop-function in the setUp()-functions code):

    override func setUp() {
        super.setUp()
        if (LSNocilla.sharedInstance().isStarted) {
            LSNocilla.sharedInstance().stop()
        }
        LSNocilla.sharedInstance().start()
        ...
    }
    
    override func tearDown() {
        //LSNocilla.sharedInstance().stop() // causes "NocillaUnexpectedRequest', reason: 'An unexpected HTTP request was fired.'"
        super.tearDown()
    }

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

6 participants