Skip to content

Commit 1adafd9

Browse files
committed
Add a test that fails for synchronous operations
1 parent 435b6a9 commit 1adafd9

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),
@@ -105,6 +106,18 @@ class TestOperationQueue : XCTestCase {
105106
XCTAssertTrue(operation.isFinished)
106107
}
107108

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

@@ -345,3 +358,14 @@ class AsyncOperation: Operation {
345358
}
346359

347360
}
361+
362+
class SyncOperation: Operation {
363+
364+
var hasRun = false
365+
366+
override func main() {
367+
Thread.sleep(forTimeInterval: 1)
368+
hasRun = true
369+
}
370+
371+
}

0 commit comments

Comments
 (0)