Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upstream: Add HttpPoolData methods required by Nighthawk. #16865

Merged
merged 1 commit into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions envoy/upstream/thread_local_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,23 @@ class HttpPoolData {
HttpPoolData(OnNewStreamFn on_new_stream, Http::ConnectionPool::Instance* pool)
: on_new_stream_(on_new_stream), pool_(pool) {}

/**
* See documentation of Http::ConnectionPool::Instance.
*/
Envoy::Http::ConnectionPool::Cancellable*
newStream(Http::ResponseDecoder& response_decoder,
Envoy::Http::ConnectionPool::Callbacks& callbacks) {
on_new_stream_();
return pool_->newStream(response_decoder, callbacks);
}
bool hasActiveConnections() const { return pool_->hasActiveConnections(); };

/**
* See documentation of Envoy::ConnectionPool::Instance.
*/
void addDrainedCallback(ConnectionPool::Instance::DrainedCb cb) {
pool_->addDrainedCallback(cb);
};

Upstream::HostDescriptionConstSharedPtr host() const { return pool_->host(); }

Expand Down
21 changes: 21 additions & 0 deletions test/common/upstream/cluster_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3422,6 +3422,27 @@ TEST_F(ClusterManagerImplTest, UpstreamSocketOptionsNullIsOkay) {
EXPECT_TRUE(opt_cp.has_value());
}

TEST_F(ClusterManagerImplTest, HttpPoolDataForwardsCallsToConnectionPool) {
createWithLocalClusterUpdate();
NiceMock<MockLoadBalancerContext> context;

Http::ConnectionPool::MockInstance* pool_mock = new Http::ConnectionPool::MockInstance();
Network::Socket::OptionsSharedPtr options_to_return = nullptr;

EXPECT_CALL(factory_, allocateConnPool_(_, _, _, _, _)).WillOnce(Return(pool_mock));

auto opt_cp = cluster_manager_->getThreadLocalCluster("cluster_1")
->httpConnPool(ResourcePriority::Default, Http::Protocol::Http11, &context);
ASSERT_TRUE(opt_cp.has_value());

EXPECT_CALL(*pool_mock, hasActiveConnections()).WillOnce(Return(true));
opt_cp.value().hasActiveConnections();

ConnectionPool::Instance::DrainedCb drained_cb = []() {};
EXPECT_CALL(*pool_mock, addDrainedCallback(_));
opt_cp.value().addDrainedCallback(drained_cb);
}

class TestUpstreamNetworkFilter : public Network::WriteFilter {
public:
Network::FilterStatus onWrite(Buffer::Instance&, bool) override {
Expand Down