@@ -858,4 +858,43 @@ - (void)testTrySetCancelled {
858
858
XCTAssertTrue (taskCompletionSource.task .cancelled );
859
859
}
860
860
861
+ - (void )testMultipleWaitUntilFinished {
862
+ BFTask *task = [[BFTask taskWithDelay: 50 ] continueWithBlock: ^id (BFTask *task) {
863
+ return @" foo" ;
864
+ }];
865
+
866
+ [task waitUntilFinished ];
867
+
868
+ XCTestExpectation *expectation = [self expectationWithDescription: NSStringFromSelector (_cmd )];
869
+ dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
870
+ [task waitUntilFinished ];
871
+ [expectation fulfill ];
872
+ });
873
+ [self waitForExpectationsWithTimeout: 10.0 handler: nil ];
874
+ }
875
+
876
+ - (void )testMultipleThreadsWaitUntilFinished {
877
+ BFTask *task = [[BFTask taskWithDelay: 500 ] continueWithBlock: ^id (BFTask *task) {
878
+ return @" foo" ;
879
+ }];
880
+
881
+ dispatch_queue_t queue = dispatch_queue_create (" com.bolts.tests.wait" , DISPATCH_QUEUE_CONCURRENT);
882
+ dispatch_group_t group = dispatch_group_create ();
883
+
884
+ XCTestExpectation *expectation = [self expectationWithDescription: NSStringFromSelector (_cmd )];
885
+ dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
886
+ dispatch_group_async (group, queue, ^{
887
+ [task waitUntilFinished ];
888
+ });
889
+ dispatch_group_async (group, queue, ^{
890
+ [task waitUntilFinished ];
891
+ });
892
+ [task waitUntilFinished ];
893
+
894
+ dispatch_group_wait (group, DISPATCH_TIME_FOREVER);
895
+ [expectation fulfill ];
896
+ });
897
+ [self waitForExpectationsWithTimeout: 10.0 handler: nil ];
898
+ }
899
+
861
900
@end
0 commit comments