Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make advance by TimeInterval in TestScheduler possible #828

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# master
*Please add new entries at the top.*

1. `TestScheduler` can `advance` by `TimeInterval`. (#828)

1. Fixed spelling error in `Token` class documentation.

# 6.6.1
Expand Down
11 changes: 11 additions & 0 deletions Sources/Scheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,17 @@ public final class TestScheduler: DateScheduler {
lock.unlock()
}

/// Advances the virtualized clock by the given interval, dequeuing and
/// executing any actions along the way.
///
/// - parameters:
/// - interval: Interval by which the current date will be advanced.
public func advance(by interval: TimeInterval) {
lock.lock()
advance(to: currentDate.addingTimeInterval(interval))
lock.unlock()
}

/// Advances the virtualized clock to the given future date, dequeuing and
/// executing any actions up until that point.
///
Expand Down
9 changes: 9 additions & 0 deletions Tests/ReactiveSwiftTests/SchedulerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,15 @@ class SchedulerSpec: QuickSpec {
expect(scheduler.currentDate) == Date.distantFuture
expect(string) == "fuzzbuzzfoobar"
}

it("should advance by DispatchTimeInterval same as by TimeInterval") {
let schedulerB = TestScheduler(startDate: startDate)

scheduler.advance(by: .milliseconds(300))
schedulerB.advance(by: 0.3)

expect(scheduler.currentDate).to(equal(schedulerB.currentDate))
}
}
}
}