Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Unified Diff: net/spdy/spdy_session_unittest.cc

Issue 2678353003: Close idle H2 sockets when SpdySession is initialized. (Closed)
Patch Set: Self Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/spdy/spdy_session_unittest.cc
diff --git a/net/spdy/spdy_session_unittest.cc b/net/spdy/spdy_session_unittest.cc
index e98358fb59e9d79c6f4491d823ba3cd45c0cfe29..f4378d428e50e8d93c87838da087afc7cf36c572 100644
--- a/net/spdy/spdy_session_unittest.cc
+++ b/net/spdy/spdy_session_unittest.cc
@@ -13,6 +13,7 @@
#include "base/callback.h"
#include "base/run_loop.h"
#include "base/test/histogram_tester.h"
+#include "base/test/scoped_feature_list.h"
#include "net/base/host_port_pair.h"
#include "net/base/io_buffer.h"
#include "net/base/ip_endpoint.h"
@@ -6006,4 +6007,84 @@ TEST(CanPoolTest, CanPoolWithAcceptablePins) {
&tss, ssl_info, "www.example.org", "mail.example.org"));
}
+class SpdySessionCloseIdleConnectionTest
+ : public SpdySessionTest,
+ public ::testing::WithParamInterface<bool> {
+ protected:
+ SpdySessionCloseIdleConnectionTest() : experiment_enabled_(GetParam()) {}
+ void SetUp() override {
+ if (experiment_enabled_) {
+ scoped_feature_list_.InitFromCommandLine("CloseIdleH2SocketsEarly",
+ std::string());
+ }
+ }
+
+ protected:
+ const bool experiment_enabled_;
+
+ private:
+ base::test::ScopedFeatureList scoped_feature_list_;
+ HttpRequestInfo request_info_;
+};
+
+INSTANTIATE_TEST_CASE_P(/* no prefix */,
+ SpdySessionCloseIdleConnectionTest,
+ ::testing::Bool());
+
+TEST_P(SpdySessionCloseIdleConnectionTest, CloseIdleConnectionsInGroup) {
+ session_deps_.host_resolver->set_synchronous_mode(true);
+
+ size_t kNumIdleSockets = 4;
davidben 2017/03/02 22:05:52 Nit: const
xunjieli 2017/03/02 23:04:01 Done.
+ MockRead reads[] = {MockRead(ASYNC, 0, 0)};
+ std::vector<std::unique_ptr<SequencedSocketData>> providers;
+ for (size_t i = 0; i < kNumIdleSockets; i++) {
+ auto provider = base::MakeUnique<SequencedSocketData>(
+ reads, arraysize(reads), nullptr, 0);
+ session_deps_.socket_factory->AddSocketDataProvider(provider.get());
+ providers.push_back(std::move(provider));
+ AddSSLSocketData();
+ }
+
+ CreateNetworkSession();
+
+ // Create some HTTP/2 sockets.
+ std::vector<std::unique_ptr<ClientSocketHandle>> handles;
+ for (size_t i = 0; i < kNumIdleSockets; i++) {
+ scoped_refptr<TransportSocketParams> transport_params(
+ new TransportSocketParams(
+ key_.host_port_pair(), false, OnHostResolutionCallback(),
+ TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT));
+
+ auto connection = base::MakeUnique<ClientSocketHandle>();
+ TestCompletionCallback callback;
+
+ SSLConfig ssl_config;
+ scoped_refptr<SSLSocketParams> ssl_params(new SSLSocketParams(
+ transport_params, nullptr, nullptr, key_.host_port_pair(), ssl_config,
+ key_.privacy_mode(), 0, false));
+ int rv = connection->Init(
+ key_.host_port_pair().ToString(), ssl_params, MEDIUM,
+ ClientSocketPool::RespectLimits::ENABLED, callback.callback(),
+ http_session_->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL),
+ NetLogWithSource());
+ rv = callback.GetResult(rv);
+ handles.push_back(std::move(connection));
+ }
+
+ // Releases handles now, and these sockets should go into the socket pool.
+ handles.clear();
+ EXPECT_EQ(
+ (int)kNumIdleSockets,
davidben 2017/03/02 22:05:52 Nit: If you make kNumIdleSockets an int, you can p
xunjieli 2017/03/02 23:04:01 Done.
+ http_session_->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL)
+ ->IdleSocketCount());
+
+ // The new SpdySession will reuse one socket from the pool.
+ CreateSecureSpdySession();
+
davidben 2017/03/02 22:05:52 Nit: maybe add // If the experiment is enabled, t
xunjieli 2017/03/02 23:04:00 Done.
+ EXPECT_EQ(
+ experiment_enabled_ ? 0 : (int)kNumIdleSockets - 1,
+ http_session_->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL)
+ ->IdleSocketCount());
+}
+
} // namespace net
« net/socket/client_socket_pool_manager_impl.cc ('K') | « net/spdy/spdy_session_pool.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698