@@ -42,6 +42,25 @@ struct MockConnectionPool {
42
42
typealias ID = HTTPConnectionPool . Connection . ID
43
43
44
44
private enum State {
45
+ // A note about idle vs. parked connections
46
+ //
47
+ // In our state machine we differentiate the concept of a connection being idle vs. it
48
+ // being parked. An idle connection is a connection that we are not executing any
49
+ // request on. A parked connection is an idle connection that will remain in this state
50
+ // for a longer period of time. For parked connections we create idle timeout timers.
51
+ //
52
+ // Consider those two flows to better understand the difference:
53
+ //
54
+ // 1. A connection becomes `idle` and there is more work queued. This will lead to a new
55
+ // request being executed on the connection. It will switch back to be in use without
56
+ // having been parked in the meantime.
57
+ //
58
+ // 2. A connection becomes `idle` and there is no more work queued. We don't want to get
59
+ // rid of the connection right away. For this reason we create an idle timeout timer
60
+ // for the connection. After having created the timer we consider the connection
61
+ // being parked. If a new request arrives, before the connection timed out, we need
62
+ // to cancel the idle timeout timer.
63
+
45
64
enum HTTP1State {
46
65
case inUse
47
66
case idle( parked: Bool , idleSince: NIODeadline )
@@ -102,7 +121,7 @@ struct MockConnectionPool {
102
121
}
103
122
}
104
123
105
- /// Is the connection idle and did we create a timeout timer for it?
124
+ /// Is the connection idle and did we create an idle timeout timer for it?
106
125
var isParked : Bool {
107
126
switch self . state {
108
127
case . starting, . closed, . http1( . inUse) , . http2( . inUse) :
@@ -192,9 +211,6 @@ struct MockConnectionPool {
192
211
if let required = request. requiredEventLoop, required !== self . eventLoop {
193
212
throw Errors . connectionDoesNotFulfillEventLoopRequirement
194
213
}
195
- if maxStreams < 1 {
196
- throw Errors . connectionDoesNotHaveHTTP2StreamAvailable
197
- }
198
214
self . state = . http2( . inUse( maxConcurrentStreams: maxStreams, used: 1 ) )
199
215
200
216
case . http2( . inUse( let maxStreams, let used) ) :
@@ -223,7 +239,7 @@ struct MockConnectionPool {
223
239
if used == 1 {
224
240
self . state = . http2( . idle( maxConcurrentStreams: maxStreams, parked: false , lastIdle: . now( ) ) )
225
241
} else {
226
- self . state = . http2( . inUse( maxConcurrentStreams: maxStreams, used: used) )
242
+ self . state = . http2( . inUse( maxConcurrentStreams: maxStreams, used: used - 1 ) )
227
243
}
228
244
229
245
case . closed:
0 commit comments