Skip to content

Commit

Permalink
HttpStreamPool: Fix NetworkContextTest.Preconnect* tests
Browse files Browse the repository at this point in the history
When the HappyEyeballsV3 feature is enabled, use HttpStreamPool's
GetInfoAsValue() to inspect the current state of the pool. This
fixes NetworkContextTest.Preconnect* tests.

The NetworkContextTest.PreconnectMax test requests 76 sockets,
which exceeds the maximum number of sockets per group. Change
the CHECK in HttpStreamPool::Preconnect() to std::min() to handle
such cases.

Bug: 346835898
Change-Id: I3993c9ea573b5ea102525a9fffd55d7e46d7b866
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5826436
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Reviewed-by: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1349943}
  • Loading branch information
bashi authored and pull[bot] committed Sep 5, 2024
1 parent d867e26 commit 1132258
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion net/http/http_stream_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "net/http/http_stream_pool.h"

#include <algorithm>
#include <map>
#include <memory>
#include <set>
Expand Down Expand Up @@ -196,7 +197,7 @@ int HttpStreamPool::Preconnect(const HttpStreamKey& stream_key,
AlternativeServiceInfo alternative_service_info,
quic::ParsedQuicVersion quic_version,
CompletionOnceCallback callback) {
CHECK_GE(kMaxStreamSocketsPerGroup, num_streams);
num_streams = std::min(kMaxStreamSocketsPerGroup, num_streams);
QuicSessionKey quic_session_key = stream_key.ToQuicSessionKey();
if (CanUseExistingQuicSession(stream_key, quic_session_key,
/*enable_ip_based_pooling=*/true,
Expand Down
20 changes: 20 additions & 0 deletions services/network/network_context_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,15 @@ class NetworkContextTest : public testing::Test {
// Looks up a value with the given name from the NetworkContext's
// TransportSocketPool info dictionary.
int GetSocketPoolInfo(NetworkContext* context, std::string_view name) {
if (base::FeatureList::IsEnabled(net::features::kHappyEyeballsV3)) {
return GetInfoFromHttpStreamPool(context, name);
} else {
return GetInfoFromClientSocketPool(context, name);
}
}

int GetInfoFromClientSocketPool(NetworkContext* context,
std::string_view name) {
return context->url_request_context()
->http_transaction_factory()
->GetSession()
Expand All @@ -583,6 +592,17 @@ class NetworkContextTest : public testing::Test {
.value_or(-1);
}

int GetInfoFromHttpStreamPool(NetworkContext* context,
std::string_view name) {
return context->url_request_context()
->http_transaction_factory()
->GetSession()
->http_stream_pool()
->GetInfoAsValue()
.FindInt(name)
.value_or(-1);
}

int GetSocketCountForGroup(NetworkContext* context,
const net::ClientSocketPool::GroupId& group) {
if (base::FeatureList::IsEnabled(net::features::kHappyEyeballsV3)) {
Expand Down

0 comments on commit 1132258

Please sign in to comment.