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 17c72c7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Tests/ExecutorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,18 @@ class ExecutorTests: XCTestCase {
func testQueueExecute() {
let expectation = expectationWithDescription(currentTestName)
var finished = false
let semaphore = dispatch_semaphore_create(0)

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 @@ -79,15 +83,19 @@ class ExecutorTests: XCTestCase {
func testOperationQueueExecute() {
let expectation = expectationWithDescription(currentTestName)
let operationQueue = NSOperationQueue()
let semaphore = dispatch_semaphore_create(0)
var finished = false

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 17c72c7

Please sign in to comment.