Is there a way to force Alamofire to do all of its work on the main thread? This is for a test scenario where I need the main thread to not continue execution until the network calls have completed and I know the status. The tests in question used to run under the XCTest
framework and so I would use XCTestExpectation
to wait for completion. The environment I'm using doesn't work with XCTest
and so I need Alamofire to be synchronous.
Since the first 2 comments have both suggested how I should test, let me provide a little more context.
I have about 100 tests that have been running just fine for the last 2 years. The tests are NOT unit tests but UI Tests using Google's EarlGrey 1. EarlGrey 1 provides UI testing that runs under XCTest so you can combine UI Testing with white box inspection of the app state. It's great.
Earl Grey 1 does not support iOS 13 and so I am porting the tests to EarlGrey 2, which runs on top of XCUITest. For the white box aspect, you make remote calls from the test process to a bundle that is injected into your app.
In this case the "mock" is the server, but it does make network calls and these happen when I call into the test bundle. I need to know when they finish so I can return after they're done.