summaryrefslogtreecommitdiffhomepage
path: root/ios/OperationsTests/OperationSmokeTests.swift
blob: 6d66e6e632015f5d789f8f3daaa912300facd981 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
//  OperationSmokeTests.swift
//  MullvadVPNTests
//
//  Created by pronebird on 09/06/2022.
//  Copyright © 2022 Mullvad VPN AB. All rights reserved.
//

import Operations
import XCTest

class OperationSmokeTests: XCTestCase {
    func testBatch() {
        let expect = expectation(description: "Expect all operations to finish.")
        let operationQueue = AsyncOperationQueue()

        let operations = (1 ... 500).flatMap { i -> [Operation] in
            let parent = BlockOperation()
            parent.cancel()

            let child = AsyncBlockOperation {
                print("Execute block operation \(i)")
            }

            child.addDependency(parent)
            child.addCondition(NoFailedDependenciesCondition(ignoreCancellations: true))

            return [parent, child]
        }

        let dispatchQueue = DispatchQueue(label: "com.OperationSmokeTests.testBatch")
        dispatchQueue.async {
            operationQueue.addOperations(operations, waitUntilFinished: true)
            expect.fulfill()
        }

        waitForExpectations(timeout: 1)
    }
}