Skip to content

Commit cd7fdee

Browse files
committed
Add a test that fails for synchronous operations
1 parent 70f8af9 commit cd7fdee

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

TestFoundation/TestOperationQueue.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class TestOperationQueue : XCTestCase {
1515
("test_OperationPriorities", test_OperationPriorities),
1616
("test_OperationCount", test_OperationCount),
1717
("test_AsyncOperation", test_AsyncOperation),
18+
("test_SyncOperation", test_SyncOperation),
1819
("test_isExecutingWorks", test_isExecutingWorks),
1920
("test_MainQueueGetter", test_MainQueueGetter),
2021
("test_CancelOneOperation", test_CancelOneOperation),
@@ -104,6 +105,18 @@ class TestOperationQueue : XCTestCase {
104105
XCTAssertTrue(operation.isFinished)
105106
}
106107

108+
func test_SyncOperation() {
109+
let operation = SyncOperation()
110+
XCTAssertFalse(operation.isExecuting)
111+
XCTAssertFalse(operation.isFinished)
112+
113+
operation.start()
114+
115+
XCTAssertFalse(operation.isExecuting)
116+
XCTAssertTrue(operation.isFinished)
117+
XCTAssertTrue(operation.hasRun)
118+
}
119+
107120
func test_MainQueueGetter() {
108121
XCTAssertTrue(OperationQueue.main === OperationQueue.main)
109122

@@ -330,3 +343,14 @@ class AsyncOperation: Operation {
330343
}
331344

332345
}
346+
347+
class SyncOperation: Operation {
348+
349+
var hasRun = false
350+
351+
override func main() {
352+
Thread.sleep(forTimeInterval: 1)
353+
hasRun = true
354+
}
355+
356+
}

0 commit comments

Comments
 (0)