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

Side by Side Diff: net/http/http_stream_factory_impl_job_controller_unittest.cc

Issue 2690393005: Cap the delay time for the main job when racing with QUIC for delayed (Closed)
Patch Set: add comments 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) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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/http/http_stream_factory_impl_job_controller.h" 5 #include "net/http/http_stream_factory_impl_job_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 939
940 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_)); 940 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_));
941 // OnStreamFailed will not resume the main job again since it's been resumed 941 // OnStreamFailed will not resume the main job again since it's been resumed
942 // already. 942 // already.
943 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); 943 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0);
944 944
945 job_controller_->OnStreamFailed(job_factory_.alternative_job(), 945 job_controller_->OnStreamFailed(job_factory_.alternative_job(),
946 ERR_NETWORK_CHANGED, SSLConfig()); 946 ERR_NETWORK_CHANGED, SSLConfig());
947 } 947 }
948 948
949 // Test that main job is blocked for kMaxDelayTimeForMainJob(3s) if
950 // http_server_properties cached an inappropriate large srtt for the server,
951 // which would potentially delay the main job for a extremely long time in
952 // delayed tcp case.
953 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCPWithLargeSrtt) {
954 // The max delay time should be in sync with .cc file.
955 base::TimeDelta kMaxDelayTimeForMainJob = base::TimeDelta::FromSeconds(3);
956 HangingResolver* resolver = new HangingResolver();
957 session_deps_.host_resolver.reset(resolver);
958
959 HttpRequestInfo request_info;
960 request_info.method = "GET";
961 request_info.url = GURL("https://www.google.com");
962
963 Initialize(request_info, false, false);
964
965 // Enable delayed TCP and set a extremely large time delay for waiting job.
966 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory();
967 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true);
968 quic_stream_factory->set_require_confirmation(false);
969 ServerNetworkStats stats1;
970 stats1.srtt = base::TimeDelta::FromSeconds(100);
971 session_->http_server_properties()->SetServerNetworkStats(
972 url::SchemeHostPort(GURL("https://www.google.com")), stats1);
973
974 // Set a SPDY alternative service for the server.
975 url::SchemeHostPort server(request_info.url);
976 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
977 SetAlternativeService(request_info, alternative_service);
978
979 request_.reset(
980 job_controller_->Start(request_info, &request_delegate_, nullptr,
981 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
982 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
983 EXPECT_TRUE(job_controller_->main_job());
984 EXPECT_TRUE(job_controller_->alternative_job());
985 EXPECT_TRUE(job_controller_->main_job()->is_waiting());
986
987 // The alternative job stalls as host resolution hangs when creating the QUIC
988 // request and controller should resume the main job after delay.
989 base::RunLoop run_loop;
990 EXPECT_CALL(*job_factory_.main_job(), Resume())
991 .Times(1)
992 .WillOnce(
993 testing::DoAll(testing::Invoke(testing::CreateFunctor(
994 &JobControllerPeer::VerifyWaitingTimeForMainJob,
995 job_controller_, kMaxDelayTimeForMainJob)),
Ryan Hamilton 2017/02/15 22:26:55 I don't' think I understand how this tests that th
996 testing::Invoke([&run_loop]() { run_loop.Quit(); })));
997
998 // Wait for the main job to be resumed.
999 run_loop.Run();
1000 }
Ryan Hamilton 2017/02/15 22:26:55 To confirm, this test fails with the old code?
Zhongyi Shi 2017/02/15 23:32:33 Yup.
1001
949 TEST_F(HttpStreamFactoryImplJobControllerTest, 1002 TEST_F(HttpStreamFactoryImplJobControllerTest,
950 ResumeMainJobImmediatelyOnStreamFailed) { 1003 ResumeMainJobImmediatelyOnStreamFailed) {
951 HangingResolver* resolver = new HangingResolver(); 1004 HangingResolver* resolver = new HangingResolver();
952 session_deps_.host_resolver.reset(resolver); 1005 session_deps_.host_resolver.reset(resolver);
953 1006
954 HttpRequestInfo request_info; 1007 HttpRequestInfo request_info;
955 request_info.method = "GET"; 1008 request_info.method = "GET";
956 request_info.url = GURL("https://www.google.com"); 1009 request_info.url = GURL("https://www.google.com");
957 1010
958 Initialize(request_info, false, false); 1011 Initialize(request_info, false, false);
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 Preconnect(kNumPreconects); 1350 Preconnect(kNumPreconects);
1298 // If experiment is enabled, only 1 stream is requested. 1351 // If experiment is enabled, only 1 stream is requested.
1299 EXPECT_EQ( 1352 EXPECT_EQ(
1300 (int)actual_num_connects, 1353 (int)actual_num_connects,
1301 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); 1354 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job()));
1302 base::RunLoop().RunUntilIdle(); 1355 base::RunLoop().RunUntilIdle();
1303 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 1356 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
1304 } 1357 }
1305 1358
1306 } // namespace net 1359 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698