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

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

Issue 2678353003: Close idle H2 sockets when SpdySession is initialized. (Closed)
Patch Set: 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
« net/spdy/spdy_session.cc ('K') | « net/spdy/spdy_session_pool.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/metrics/field_trial.h"
14 #include "base/run_loop.h" 15 #include "base/run_loop.h"
15 #include "base/test/histogram_tester.h" 16 #include "base/test/histogram_tester.h"
17 #include "base/test/mock_entropy_provider.h"
18 #include "base/test/scoped_feature_list.h"
16 #include "net/base/host_port_pair.h" 19 #include "net/base/host_port_pair.h"
17 #include "net/base/io_buffer.h" 20 #include "net/base/io_buffer.h"
18 #include "net/base/ip_endpoint.h" 21 #include "net/base/ip_endpoint.h"
19 #include "net/base/proxy_delegate.h" 22 #include "net/base/proxy_delegate.h"
20 #include "net/base/request_priority.h" 23 #include "net/base/request_priority.h"
21 #include "net/base/test_data_stream.h" 24 #include "net/base/test_data_stream.h"
22 #include "net/base/test_proxy_delegate.h" 25 #include "net/base/test_proxy_delegate.h"
23 #include "net/cert/ct_policy_status.h" 26 #include "net/cert/ct_policy_status.h"
24 #include "net/log/net_log_event_type.h" 27 #include "net/log/net_log_event_type.h"
25 #include "net/log/net_log_source.h" 28 #include "net/log/net_log_source.h"
(...skipping 5973 matching lines...) Expand 10 before | Expand all | Expand 10 after
5999 SSLInfo ssl_info; 6002 SSLInfo ssl_info;
6000 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), 6003 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(),
6001 "spdy_pooling.pem"); 6004 "spdy_pooling.pem");
6002 ssl_info.is_issued_by_known_root = true; 6005 ssl_info.is_issued_by_known_root = true;
6003 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); 6006 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin));
6004 6007
6005 EXPECT_TRUE(SpdySession::CanPool( 6008 EXPECT_TRUE(SpdySession::CanPool(
6006 &tss, ssl_info, "www.example.org", "mail.example.org")); 6009 &tss, ssl_info, "www.example.org", "mail.example.org"));
6007 } 6010 }
6008 6011
6012 class SpdySessionCloseIdleConnectionTest
6013 : public SpdySessionTest,
6014 public ::testing::WithParamInterface<bool> {
6015 protected:
6016 void SetUp() override {
6017 field_trial_list_ = base::MakeUnique<base::FieldTrialList>(
6018 base::MakeUnique<base::MockEntropyProvider>());
6019 std::string kTrialName = "name";
6020 std::string kTrialGroup = "group";
6021 base::FieldTrial* trial =
6022 base::FieldTrialList::CreateFieldTrial(kTrialName, kTrialGroup);
6023 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
Bence 2017/02/08 00:18:52 Use auto and base::MakeUnique as suggested by http
xunjieli 2017/02/08 14:15:40 Done.
6024 feature_list->RegisterFieldTrialOverride(
6025 "CloseIdleH2SocketsEarly",
6026 GetParam() ? base::FeatureList::OVERRIDE_ENABLE_FEATURE
Bence 2017/02/08 00:18:52 Add a protected const bool member to save GetParam
xunjieli 2017/02/08 14:15:40 Done.
6027 : base::FeatureList::OVERRIDE_DISABLE_FEATURE,
6028 trial);
6029 scoped_feature_list_.InitWithFeatureList(std::move(feature_list));
6030 }
6031
6032 private:
6033 std::unique_ptr<base::FieldTrialList> field_trial_list_;
6034 base::test::ScopedFeatureList scoped_feature_list_;
6035 HttpRequestInfo request_info_;
6036 };
6037
6038 INSTANTIATE_TEST_CASE_P(/* no prefix */,
6039 SpdySessionCloseIdleConnectionTest,
6040 ::testing::Bool());
6041
6042 TEST_P(SpdySessionCloseIdleConnectionTest, CloseIdleConnectionsInGroup) {
6043 session_deps_.host_resolver->set_synchronous_mode(true);
6044
6045 size_t kNumIdleSockets = 4;
6046 MockRead reads[] = {MockRead(ASYNC, 0, 0)};
6047 std::vector<std::unique_ptr<SequencedSocketData>> providers;
6048 for (size_t i = 0; i < kNumIdleSockets; i++) {
6049 auto provider = base::MakeUnique<SequencedSocketData>(
6050 reads, arraysize(reads), nullptr, 0);
6051 session_deps_.socket_factory->AddSocketDataProvider(provider.get());
6052 providers.push_back(std::move(provider));
6053 AddSSLSocketData();
6054 }
6055
6056 CreateNetworkSession();
6057
6058 // Create some Http/2 sockets.
Bence 2017/02/08 00:18:52 Nit: HTTP/2 is usually written in all uppercase.
xunjieli 2017/02/08 14:15:40 Done.
6059 std::vector<std::unique_ptr<ClientSocketHandle>> handles;
6060 for (size_t i = 0; i < kNumIdleSockets; i++) {
6061 scoped_refptr<TransportSocketParams> transport_params(
6062 new TransportSocketParams(
6063 key_.host_port_pair(), false, OnHostResolutionCallback(),
6064 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT));
6065
6066 std::unique_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
Bence 2017/02/08 00:18:52 base::MakeUnique<>
xunjieli 2017/02/08 14:15:40 Done.
6067 TestCompletionCallback callback;
6068
6069 SSLConfig ssl_config;
6070 scoped_refptr<SSLSocketParams> ssl_params(
6071 new SSLSocketParams(transport_params, NULL, NULL, key_.host_port_pair(),
Bence 2017/02/08 00:18:52 s/NULL/nullptr/g
xunjieli 2017/02/08 14:15:40 Done.
6072 ssl_config, key_.privacy_mode(), 0, false));
6073 int rv = connection->Init(
6074 key_.host_port_pair().ToString(), ssl_params, MEDIUM,
6075 ClientSocketPool::RespectLimits::ENABLED, callback.callback(),
6076 http_session_->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL),
6077 NetLogWithSource());
6078 rv = callback.GetResult(rv);
6079 handles.push_back(std::move(connection));
6080 }
6081
6082 // Releases handles now, and these sockets should go into the socket pool.
6083 handles.clear();
6084 EXPECT_EQ(
6085 (int)kNumIdleSockets,
6086 http_session_->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL)
6087 ->IdleSocketCount());
6088
6089 // The new SpdySession will reuse one socket from the pool.
6090 CreateSecureSpdySession();
6091
6092 EXPECT_EQ(
6093 GetParam() ? 0 : (int)kNumIdleSockets - 1,
Bence 2017/02/08 00:18:52 Use protected const bool member instead of GetPara
xunjieli 2017/02/08 14:15:40 Done.
6094 http_session_->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL)
6095 ->IdleSocketCount());
6096 }
6097
6009 } // namespace net 6098 } // namespace net
OLDNEW
« net/spdy/spdy_session.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