Skip to content

Instantly share code, notes, and snippets.

@sisoje
Last active February 15, 2019 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sisoje/4a73e36ffbe917a25d14deacd814bfc9 to your computer and use it in GitHub Desktop.
Save sisoje/4a73e36ffbe917a25d14deacd814bfc9 to your computer and use it in GitHub Desktop.
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)
}
}
@sisoje
Copy link
Author

sisoje commented Feb 15, 2019

works with autoreleasepool, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment