func testExitsInterationEarly()

in source/UberCoreTests/AsyncDispatcherTests.swift [73:104]


    func testExitsInterationEarly() {
        let urls: [URL] = [ URL(string: "http://www.google.com")!,
                            URL(string: "http://www.uber.com")!,
                            URL(string: "http://www.facebook.com")! ]

        let finallyExp = XCTestExpectation(description: "finally closure should be called")

        var emittedErrors = [NSError]()

        AsyncDispatcher.exec(for: urls,
                             with: { _ in },
                             asyncMethod: openURLTestMethod(_:completion:),
                             continue: { (error: NSError?) -> Bool in
                                if let error = error {
                                    emittedErrors.append(error)
                                    if error.domain == "http://www.uber.com" {
                                        return false
                                    }
                                }
                                return true
                             },
                             finally: {
                                finallyExp.fulfill()
                             })

        wait(for: [finallyExp], timeout: 0.1)

        let expectedErrors = [ NSError(domain: "http://www.google.com", code: 0, userInfo: nil),
                               NSError(domain: "http://www.uber.com", code: 0, userInfo: nil) ]

        XCTAssertEqual(emittedErrors, expectedErrors)
    }