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

Side by Side Diff: net/spdy/spdy_session_unittest.cc

Issue 2678353003: Close idle H2 sockets when SpdySession is initialized. (Closed)
Patch Set: Address comments to hook directly to ClientSocketHandle Created 3 years, 9 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
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 5998 matching lines...) Expand 10 before | Expand all | Expand 10 after
6024 SSLInfo ssl_info; 6025 SSLInfo ssl_info;
6025 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), 6026 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(),
6026 "spdy_pooling.pem"); 6027 "spdy_pooling.pem");
6027 ssl_info.is_issued_by_known_root = true; 6028 ssl_info.is_issued_by_known_root = true;
6028 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); 6029 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin));
6029 6030
6030 EXPECT_TRUE(SpdySession::CanPool( 6031 EXPECT_TRUE(SpdySession::CanPool(
6031 &tss, ssl_info, "www.example.org", "mail.example.org")); 6032 &tss, ssl_info, "www.example.org", "mail.example.org"));
6032 } 6033 }
6033 6034
6035 class SpdySessionCloseIdleConnectionTest
6036 : public SpdySessionTest,
6037 public ::testing::WithParamInterface<bool> {
6038 protected:
6039 SpdySessionCloseIdleConnectionTest() : experiment_enabled_(GetParam()) {}
6040 void SetUp() override {
6041 if (experiment_enabled_) {
6042 scoped_feature_list_.InitFromCommandLine("CloseIdleH2SocketsEarly",
6043 std::string());
6044 }
6045 }
6046
6047 protected:
6048 const bool experiment_enabled_;
6049
6050 private:
6051 base::test::ScopedFeatureList scoped_feature_list_;
6052 HttpRequestInfo request_info_;
6053 };
6054
6055 INSTANTIATE_TEST_CASE_P(/* no prefix */,
6056 SpdySessionCloseIdleConnectionTest,
6057 ::testing::Bool());
6058
6059 TEST_P(SpdySessionCloseIdleConnectionTest, CloseIdleConnectionsInGroup) {
6060 session_deps_.host_resolver->set_synchronous_mode(true);
6061
6062 const int kNumIdleSockets = 4;
6063 MockRead reads[] = {MockRead(ASYNC, 0, 0)};
6064 std::vector<std::unique_ptr<SequencedSocketData>> providers;
6065 for (int i = 0; i < kNumIdleSockets; i++) {
6066 auto provider = base::MakeUnique<SequencedSocketData>(
6067 reads, arraysize(reads), nullptr, 0);
6068 session_deps_.socket_factory->AddSocketDataProvider(provider.get());
6069 providers.push_back(std::move(provider));
6070 AddSSLSocketData();
6071 }
6072
6073 CreateNetworkSession();
6074
6075 // Create some HTTP/2 sockets.
6076 std::vector<std::unique_ptr<ClientSocketHandle>> handles;
6077 for (size_t i = 0; i < kNumIdleSockets; i++) {
6078 scoped_refptr<TransportSocketParams> transport_params(
6079 new TransportSocketParams(
6080 key_.host_port_pair(), false, OnHostResolutionCallback(),
6081 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT));
6082
6083 auto connection = base::MakeUnique<ClientSocketHandle>();
6084 TestCompletionCallback callback;
6085
6086 SSLConfig ssl_config;
6087 scoped_refptr<SSLSocketParams> ssl_params(new SSLSocketParams(
6088 transport_params, nullptr, nullptr, key_.host_port_pair(), ssl_config,
6089 key_.privacy_mode(), 0, false));
6090 int rv = connection->Init(
6091 key_.host_port_pair().ToString(), ssl_params, MEDIUM,
6092 ClientSocketPool::RespectLimits::ENABLED, callback.callback(),
6093 http_session_->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL),
6094 NetLogWithSource());
6095 rv = callback.GetResult(rv);
6096 handles.push_back(std::move(connection));
6097 }
6098
6099 // Releases handles now, and these sockets should go into the socket pool.
6100 handles.clear();
6101 EXPECT_EQ(
6102 kNumIdleSockets,
6103 http_session_->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL)
6104 ->IdleSocketCount());
6105
6106 // The new SpdySession will reuse one socket from the pool.
6107 CreateSecureSpdySession();
6108
6109 // If the experiment is enabled, the SpdySession will close idle sockets.
6110 EXPECT_EQ(
6111 experiment_enabled_ ? 0 : kNumIdleSockets - 1,
6112 http_session_->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL)
6113 ->IdleSocketCount());
6114 }
6115
6034 } // namespace net 6116 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698