Skip to content

Commit 8ef1f4e

Browse files
committed
changed timesource to use clock
revert var
1 parent 70f9f0a commit 8ef1f4e

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

Tests/DistributedClusterTests/Cluster/SWIM/SWIMActorClusteredTests.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,18 +484,21 @@ final class SWIMActorClusteredTests: ClusteredActorSystemsXCTestCase {
484484
}
485485

486486
class TestTimeSource {
487-
let currentTime: UnsafeAtomic<UInt64>
487+
private var instant: ContinuousClock.Instant
488488

489-
/// starting from 1 to ensure .distantPast is already expired
490-
init(currentTime: UInt64 = 1) {
491-
self.currentTime = .create(currentTime)
489+
/// starting from a value close to the distant past
490+
init(currentTime: ContinuousClock.Instant = (.now - .nanoseconds(1))) {
491+
self.instant = currentTime
492492
}
493493

494-
func now() -> DispatchTime {
495-
DispatchTime(uptimeNanoseconds: self.currentTime.load(ordering: .relaxed))
494+
/// Returns the current mocked time as ContinuousClock.Instant
495+
@Sendable
496+
func now() -> ContinuousClock.Instant {
497+
self.instant
496498
}
497499

498-
func tick() {
499-
_ = self.currentTime.loadThenWrappingIncrement(by: 100, ordering: .relaxed)
500+
/// Advances the mocked time by the specified duration (default 100 nanoseconds, for compatibility)
501+
func tick(by duration: Duration = .nanoseconds(100)) {
502+
self.instant += duration
500503
}
501504
}

0 commit comments

Comments
 (0)