Skip to content

Commit 3883d72

Browse files
authored
Make UnimplementedScheduler behave like ImmediateScheduler. (#69)
* Make UnimplementedScheduler behave like ImmediateScheduler. * tests * Add test related to #57
1 parent 5c337bb commit 3883d72

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

Sources/CombineSchedulers/UnimplementedScheduler.swift

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
An unimplemented scheduler scheduled an action to run immediately.
119119
"""
120120
)
121+
action()
121122
}
122123

123124
public func schedule(
@@ -132,6 +133,7 @@
132133
An unimplemented scheduler scheduled an action to run later.
133134
"""
134135
)
136+
action()
135137
}
136138

137139
public func schedule(
@@ -147,6 +149,7 @@
147149
An unimplemented scheduler scheduled an action to run on a timer.
148150
"""
149151
)
152+
action()
150153
return AnyCancellable {}
151154
}
152155
}

Tests/CombineSchedulersTests/TestSchedulerTests.swift

+14
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,18 @@ final class CombineSchedulerTests: XCTestCase {
235235
let count = await task.value
236236
XCTAssertEqual(count, 10)
237237
}
238+
239+
func testNowIsAdvanced() {
240+
let testScheduler = DispatchQueue.test
241+
let start = testScheduler.now
242+
243+
testScheduler.advance(by: .seconds(1))
244+
XCTAssertEqual(testScheduler.now, start.advanced(by: .seconds(1)))
245+
246+
testScheduler.advance()
247+
XCTAssertEqual(testScheduler.now, start.advanced(by: .seconds(1)))
248+
249+
testScheduler.advance(by: .seconds(1))
250+
XCTAssertEqual(testScheduler.now, start.advanced(by: .seconds(2)))
251+
}
238252
}

Tests/CombineSchedulersTests/UnimplementedSchedulerTests.swift

+18-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,26 @@
99

1010
XCTExpectFailure { _ = scheduler.now }
1111
XCTExpectFailure { _ = scheduler.minimumTolerance }
12-
XCTExpectFailure { scheduler.schedule(options: nil) {} }
1312
XCTExpectFailure {
14-
scheduler.schedule(after: .init(.init()), tolerance: .zero, options: nil) {}
13+
let expectation = self.expectation(description: "schedule")
14+
scheduler.schedule(options: nil) {
15+
expectation.fulfill()
16+
}
17+
self.wait(for: [expectation], timeout: 0.1)
1518
}
16-
_ = XCTExpectFailure {
17-
scheduler.schedule(after: .init(.init()), interval: 1, tolerance: .zero, options: nil) {}
19+
XCTExpectFailure {
20+
let expectation = self.expectation(description: "schedule")
21+
scheduler.schedule(after: .init(.init()), tolerance: .zero, options: nil) {
22+
expectation.fulfill()
23+
}
24+
self.wait(for: [expectation], timeout: 0.1)
25+
}
26+
XCTExpectFailure {
27+
let expectation = self.expectation(description: "schedule")
28+
_ = scheduler.schedule(after: .init(.init()), interval: 1, tolerance: .zero, options: nil) {
29+
expectation.fulfill()
30+
}
31+
self.wait(for: [expectation], timeout: 0.1)
1832
}
1933
}
2034
}

0 commit comments

Comments
 (0)