-
Notifications
You must be signed in to change notification settings - Fork 5
/
GroupWorkTests.swift
51 lines (41 loc) · 1013 Bytes
/
GroupWorkTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import XCTest
import GroupWork
#if os(Linux)
import Dispatch
#endif
class GroupWorkTests: XCTestCase {
func test() {
let expectation = self.expectation(description: #function)
let work = GroupWork()
work.shortAsync()
work.longAsync()
work.allDone {
XCTAssert(work.result)
expectation.fulfill()
}
waitForExpectations(timeout: 10)
}
}
extension GroupWork {
func shortAsync() {
start()
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
self.finish(withResult: true)
}
}
func longAsync() {
start()
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2)) {
self.finish(withResult: true)
}
}
}
#if os(Linux)
extension GroupWorkTests {
static var allTests: [(String, (GroupWorkTests) -> () throws -> Void)] {
return [
("test", test)
]
}
}
#endif