Hello,
I’m curious if there’s interest in adding a controllable or “test” clock to swift-testing. I’ve found in my own projects that being able to manipulate and advance time deterministically during unit tests can be incredibly helpful, especially for testing features like retries, delays, and timeouts.
Here’s a rough sketch of the kind of interface I have in mind:
struct TestClock<Duration>: Clock {
func sleep(until deadline: Instant, tolerance: Instant.Duration?) async throws
func advance(to instant: Instant)
func advance(by duration Duration)
}
The idea would be to provide a clock implementation where time only moves forward when you explicitly tell it to, which enables precise and reliable testing of time-based behavior.
I’ve seen similar utilities (or actually a clock with almost the same interface and functionality) in Pointfree‘s swift-clocks GitHub - pointfreeco/swift-clocks: ⏰ A few clocks that make working with Swift concurrency more testable and more versatile., but introducing a full dependency solely for test purposes can feel a bit heavy, especially when the functionality needed is quite (test) focused.
Would others find this useful in swift-testing? I’d love to hear if anyone else has run into the same need or has thoughts on design or scope.
Thanks.