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

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

Issue 2794963002: Check callback is run in QuicStreamFactory::Job (Closed)
Patch Set: fix tests Created 3 years, 8 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 | « no previous file | net/quic/chromium/quic_stream_factory.cc » ('j') | 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) 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 int Resolve(const RequestInfo& info, 65 int Resolve(const RequestInfo& info,
66 RequestPriority priority, 66 RequestPriority priority,
67 AddressList* addresses, 67 AddressList* addresses,
68 const CompletionCallback& callback, 68 const CompletionCallback& callback,
69 std::unique_ptr<Request>* out_req, 69 std::unique_ptr<Request>* out_req,
70 const NetLogWithSource& net_log) override { 70 const NetLogWithSource& net_log) override {
71 return ERR_NAME_NOT_RESOLVED; 71 return ERR_NAME_NOT_RESOLVED;
72 } 72 }
73 }; 73 };
74 74
75 // TODO(xunjieli): This should just use HangingHostResolver from
76 // mock_host_resolver.h
75 class HangingResolver : public MockHostResolverBase { 77 class HangingResolver : public MockHostResolverBase {
76 public: 78 public:
77 HangingResolver() : MockHostResolverBase(false /*use_caching*/) {} 79 HangingResolver() : MockHostResolverBase(false /*use_caching*/) {}
78 ~HangingResolver() override {} 80 ~HangingResolver() override {}
79 81
80 int Resolve(const RequestInfo& info, 82 int Resolve(const RequestInfo& info,
81 RequestPriority priority, 83 RequestPriority priority,
82 AddressList* addresses, 84 AddressList* addresses,
83 const CompletionCallback& callback, 85 const CompletionCallback& callback,
84 std::unique_ptr<Request>* out_req, 86 std::unique_ptr<Request>* out_req,
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 // Wait until OnStreamFailedCallback is executed on the alternative job. 894 // Wait until OnStreamFailedCallback is executed on the alternative job.
893 // Request shouldn't be notified as the main job is still pending status. 895 // Request shouldn't be notified as the main job is still pending status.
894 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); 896 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
895 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); 897 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1);
896 898
897 base::RunLoop().RunUntilIdle(); 899 base::RunLoop().RunUntilIdle();
898 } 900 }
899 901
900 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { 902 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) {
901 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; 903 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner;
902 HangingResolver* resolver = new HangingResolver(); 904 auto failing_resolver = base::MakeUnique<MockHostResolver>();
903 session_deps_.host_resolver.reset(resolver); 905 failing_resolver->set_ondemand_mode(true);
906 failing_resolver->rules()->AddSimulatedFailure("*google.com");
907 session_deps_.host_resolver = std::move(failing_resolver);
904 908
905 HttpRequestInfo request_info; 909 HttpRequestInfo request_info;
906 request_info.method = "GET"; 910 request_info.method = "GET";
907 request_info.url = GURL("https://www.google.com"); 911 request_info.url = GURL("https://www.google.com");
908 912
909 Initialize(request_info); 913 Initialize(request_info);
910 914
911 // Enable delayed TCP and set time delay for waiting job. 915 // Enable delayed TCP and set time delay for waiting job.
912 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); 916 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory();
913 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); 917 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true);
(...skipping 27 matching lines...) Expand all
941 EXPECT_TRUE(job_controller_->main_job()); 945 EXPECT_TRUE(job_controller_->main_job());
942 EXPECT_TRUE(job_controller_->alternative_job()); 946 EXPECT_TRUE(job_controller_->alternative_job());
943 947
944 // |alternative_job| fails but should not report status to Request. 948 // |alternative_job| fails but should not report status to Request.
945 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); 949 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
946 950
947 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_)); 951 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_));
948 // OnStreamFailed will post a task to resume the main job immediately but 952 // OnStreamFailed will post a task to resume the main job immediately but
949 // won't call Resume() on the main job since it's been resumed already. 953 // won't call Resume() on the main job since it's been resumed already.
950 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); 954 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0);
951 job_controller_->OnStreamFailed(job_factory_.alternative_job(), 955 // Now unblock Resolver so that alternate job (and QuicStreamFactory::Job) can
952 ERR_NETWORK_CHANGED, SSLConfig()); 956 // be cleaned up.
957 session_deps_.host_resolver->ResolveAllPending();
Zhongyi Shi 2017/04/03 22:55:39 nit: could you add EXPECT_FALSE(job_controller_->a
xunjieli 2017/04/04 15:27:29 Done.
953 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); 958 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount());
954 test_task_runner->FastForwardUntilNoTasksRemain(); 959 test_task_runner->FastForwardUntilNoTasksRemain();
955 } 960 }
956 961
957 // Test that main job is blocked for kMaxDelayTimeForMainJob(3s) if 962 // Test that main job is blocked for kMaxDelayTimeForMainJob(3s) if
958 // http_server_properties cached an inappropriate large srtt for the server, 963 // http_server_properties cached an inappropriate large srtt for the server,
959 // which would potentially delay the main job for a extremely long time in 964 // which would potentially delay the main job for a extremely long time in
960 // delayed tcp case. 965 // delayed tcp case.
961 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCPWithLargeSrtt) { 966 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCPWithLargeSrtt) {
962 // Overrides the main thread's message loop with a mock tick clock so that we 967 // Overrides the main thread's message loop with a mock tick clock so that we
963 // could verify the main job is resumed with appropriate delay. 968 // could verify the main job is resumed with appropriate delay.
964 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; 969 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner;
965 // The max delay time should be in sync with .cc file. 970 // The max delay time should be in sync with .cc file.
966 base::TimeDelta kMaxDelayTimeForMainJob = base::TimeDelta::FromSeconds(3); 971 base::TimeDelta kMaxDelayTimeForMainJob = base::TimeDelta::FromSeconds(3);
967 HangingResolver* resolver = new HangingResolver(); 972 auto failing_resolver = base::MakeUnique<MockHostResolver>();
968 session_deps_.host_resolver.reset(resolver); 973 failing_resolver->set_ondemand_mode(true);
974 failing_resolver->rules()->AddSimulatedFailure("*google.com");
975 session_deps_.host_resolver = std::move(failing_resolver);
969 976
970 HttpRequestInfo request_info; 977 HttpRequestInfo request_info;
971 request_info.method = "GET"; 978 request_info.method = "GET";
972 request_info.url = GURL("https://www.google.com"); 979 request_info.url = GURL("https://www.google.com");
973 980
974 Initialize(request_info); 981 Initialize(request_info);
975 982
976 // Enable delayed TCP and set a extremely large time delay for waiting job. 983 // Enable delayed TCP and set a extremely large time delay for waiting job.
977 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); 984 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory();
978 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); 985 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true);
(...skipping 19 matching lines...) Expand all
998 // The alternative job stalls as host resolution hangs when creating the QUIC 1005 // The alternative job stalls as host resolution hangs when creating the QUIC
999 // request and controller should resume the main job after delay. 1006 // request and controller should resume the main job after delay.
1000 EXPECT_TRUE(test_task_runner->HasPendingTask()); 1007 EXPECT_TRUE(test_task_runner->HasPendingTask());
1001 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); 1008 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount());
1002 1009
1003 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); 1010 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1);
1004 // Move forward the task runner with kMaxDelayTimeForMainJob and verify the 1011 // Move forward the task runner with kMaxDelayTimeForMainJob and verify the
1005 // main job is resumed. 1012 // main job is resumed.
1006 test_task_runner->FastForwardBy(kMaxDelayTimeForMainJob); 1013 test_task_runner->FastForwardBy(kMaxDelayTimeForMainJob);
1007 EXPECT_FALSE(test_task_runner->HasPendingTask()); 1014 EXPECT_FALSE(test_task_runner->HasPendingTask());
1015
1016 // Now unblock Resolver so that alternate job (and QuicStreamFactory::Job) can
1017 // be cleaned up.
1018 session_deps_.host_resolver->ResolveAllPending();
1019 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount());
Zhongyi Shi 2017/04/03 22:55:39 ditto
xunjieli 2017/04/04 15:27:28 Done.
1020 test_task_runner->FastForwardUntilNoTasksRemain();
1008 } 1021 }
1009 1022
1010 TEST_F(HttpStreamFactoryImplJobControllerTest, 1023 TEST_F(HttpStreamFactoryImplJobControllerTest,
1011 ResumeMainJobImmediatelyOnStreamFailed) { 1024 ResumeMainJobImmediatelyOnStreamFailed) {
1012 // Overrides the main thread's message loop with a mock tick clock so that we 1025 // Overrides the main thread's message loop with a mock tick clock so that we
1013 // could verify the main job is resumed with appropriate delay. 1026 // could verify the main job is resumed with appropriate delay.
1014 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; 1027 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner;
1015 1028
1016 HangingResolver* resolver = new HangingResolver(); 1029 auto failing_resolver = base::MakeUnique<MockHostResolver>();
1017 session_deps_.host_resolver.reset(resolver); 1030 failing_resolver->set_ondemand_mode(true);
1031 failing_resolver->rules()->AddSimulatedFailure("*google.com");
1032 session_deps_.host_resolver = std::move(failing_resolver);
1018 1033
1019 HttpRequestInfo request_info; 1034 HttpRequestInfo request_info;
1020 request_info.method = "GET"; 1035 request_info.method = "GET";
1021 request_info.url = GURL("https://www.google.com"); 1036 request_info.url = GURL("https://www.google.com");
1022 1037
1023 Initialize(request_info); 1038 Initialize(request_info);
1024 1039
1025 // Enable delayed TCP and set time delay for waiting job. 1040 // Enable delayed TCP and set time delay for waiting job.
1026 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); 1041 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory();
1027 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); 1042 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true);
(...skipping 17 matching lines...) Expand all
1045 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 1060 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
1046 EXPECT_TRUE(job_controller_->main_job()); 1061 EXPECT_TRUE(job_controller_->main_job());
1047 EXPECT_TRUE(job_controller_->alternative_job()); 1062 EXPECT_TRUE(job_controller_->alternative_job());
1048 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); 1063 EXPECT_TRUE(job_controller_->main_job()->is_waiting());
1049 1064
1050 EXPECT_TRUE(test_task_runner->HasPendingTask()); 1065 EXPECT_TRUE(test_task_runner->HasPendingTask());
1051 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); 1066 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount());
1052 1067
1053 // |alternative_job| fails but should not report status to Request. 1068 // |alternative_job| fails but should not report status to Request.
1054 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); 1069 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
1055 job_controller_->OnStreamFailed(job_factory_.alternative_job(), 1070 // Now unblock Resolver to fail the alternate job.
1056 ERR_NETWORK_CHANGED, SSLConfig()); 1071 session_deps_.host_resolver->ResolveAllPending();
Zhongyi Shi 2017/04/03 22:55:39 ditto
xunjieli 2017/04/04 15:27:28 Done.
1057 EXPECT_EQ(2u, test_task_runner->GetPendingTaskCount()); 1072 EXPECT_EQ(2u, test_task_runner->GetPendingTaskCount());
1058 1073
1059 // Verify the main job will be resumed immediately. 1074 // Verify the main job will be resumed immediately.
1060 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); 1075 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1);
1061 // Execute tasks that have no remaining delay. Tasks with nonzero delay will 1076 // Execute tasks that have no remaining delay. Tasks with nonzero delay will
1062 // remain queued. 1077 // remain queued.
1063 test_task_runner->RunUntilIdle(); 1078 test_task_runner->RunUntilIdle();
1064 1079
1065 // Verify there is another task to resume main job with delay but should 1080 // Verify there is another task to resume main job with delay but should
1066 // not call Resume() on the main job as main job has been resumed. 1081 // not call Resume() on the main job as main job has been resumed.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); 1140 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations());
1126 } 1141 }
1127 1142
1128 // Verifies that the main job is resumed properly after a delay when the 1143 // Verifies that the main job is resumed properly after a delay when the
1129 // alternative proxy server job hangs. 1144 // alternative proxy server job hangs.
1130 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCPAlternativeProxy) { 1145 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCPAlternativeProxy) {
1131 // Overrides the main thread's message loop with a mock tick clock so that we 1146 // Overrides the main thread's message loop with a mock tick clock so that we
1132 // could verify the main job is resumed with appropriate delay. 1147 // could verify the main job is resumed with appropriate delay.
1133 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; 1148 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner;
1134 1149
1135 // Using hanging resolver will cause the alternative job to hang indefinitely. 1150 auto failing_resolver = base::MakeUnique<MockHostResolver>();
1136 HangingResolver* resolver = new HangingResolver(); 1151 failing_resolver->set_ondemand_mode(true);
1137 session_deps_.host_resolver.reset(resolver); 1152 failing_resolver->rules()->AddSimulatedFailure("*myproxy.org");
1153 session_deps_.host_resolver = std::move(failing_resolver);
1138 1154
1139 UseAlternativeProxy(); 1155 UseAlternativeProxy();
1140 1156
1141 HttpRequestInfo request_info; 1157 HttpRequestInfo request_info;
1142 request_info.method = "GET"; 1158 request_info.method = "GET";
1143 request_info.url = GURL("http://mail.example.org/"); 1159 request_info.url = GURL("http://mail.example.org/");
1144 Initialize(request_info); 1160 Initialize(request_info);
1145 1161
1146 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); 1162 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic());
1147 1163
(...skipping 28 matching lines...) Expand all
1176 1192
1177 // Move forward the delay and verify the main job is resumed. 1193 // Move forward the delay and verify the main job is resumed.
1178 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); 1194 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1);
1179 test_task_runner->FastForwardBy(base::TimeDelta::FromMicroseconds(15)); 1195 test_task_runner->FastForwardBy(base::TimeDelta::FromMicroseconds(15));
1180 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_)); 1196 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_));
1181 1197
1182 test_task_runner->RunUntilIdle(); 1198 test_task_runner->RunUntilIdle();
1183 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); 1199 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid());
1184 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); 1200 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations());
1185 EXPECT_FALSE(test_task_runner->HasPendingTask()); 1201 EXPECT_FALSE(test_task_runner->HasPendingTask());
1202
1203 // Now unblock Resolver so that alternate job (and QuicStreamFactory::Job) can
1204 // be cleaned up.
1205 session_deps_.host_resolver->ResolveAllPending();
1206 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount());
1207 test_task_runner->FastForwardUntilNoTasksRemain();
Zhongyi Shi 2017/04/03 22:55:39 ditto
xunjieli 2017/04/04 15:27:28 Done.
1186 } 1208 }
1187 1209
1188 // Verifies that the alternative proxy server job fails immediately, and the 1210 // Verifies that the alternative proxy server job fails immediately, and the
1189 // main job is not blocked. 1211 // main job is not blocked.
1190 TEST_F(HttpStreamFactoryImplJobControllerTest, FailAlternativeProxy) { 1212 TEST_F(HttpStreamFactoryImplJobControllerTest, FailAlternativeProxy) {
1191 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; 1213 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner;
1192 // Using failing resolver will cause the alternative job to fail. 1214 // Using failing resolver will cause the alternative job to fail.
1193 FailingHostResolver* resolver = new FailingHostResolver(); 1215 FailingHostResolver* resolver = new FailingHostResolver();
1194 session_deps_.host_resolver.reset(resolver); 1216 session_deps_.host_resolver.reset(resolver);
1195 1217
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 Preconnect(kNumPreconects); 1404 Preconnect(kNumPreconects);
1383 // If experiment is enabled, only 1 stream is requested. 1405 // If experiment is enabled, only 1 stream is requested.
1384 EXPECT_EQ( 1406 EXPECT_EQ(
1385 (int)actual_num_connects, 1407 (int)actual_num_connects,
1386 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); 1408 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job()));
1387 base::RunLoop().RunUntilIdle(); 1409 base::RunLoop().RunUntilIdle();
1388 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 1410 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
1389 } 1411 }
1390 1412
1391 } // namespace net 1413 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/quic/chromium/quic_stream_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698