@@ -34,6 +34,7 @@ class TestOperationQueue : XCTestCase {
34
34
( " test_CancelWhileSuspended " , test_CancelWhileSuspended) ,
35
35
( " test_OperationOrder " , test_OperationOrder) ,
36
36
( " test_OperationOrder2 " , test_OperationOrder2) ,
37
+ ( " test_ExecutionOrder " , test_ExecutionOrder) ,
37
38
( " test_WaitUntilFinished " , test_WaitUntilFinished) ,
38
39
( " test_OperationWaitUntilFinished " , test_OperationWaitUntilFinished) ,
39
40
( " test_CustomOperationReady " , test_CustomOperationReady) ,
@@ -531,6 +532,32 @@ class TestOperationQueue : XCTestCase {
531
532
XCTAssertEqual ( array, [ 5 , 4 , 3 , 2 , 1 ] )
532
533
}
533
534
535
+ func test_ExecutionOrder( ) {
536
+ let queue = OperationQueue ( )
537
+
538
+ let didRunOp1 = expectation ( description: " Did run first operation " )
539
+ let didRunOp1Dependency = expectation ( description: " Did run first operation dependency " )
540
+ let didRunOp2 = expectation ( description: " Did run second operation " )
541
+ var didRunOp1DependencyFirst = false
542
+
543
+ let op1 = BlockOperation {
544
+ didRunOp1. fulfill ( )
545
+ XCTAssertTrue ( didRunOp1DependencyFirst, " Dependency should be executed first " )
546
+ }
547
+ let op1Dependency = BlockOperation {
548
+ didRunOp1Dependency. fulfill ( )
549
+ didRunOp1DependencyFirst = true
550
+ }
551
+ op1. addDependency ( op1Dependency)
552
+ queue. addOperations ( [ op1, op1Dependency] , waitUntilFinished: false )
553
+
554
+ queue. addOperation {
555
+ didRunOp2. fulfill ( )
556
+ }
557
+
558
+ waitForExpectations ( timeout: 1.0 )
559
+ }
560
+
534
561
func test_WaitUntilFinished( ) {
535
562
let queue1 = OperationQueue ( )
536
563
let queue2 = OperationQueue ( )
0 commit comments