Chromium Code Reviews| Index: net/spdy/spdy_session_unittest.cc |
| diff --git a/net/spdy/spdy_session_unittest.cc b/net/spdy/spdy_session_unittest.cc |
| index 248e623bd125aec5756260ea1bce0c1d51fde009..1f90bfdee5ee57cc3ced80a28bfa0773171b9d32 100644 |
| --- a/net/spdy/spdy_session_unittest.cc |
| +++ b/net/spdy/spdy_session_unittest.cc |
| @@ -11,8 +11,11 @@ |
| #include "base/base64.h" |
| #include "base/bind.h" |
| #include "base/callback.h" |
| +#include "base/metrics/field_trial.h" |
| #include "base/run_loop.h" |
| #include "base/test/histogram_tester.h" |
| +#include "base/test/mock_entropy_provider.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 +6009,90 @@ TEST(CanPoolTest, CanPoolWithAcceptablePins) { |
| &tss, ssl_info, "www.example.org", "mail.example.org")); |
| } |
| +class SpdySessionCloseIdleConnectionTest |
| + : public SpdySessionTest, |
| + public ::testing::WithParamInterface<bool> { |
| + protected: |
| + void SetUp() override { |
| + field_trial_list_ = base::MakeUnique<base::FieldTrialList>( |
| + base::MakeUnique<base::MockEntropyProvider>()); |
| + std::string kTrialName = "name"; |
| + std::string kTrialGroup = "group"; |
| + base::FieldTrial* trial = |
| + base::FieldTrialList::CreateFieldTrial(kTrialName, kTrialGroup); |
| + 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.
|
| + feature_list->RegisterFieldTrialOverride( |
| + "CloseIdleH2SocketsEarly", |
| + 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.
|
| + : base::FeatureList::OVERRIDE_DISABLE_FEATURE, |
| + trial); |
| + scoped_feature_list_.InitWithFeatureList(std::move(feature_list)); |
| + } |
| + |
| + private: |
| + std::unique_ptr<base::FieldTrialList> field_trial_list_; |
| + 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; |
| + 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. |
|
Bence
2017/02/08 00:18:52
Nit: HTTP/2 is usually written in all uppercase.
xunjieli
2017/02/08 14:15:40
Done.
|
| + 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)); |
| + |
| + std::unique_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
|
Bence
2017/02/08 00:18:52
base::MakeUnique<>
xunjieli
2017/02/08 14:15:40
Done.
|
| + TestCompletionCallback callback; |
| + |
| + SSLConfig ssl_config; |
| + scoped_refptr<SSLSocketParams> ssl_params( |
| + 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.
|
| + 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, |
| + http_session_->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| + ->IdleSocketCount()); |
| + |
| + // The new SpdySession will reuse one socket from the pool. |
| + CreateSecureSpdySession(); |
| + |
| + EXPECT_EQ( |
| + 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.
|
| + http_session_->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| + ->IdleSocketCount()); |
| +} |
| + |
| } // namespace net |