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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/spdy/spdy_session.h" 5 #include "net/spdy/spdy_session.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/test/histogram_tester.h" 15 #include "base/test/histogram_tester.h"
16 #include "base/test/scoped_feature_list.h"
16 #include "net/base/host_port_pair.h" 17 #include "net/base/host_port_pair.h"
17 #include "net/base/io_buffer.h" 18 #include "net/base/io_buffer.h"
18 #include "net/base/ip_endpoint.h" 19 #include "net/base/ip_endpoint.h"
19 #include "net/base/proxy_delegate.h" 20 #include "net/base/proxy_delegate.h"
20 #include "net/base/request_priority.h" 21 #include "net/base/request_priority.h"
21 #include "net/base/test_data_stream.h" 22 #include "net/base/test_data_stream.h"
22 #include "net/base/test_proxy_delegate.h" 23 #include "net/base/test_proxy_delegate.h"
23 #include "net/cert/ct_policy_status.h" 24 #include "net/cert/ct_policy_status.h"
24 #include "net/log/net_log_event_type.h" 25 #include "net/log/net_log_event_type.h"
25 #include "net/log/net_log_source.h" 26 #include "net/log/net_log_source.h"
(...skipping 5973 matching lines...) Expand 10 before | Expand all | Expand 10 after
5999 SSLInfo ssl_info; 6000 SSLInfo ssl_info;
6000 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), 6001 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(),
6001 "spdy_pooling.pem"); 6002 "spdy_pooling.pem");
6002 ssl_info.is_issued_by_known_root = true; 6003 ssl_info.is_issued_by_known_root = true;
6003 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); 6004 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin));
6004 6005
6005 EXPECT_TRUE(SpdySession::CanPool( 6006 EXPECT_TRUE(SpdySession::CanPool(
6006 &tss, ssl_info, "www.example.org", "mail.example.org")); 6007 &tss, ssl_info, "www.example.org", "mail.example.org"));
6007 } 6008 }
6008 6009
6010 class SpdySessionCloseIdleConnectionTest
6011 : public SpdySessionTest,
6012 public ::testing::WithParamInterface<bool> {
6013 protected:
6014 SpdySessionCloseIdleConnectionTest() : experiment_enabled_(GetParam()) {}
6015 void SetUp() override {
6016 if (experiment_enabled_) {
6017 scoped_feature_list_.InitFromCommandLine("CloseIdleH2SocketsEarly",
6018 std::string());
6019 }
6020 }
6021
6022 protected:
6023 const bool experiment_enabled_;
6024
6025 private:
6026 base::test::ScopedFeatureList scoped_feature_list_;
6027 HttpRequestInfo request_info_;
6028 };
6029
6030 INSTANTIATE_TEST_CASE_P(/* no prefix */,
6031 SpdySessionCloseIdleConnectionTest,
6032 ::testing::Bool());
6033
6034 TEST_P(SpdySessionCloseIdleConnectionTest, CloseIdleConnectionsInGroup) {
6035 session_deps_.host_resolver->set_synchronous_mode(true);
6036
6037 size_t kNumIdleSockets = 4;
davidben 2017/03/02 22:05:52 Nit: const
xunjieli 2017/03/02 23:04:01 Done.
6038 MockRead reads[] = {MockRead(ASYNC, 0, 0)};
6039 std::vector<std::unique_ptr<SequencedSocketData>> providers;
6040 for (size_t i = 0; i < kNumIdleSockets; i++) {
6041 auto provider = base::MakeUnique<SequencedSocketData>(
6042 reads, arraysize(reads), nullptr, 0);
6043 session_deps_.socket_factory->AddSocketDataProvider(provider.get());
6044 providers.push_back(std::move(provider));
6045 AddSSLSocketData();
6046 }
6047
6048 CreateNetworkSession();
6049
6050 // Create some HTTP/2 sockets.
6051 std::vector<std::unique_ptr<ClientSocketHandle>> handles;
6052 for (size_t i = 0; i < kNumIdleSockets; i++) {
6053 scoped_refptr<TransportSocketParams> transport_params(
6054 new TransportSocketParams(
6055 key_.host_port_pair(), false, OnHostResolutionCallback(),
6056 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT));
6057
6058 auto connection = base::MakeUnique<ClientSocketHandle>();
6059 TestCompletionCallback callback;
6060
6061 SSLConfig ssl_config;
6062 scoped_refptr<SSLSocketParams> ssl_params(new SSLSocketParams(
6063 transport_params, nullptr, nullptr, key_.host_port_pair(), ssl_config,
6064 key_.privacy_mode(), 0, false));
6065 int rv = connection->Init(
6066 key_.host_port_pair().ToString(), ssl_params, MEDIUM,
6067 ClientSocketPool::RespectLimits::ENABLED, callback.callback(),
6068 http_session_->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL),
6069 NetLogWithSource());
6070 rv = callback.GetResult(rv);
6071 handles.push_back(std::move(connection));
6072 }
6073
6074 // Releases handles now, and these sockets should go into the socket pool.
6075 handles.clear();
6076 EXPECT_EQ(
6077 (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.
6078 http_session_->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL)
6079 ->IdleSocketCount());
6080
6081 // The new SpdySession will reuse one socket from the pool.
6082 CreateSecureSpdySession();
6083
davidben 2017/03/02 22:05:52 Nit: maybe add // If the experiment is enabled, t
xunjieli 2017/03/02 23:04:00 Done.
6084 EXPECT_EQ(
6085 experiment_enabled_ ? 0 : (int)kNumIdleSockets - 1,
6086 http_session_->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL)
6087 ->IdleSocketCount());
6088 }
6089
6009 } // namespace net 6090 } // namespace net
OLDNEW
« 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