1
- @ testable import _ConnectionPoolModule
1
+ import _ConnectionPoolModule
2
2
import Atomics
3
3
import DequeModule
4
+ import NIOConcurrencyHelpers
4
5
5
6
@available ( macOS 13 . 0 , iOS 16 . 0 , tvOS 16 . 0 , watchOS 9 . 0 , * )
6
- final class MockClock : Clock {
7
- struct Instant : InstantProtocol , Comparable {
8
- typealias Duration = Swift . Duration
7
+ public final class MockClock : Clock {
8
+ public struct Instant : InstantProtocol , Comparable {
9
+ public typealias Duration = Swift . Duration
9
10
10
- func advanced( by duration: Self . Duration ) -> Self {
11
+ public func advanced( by duration: Self . Duration ) -> Self {
11
12
. init( self . base + duration)
12
13
}
13
14
14
- func duration( to other: Self ) -> Self . Duration {
15
+ public func duration( to other: Self ) -> Self . Duration {
15
16
self . base - other. base
16
17
}
17
18
18
19
private var base : Swift . Duration
19
20
20
- init ( _ base: Duration ) {
21
+ public init ( _ base: Duration ) {
21
22
self . base = base
22
23
}
23
24
24
- static func < ( lhs: Self , rhs: Self ) -> Bool {
25
+ public static func < ( lhs: Self , rhs: Self ) -> Bool {
25
26
lhs. base < rhs. base
26
27
}
27
28
28
- static func == ( lhs: Self , rhs: Self ) -> Bool {
29
+ public static func == ( lhs: Self , rhs: Self ) -> Bool {
29
30
lhs. base == rhs. base
30
31
}
31
32
}
@@ -58,16 +59,18 @@ final class MockClock: Clock {
58
59
var continuation : CheckedContinuation < Void , any Error >
59
60
}
60
61
61
- typealias Duration = Swift . Duration
62
+ public typealias Duration = Swift . Duration
62
63
63
- var minimumResolution : Duration { . nanoseconds( 1 ) }
64
+ public var minimumResolution : Duration { . nanoseconds( 1 ) }
64
65
65
- var now : Instant { self . stateBox. withLockedValue { $0. now } }
66
+ public var now : Instant { self . stateBox. withLockedValue { $0. now } }
66
67
67
68
private let stateBox = NIOLockedValueBox ( State ( ) )
68
69
private let waiterIDGenerator = ManagedAtomic ( 0 )
69
70
70
- func sleep( until deadline: Instant , tolerance: Duration ? ) async throws {
71
+ public init ( ) { }
72
+
73
+ public func sleep( until deadline: Instant , tolerance: Duration ? ) async throws {
71
74
let waiterID = self . waiterIDGenerator. loadThenWrappingIncrement ( ordering: . relaxed)
72
75
73
76
return try await withTaskCancellationHandler {
@@ -131,7 +134,7 @@ final class MockClock: Clock {
131
134
}
132
135
133
136
@discardableResult
134
- func nextTimerScheduled( ) async -> Instant {
137
+ public func nextTimerScheduled( ) async -> Instant {
135
138
await withCheckedContinuation { ( continuation: CheckedContinuation < Instant , Never > ) in
136
139
let instant = self . stateBox. withLockedValue { state -> Instant ? in
137
140
if let scheduled = state. nextDeadlines. popFirst ( ) {
@@ -149,7 +152,7 @@ final class MockClock: Clock {
149
152
}
150
153
}
151
154
152
- func advance( to deadline: Instant ) {
155
+ public func advance( to deadline: Instant ) {
153
156
let waiters = self . stateBox. withLockedValue { state -> ArraySlice < Sleeper > in
154
157
precondition ( deadline > state. now, " Time can only move forward " )
155
158
state. now = deadline
0 commit comments