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

Not working with URLSessionConfiguration.background #97

Open
NeverwinterMoon opened this issue Apr 24, 2018 · 0 comments
Open

Not working with URLSessionConfiguration.background #97

NeverwinterMoon opened this issue Apr 24, 2018 · 0 comments

Comments

@NeverwinterMoon
Copy link

NeverwinterMoon commented Apr 24, 2018

It looks to be similar to: #50 which was marked as fixed.

I have a SessionManager initialized as a singleton and then used in the service under test. I first stub everything with Mockingjay and then call one of the service's methods, this in turn makes a request using Alamofire SessionManager. And the real request goes through.

Now, if I don't use the singleton SessionManager and create it inside the test, then pass it to the service under test, then Mockingjay stubbing works.

Interestingly enough, in the original scenario, the SessionManager singleton is actually only called (so, initialized) for the first time in the service under test (I don't use the real AppDelegate in unit tests), meaning (I might still be wrong on this though) that the stub is called before the SessionManager is even created and still this fails to work...

Xcode 9.3
Swift 4.1
Alamofire 4.7.2
Mockingjay 2.0.1

EDIT

OK, this is more clear now. It's not about just SessionManager, but about the manager using non-default configuration:

static let sessionManager: Alamofire.SessionManager = {
    let configuration = URLSessionConfiguration.background(withIdentifier: "XXX")
    configuration.timeoutIntervalForRequest = 60

    return Alamofire.SessionManager(configuration: configuration)
  }()

When not using background configuration, stubbing works.

@NeverwinterMoon NeverwinterMoon changed the title Not working with Alamofire SessionManager singleton Not working with URLSessionConfiguration.background Apr 24, 2018
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

1 participant