@@ -67,6 +67,22 @@ struct ConnPoolCallbacks : public Tcp::ConnectionPool::Callbacks {
67
67
Upstream::HostDescriptionConstSharedPtr host_;
68
68
};
69
69
70
+ class TestActiveTcpClient : public ActiveTcpClient {
71
+ public:
72
+ using ActiveTcpClient::ActiveTcpClient;
73
+
74
+ ~TestActiveTcpClient () override { parent ().onConnDestroyed (); }
75
+ void clearCallbacks () override {
76
+ if (state_ == Envoy::ConnectionPool::ActiveClient::State::BUSY ||
77
+ state_ == Envoy::ConnectionPool::ActiveClient::State::DRAINING) {
78
+ parent ().onConnReleased (*this );
79
+ }
80
+ ActiveTcpClient::clearCallbacks ();
81
+ }
82
+
83
+ Envoy::Tcp::ConnPoolImpl& parent () { return *static_cast <ConnPoolImpl*>(&parent_); }
84
+ };
85
+
70
86
/* *
71
87
* A wrapper around a ConnectionPoolImpl which tracks when the bridge between
72
88
* the pool and the consumer of the connection is released and destroyed.
@@ -143,7 +159,13 @@ class ConnPoolBase : public Tcp::ConnectionPool::Instance {
143
159
parent_.onConnReleasedForTest ();
144
160
}
145
161
162
+ Envoy::ConnectionPool::ActiveClientPtr instantiateActiveClient () override {
163
+ return std::make_unique<TestActiveTcpClient>(
164
+ *this , Envoy::ConnectionPool::ConnPoolImplBase::host (), 1 );
165
+ }
166
+
146
167
void onConnDestroyed () override { parent_.onConnDestroyedForTest (); }
168
+ Event::PostCb post_cb_;
147
169
ConnPoolBase& parent_;
148
170
};
149
171
@@ -202,12 +224,11 @@ void ConnPoolBase::expectEnableUpstreamReady(bool run) {
202
224
if (!test_new_connection_pool_) {
203
225
dynamic_cast <OriginalConnPoolImplForTest*>(conn_pool_.get ())->expectEnableUpstreamReady (run);
204
226
} else {
205
- if (!run) {
206
- EXPECT_CALL (*mock_upstream_ready_cb_, scheduleCallbackCurrentIteration ())
207
- .Times (1 )
208
- .RetiresOnSaturation ();
227
+ Event::PostCb& post_cb = dynamic_cast <ConnPoolImplForTest*>(conn_pool_.get ())->post_cb_ ;
228
+ if (run) {
229
+ post_cb ();
209
230
} else {
210
- mock_upstream_ready_cb_-> invokeCallback ( );
231
+ EXPECT_CALL (mock_dispatcher_, post (_)). WillOnce (testing::SaveArg< 0 >(&post_cb) );
211
232
}
212
233
}
213
234
}
@@ -219,7 +240,9 @@ class TcpConnPoolImplTest : public testing::TestWithParam<bool> {
219
240
public:
220
241
TcpConnPoolImplTest ()
221
242
: test_new_connection_pool_(GetParam()),
222
- upstream_ready_cb_ (new NiceMock<Event::MockSchedulableCallback>(&dispatcher_)),
243
+ upstream_ready_cb_ (test_new_connection_pool_
244
+ ? nullptr
245
+ : new NiceMock<Event::MockSchedulableCallback>(&dispatcher_)),
223
246
host_(Upstream::makeTestHost(cluster_, " tcp://127.0.0.1:9000" )),
224
247
conn_pool_(dispatcher_, host_, upstream_ready_cb_, test_new_connection_pool_) {}
225
248
@@ -244,7 +267,9 @@ class TcpConnPoolImplDestructorTest : public testing::TestWithParam<bool> {
244
267
public:
245
268
TcpConnPoolImplDestructorTest ()
246
269
: test_new_connection_pool_(GetParam()),
247
- upstream_ready_cb_ (new NiceMock<Event::MockSchedulableCallback>(&dispatcher_)) {
270
+ upstream_ready_cb_ (test_new_connection_pool_
271
+ ? nullptr
272
+ : new NiceMock<Event::MockSchedulableCallback>(&dispatcher_)) {
248
273
host_ = Upstream::makeTestHost (cluster_, " tcp://127.0.0.1:9000" );
249
274
if (test_new_connection_pool_) {
250
275
conn_pool_ = std::make_unique<ConnPoolImpl>(
0 commit comments