Skip to content

Commit

Permalink
Merge pull request #243 from BoltsFramework/nlutsenko.flakytest
Browse files Browse the repository at this point in the history
Fix flaky test in TaskTests.
  • Loading branch information
nlutsenko committed Mar 30, 2016
2 parents 5c47fa7 + aaa6d76 commit f8db004
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions BoltsTests/TaskTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -637,16 +637,22 @@ - (void)testTasksForTaskForCompletionOfAnyTasksWithSuccess {
}

- (void)testTasksForTaskForCompletionOfAnyTasksWithRacing {
BFTask *first = [[BFTask taskWithDelay:2] continueWithBlock:^id _Nullable(BFTask * _Nonnull task) {
return [BFTask taskWithResult:@"first"];
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);

BFExecutor *executor = [BFExecutor executorWithDispatchQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];

BFTask *first = [BFTask taskFromExecutor:executor withBlock:^id _Nullable {
return @"first";
}];
BFTask *second = [[BFTask taskWithDelay:3] continueWithBlock:^id _Nullable(BFTask * _Nonnull task) {
return [BFTask taskWithResult:@"second"];
BFTask *second = [BFTask taskFromExecutor:executor withBlock:^id _Nullable {
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
return @"second";
}];


BFTask *task = [BFTask taskForCompletionOfAnyTask:@[first, second]];
[task waitUntilFinished];

dispatch_semaphore_signal(semaphore);

XCTAssertEqualObjects(@"first", task.result);
}
Expand Down

0 comments on commit f8db004

Please sign in to comment.