@@ -52,13 +52,13 @@ func TestCMAPProse(t *testing.T) {
52
52
assert .Equal (t , numClosed , len (closed ), "expected %d closed events, got %d" , numClosed , len (closed ))
53
53
54
54
netCount := numCreated - numClosed
55
- assert .Equal (t , netCount , len ( p . opened ), "expected %d connections in opened map, got %d" , netCount ,
56
- len ( p . opened ))
55
+ assert .Equal (t , netCount , p . totalConnectionCount ( ), "expected %d connections in opened map, got %d" , netCount ,
56
+ p . totalConnectionCount ( ))
57
57
}
58
58
59
- t .Run ("get " , func (t * testing.T ) {
59
+ t .Run ("checkOut " , func (t * testing.T ) {
60
60
t .Run ("errored connection exists in pool" , func (t * testing.T ) {
61
- // If a connection is created as part of minPoolSize maintenance and errors while connecting, get ()
61
+ // If a connection is created as part of minPoolSize maintenance and errors while connecting, checkOut ()
62
62
// should report that error and publish an event.
63
63
clearEvents ()
64
64
@@ -76,20 +76,19 @@ func TestCMAPProse(t *testing.T) {
76
76
}
77
77
pool := createTestPool (t , cfg , connOpts ... )
78
78
79
- _ , err := pool .get (context .Background ())
80
- assert .NotNil (t , err , "expected get () error, got nil" )
79
+ _ , err := pool .checkOut (context .Background ())
80
+ assert .NotNil (t , err , "expected checkOut () error, got nil" )
81
81
82
- // If the connection doesn't finish connecting before resourcePool gives it back, the error will be
83
- // detected by pool.get and result in a created/closed count of 1. If it does finish connecting, the
84
- // error will be detected by resourcePool, which will return nil. Then, pool will try to create a new
85
- // connection, which will also error. This process will result in a created/closed count of 2.
86
82
assert .True (t , len (created ) == 1 || len (created ) == 2 , "expected 1 or 2 opened events, got %d" , len (created ))
87
83
assert .True (t , len (closed ) == 1 || len (closed ) == 2 , "expected 1 or 2 closed events, got %d" , len (closed ))
84
+
85
+ _ = pool .disconnect (context .Background ())
88
86
netCount := len (created ) - len (closed )
89
87
assert .Equal (t , 0 , netCount , "expected net connection count to be 0, got %d" , netCount )
90
88
})
91
89
t .Run ("pool is empty" , func (t * testing.T ) {
92
- // If a new connection is created during get(), get() should report that error and publish an event.
90
+ // If a checkOut() has to create a new connection and that connection encounters an
91
+ // error while connecting, checkOut() should return that error and publish an event.
93
92
clearEvents ()
94
93
95
94
var dialer DialerFunc = func (context.Context , string , string ) (net.Conn , error ) {
@@ -103,13 +102,16 @@ func TestCMAPProse(t *testing.T) {
103
102
}),
104
103
}
105
104
pool := createTestPool (t , getConfig (), connOpts ... )
105
+ defer func () {
106
+ _ = pool .disconnect (context .Background ())
107
+ }()
106
108
107
- _ , err := pool .get (context .Background ())
108
- assert .NotNil (t , err , "expected get () error, got nil" )
109
+ _ , err := pool .checkOut (context .Background ())
110
+ assert .NotNil (t , err , "expected checkOut () error, got nil" )
109
111
assertConnectionCounts (t , pool , 1 , 1 )
110
112
})
111
113
})
112
- t .Run ("put " , func (t * testing.T ) {
114
+ t .Run ("checkIn " , func (t * testing.T ) {
113
115
t .Run ("errored connection" , func (t * testing.T ) {
114
116
// If the connection being returned to the pool encountered a network error, it should be removed from
115
117
// the pool and an event should be published.
@@ -124,16 +126,19 @@ func TestCMAPProse(t *testing.T) {
124
126
WithDialer (func (Dialer ) Dialer { return dialer }),
125
127
}
126
128
pool := createTestPool (t , getConfig (), connOpts ... )
129
+ defer func () {
130
+ _ = pool .disconnect (context .Background ())
131
+ }()
127
132
128
- conn , err := pool .get (context .Background ())
129
- assert .Nil (t , err , "get error: %v" , err )
133
+ conn , err := pool .checkOut (context .Background ())
134
+ assert .Nil (t , err , "checkOut() error: %v" , err )
130
135
131
136
// Force a network error by writing to the connection.
132
137
err = conn .writeWireMessage (context .Background (), nil )
133
138
assert .NotNil (t , err , "expected writeWireMessage error, got nil" )
134
139
135
- err = pool .put (conn )
136
- assert .Nil (t , err , "put error: %v" , err )
140
+ err = pool .checkIn (conn )
141
+ assert .Nil (t , err , "checkIn() error: %v" , err )
137
142
138
143
assertConnectionCounts (t , pool , 1 , 1 )
139
144
evt := <- closed
@@ -157,16 +162,19 @@ func TestCMAPProse(t *testing.T) {
157
162
WithIdleTimeout (func (time.Duration ) time.Duration { return 1 * time .Second }),
158
163
}
159
164
pool := createTestPool (t , getConfig (), connOpts ... )
165
+ defer func () {
166
+ _ = pool .disconnect (context .Background ())
167
+ }()
160
168
161
- conn , err := pool .get (context .Background ())
162
- assert .Nil (t , err , "get error: %v" , err )
169
+ conn , err := pool .checkOut (context .Background ())
170
+ assert .Nil (t , err , "checkOut() error: %v" , err )
163
171
164
172
// Set the idleDeadline to a time in the past to simulate expiration.
165
173
pastTime := time .Now ().Add (- 10 * time .Second )
166
174
conn .idleDeadline .Store (pastTime )
167
175
168
- err = pool .put (conn )
169
- assert .Nil (t , err , "put error: %v" , err )
176
+ err = pool .checkIn (conn )
177
+ assert .Nil (t , err , "checkIn() error: %v" , err )
170
178
171
179
assertConnectionCounts (t , pool , 1 , 1 )
172
180
evt := <- closed
@@ -189,10 +197,10 @@ func TestCMAPProse(t *testing.T) {
189
197
conns := checkoutConnections (t , pool , numConns )
190
198
assertConnectionCounts (t , pool , numConns , 0 )
191
199
192
- // Return all connections to the pool and assert that none were closed by put ().
200
+ // Return all connections to the pool and assert that none were closed by checkIn ().
193
201
for i , c := range conns {
194
- err := pool .put (c )
195
- assert .Nil (t , err , "put error at index %d: %v" , i , err )
202
+ err := pool .checkIn (c )
203
+ assert .Nil (t , err , "checkIn() error at index %d: %v" , i , err )
196
204
}
197
205
assertConnectionCounts (t , pool , numConns , 0 )
198
206
@@ -223,8 +231,8 @@ func TestCMAPProse(t *testing.T) {
223
231
224
232
// Only return 2 of the connection.
225
233
for i := 0 ; i < 2 ; i ++ {
226
- err := pool .put (conns [i ])
227
- assert .Nil (t , err , "put error at index %d: %v" , i , err )
234
+ err := pool .checkIn (conns [i ])
235
+ assert .Nil (t , err , "checkIn() error at index %d: %v" , i , err )
228
236
}
229
237
conns = conns [2 :]
230
238
assertConnectionCounts (t , pool , numConns , 0 )
@@ -237,8 +245,8 @@ func TestCMAPProse(t *testing.T) {
237
245
// Return the remaining connections and assert that the closed event count does not increase because
238
246
// these connections have already been closed.
239
247
for i , c := range conns {
240
- err := pool .put (c )
241
- assert .Nil (t , err , "put error at index %d: %v" , i , err )
248
+ err := pool .checkIn (c )
249
+ assert .Nil (t , err , "checkIn() error at index %d: %v" , i , err )
242
250
}
243
251
assertConnectionCounts (t , pool , numConns , numConns )
244
252
@@ -269,8 +277,8 @@ func checkoutConnections(t *testing.T, p *pool, numConns int) []*connection {
269
277
conns := make ([]* connection , 0 , numConns )
270
278
271
279
for i := 0 ; i < numConns ; i ++ {
272
- conn , err := p .get (context .Background ())
273
- assert .Nil (t , err , "get error at index %d: %v" , i , err )
280
+ conn , err := p .checkOut (context .Background ())
281
+ assert .Nil (t , err , "checkOut() error at index %d: %v" , i , err )
274
282
conns = append (conns , conn )
275
283
}
276
284
0 commit comments