Last active
February 15, 2019 10:48
-
-
Save sisoje/4a73e36ffbe917a25d14deacd814bfc9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
import Foundation | |
class TestFulfill: XCTestCase { | |
class FulfillOnRelease { | |
let ex: XCTestExpectation | |
init(_ ex: XCTestExpectation) { | |
self.ex = ex | |
} | |
deinit { | |
print("Fullfiling: \(ex.description)") | |
ex.fulfill() | |
} | |
} | |
func testFulfillWithDispatchOk() { | |
let queue = DispatchQueue(label: #function) | |
(0..<3).forEach { index in | |
let ex = expectation(description: "\(#function) \(index)") | |
let fulfillOnRelease = FulfillOnRelease(ex) | |
queue.async { | |
print("Retaining: \(fulfillOnRelease.ex.description)") | |
} | |
} | |
waitForExpectations(timeout: 1, handler: nil) | |
} | |
func testFulfillWithOperationQueueBad() { | |
let queue = OperationQueue() | |
(0..<3).forEach { index in | |
let ex = expectation(description: "\(#function) \(index)") | |
let fulfillOnRelease = FulfillOnRelease(ex) | |
queue.addOperation { | |
print("Retaining: \(fulfillOnRelease.ex.description)") | |
} | |
} | |
waitForExpectations(timeout: 1, handler: nil) | |
} | |
func testFulfillWithOperationQueueOk() { | |
let queue = OperationQueue() | |
(0..<3).forEach { index in | |
let ex = expectation(description: "\(#function) \(index)") | |
let fulfillOnRelease = FulfillOnRelease(ex) | |
let blockOperation = BlockOperation { | |
print("Retaining: \(fulfillOnRelease.ex.description)") | |
} | |
queue.addOperation(blockOperation) | |
} | |
waitForExpectations(timeout: 1, handler: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
works with autoreleasepool, thanks