Skip to content

Commit

Permalink
Make ExecutorTests less flaky.
Browse files Browse the repository at this point in the history
  • Loading branch information
nlutsenko committed Mar 17, 2016
1 parent 9547946 commit 0d90be4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Tests/ExecutorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ class ExecutorTests: XCTestCase {

func testQueueExecute() {
let expectation = expectationWithDescription(currentTestName)
let semaphore = dispatch_semaphore_create(0)
var finished = false

Executor.Queue(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)).execute {
expectation.fulfill()
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER)
finished = true
expectation.fulfill()
}

XCTAssertFalse(finished)
dispatch_semaphore_signal(semaphore)
waitForExpectationsWithTimeout(0.5, handler: nil)
XCTAssertTrue(finished)
}

func testClosureExecute() {
Expand All @@ -78,16 +82,20 @@ class ExecutorTests: XCTestCase {

func testOperationQueueExecute() {
let expectation = expectationWithDescription(currentTestName)
let operationQueue = NSOperationQueue()
let semaphore = dispatch_semaphore_create(0)
var finished = false

let operationQueue = NSOperationQueue()
Executor.OperationQueue(operationQueue).execute {
expectation.fulfill()
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER)
finished = true
expectation.fulfill()
}

XCTAssertFalse(finished)
dispatch_semaphore_signal(semaphore)
waitForExpectationsWithTimeout(0.5, handler: nil)
XCTAssertTrue(finished)
}

// MARK: Descriptions
Expand Down

0 comments on commit 0d90be4

Please sign in to comment.