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

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: Address comment 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();
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();
960 EXPECT_FALSE(job_controller_->alternative_job());
955 } 961 }
956 962
957 // Test that main job is blocked for kMaxDelayTimeForMainJob(3s) if 963 // Test that main job is blocked for kMaxDelayTimeForMainJob(3s) if
958 // http_server_properties cached an inappropriate large srtt for the server, 964 // 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 965 // which would potentially delay the main job for a extremely long time in
960 // delayed tcp case. 966 // delayed tcp case.
961 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCPWithLargeSrtt) { 967 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCPWithLargeSrtt) {
962 // Overrides the main thread's message loop with a mock tick clock so that we 968 // 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. 969 // could verify the main job is resumed with appropriate delay.
964 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; 970 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner;
965 // The max delay time should be in sync with .cc file. 971 // The max delay time should be in sync with .cc file.
966 base::TimeDelta kMaxDelayTimeForMainJob = base::TimeDelta::FromSeconds(3); 972 base::TimeDelta kMaxDelayTimeForMainJob = base::TimeDelta::FromSeconds(3);
967 HangingResolver* resolver = new HangingResolver(); 973 auto failing_resolver = base::MakeUnique<MockHostResolver>();
968 session_deps_.host_resolver.reset(resolver); 974 failing_resolver->set_ondemand_mode(true);
975 failing_resolver->rules()->AddSimulatedFailure("*google.com");
976 session_deps_.host_resolver = std::move(failing_resolver);
969 977
970 HttpRequestInfo request_info; 978 HttpRequestInfo request_info;
971 request_info.method = "GET"; 979 request_info.method = "GET";
972 request_info.url = GURL("https://www.google.com"); 980 request_info.url = GURL("https://www.google.com");
973 981
974 Initialize(request_info); 982 Initialize(request_info);
975 983
976 // Enable delayed TCP and set a extremely large time delay for waiting job. 984 // Enable delayed TCP and set a extremely large time delay for waiting job.
977 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); 985 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory();
978 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); 986 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 1006 // The alternative job stalls as host resolution hangs when creating the QUIC
999 // request and controller should resume the main job after delay. 1007 // request and controller should resume the main job after delay.
1000 EXPECT_TRUE(test_task_runner->HasPendingTask()); 1008 EXPECT_TRUE(test_task_runner->HasPendingTask());
1001 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); 1009 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount());
1002 1010
1003 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); 1011 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1);
1004 // Move forward the task runner with kMaxDelayTimeForMainJob and verify the 1012 // Move forward the task runner with kMaxDelayTimeForMainJob and verify the
1005 // main job is resumed. 1013 // main job is resumed.
1006 test_task_runner->FastForwardBy(kMaxDelayTimeForMainJob); 1014 test_task_runner->FastForwardBy(kMaxDelayTimeForMainJob);
1007 EXPECT_FALSE(test_task_runner->HasPendingTask()); 1015 EXPECT_FALSE(test_task_runner->HasPendingTask());
1016
1017 // Now unblock Resolver so that alternate job (and QuicStreamFactory::Job) can
1018 // be cleaned up.
1019 session_deps_.host_resolver->ResolveAllPending();
1020 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount());
1021 test_task_runner->FastForwardUntilNoTasksRemain();
1022 EXPECT_FALSE(job_controller_->alternative_job());
1008 } 1023 }
1009 1024
1010 TEST_F(HttpStreamFactoryImplJobControllerTest, 1025 TEST_F(HttpStreamFactoryImplJobControllerTest,
1011 ResumeMainJobImmediatelyOnStreamFailed) { 1026 ResumeMainJobImmediatelyOnStreamFailed) {
1012 // Overrides the main thread's message loop with a mock tick clock so that we 1027 // 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. 1028 // could verify the main job is resumed with appropriate delay.
1014 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; 1029 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner;
1015 1030
1016 HangingResolver* resolver = new HangingResolver(); 1031 auto failing_resolver = base::MakeUnique<MockHostResolver>();
1017 session_deps_.host_resolver.reset(resolver); 1032 failing_resolver->set_ondemand_mode(true);
1033 failing_resolver->rules()->AddSimulatedFailure("*google.com");
1034 session_deps_.host_resolver = std::move(failing_resolver);
1018 1035
1019 HttpRequestInfo request_info; 1036 HttpRequestInfo request_info;
1020 request_info.method = "GET"; 1037 request_info.method = "GET";
1021 request_info.url = GURL("https://www.google.com"); 1038 request_info.url = GURL("https://www.google.com");
1022 1039
1023 Initialize(request_info); 1040 Initialize(request_info);
1024 1041
1025 // Enable delayed TCP and set time delay for waiting job. 1042 // Enable delayed TCP and set time delay for waiting job.
1026 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); 1043 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory();
1027 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); 1044 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true);
(...skipping 17 matching lines...) Expand all
1045 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 1062 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
1046 EXPECT_TRUE(job_controller_->main_job()); 1063 EXPECT_TRUE(job_controller_->main_job());
1047 EXPECT_TRUE(job_controller_->alternative_job()); 1064 EXPECT_TRUE(job_controller_->alternative_job());
1048 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); 1065 EXPECT_TRUE(job_controller_->main_job()->is_waiting());
1049 1066
1050 EXPECT_TRUE(test_task_runner->HasPendingTask()); 1067 EXPECT_TRUE(test_task_runner->HasPendingTask());
1051 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); 1068 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount());
1052 1069
1053 // |alternative_job| fails but should not report status to Request. 1070 // |alternative_job| fails but should not report status to Request.
1054 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); 1071 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
1055 job_controller_->OnStreamFailed(job_factory_.alternative_job(), 1072 // Now unblock Resolver to fail the alternate job.
1056 ERR_NETWORK_CHANGED, SSLConfig()); 1073 session_deps_.host_resolver->ResolveAllPending();
1057 EXPECT_EQ(2u, test_task_runner->GetPendingTaskCount()); 1074 EXPECT_EQ(2u, test_task_runner->GetPendingTaskCount());
1058 1075
1059 // Verify the main job will be resumed immediately. 1076 // Verify the main job will be resumed immediately.
1060 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); 1077 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1);
1061 // Execute tasks that have no remaining delay. Tasks with nonzero delay will 1078 // Execute tasks that have no remaining delay. Tasks with nonzero delay will
1062 // remain queued. 1079 // remain queued.
1063 test_task_runner->RunUntilIdle(); 1080 test_task_runner->RunUntilIdle();
1064 1081
1065 // Verify there is another task to resume main job with delay but should 1082 // 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. 1083 // not call Resume() on the main job as main job has been resumed.
1067 EXPECT_TRUE(test_task_runner->HasPendingTask()); 1084 EXPECT_TRUE(test_task_runner->HasPendingTask());
1068 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); 1085 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount());
1069 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); 1086 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0);
1070 test_task_runner->FastForwardBy(base::TimeDelta::FromMicroseconds(15)); 1087 test_task_runner->FastForwardBy(base::TimeDelta::FromMicroseconds(15));
1071 EXPECT_FALSE(test_task_runner->HasPendingTask()); 1088 EXPECT_FALSE(test_task_runner->HasPendingTask());
1089 EXPECT_FALSE(job_controller_->alternative_job());
1072 } 1090 }
1073 1091
1074 // Verifies that the alternative proxy server job is not created if the URL 1092 // Verifies that the alternative proxy server job is not created if the URL
1075 // scheme is HTTPS. 1093 // scheme is HTTPS.
1076 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpsURL) { 1094 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpsURL) {
1077 // Using hanging resolver will cause the alternative job to hang indefinitely. 1095 // Using hanging resolver will cause the alternative job to hang indefinitely.
1078 HangingResolver* resolver = new HangingResolver(); 1096 HangingResolver* resolver = new HangingResolver();
1079 session_deps_.host_resolver.reset(resolver); 1097 session_deps_.host_resolver.reset(resolver);
1080 1098
1081 HttpRequestInfo request_info; 1099 HttpRequestInfo request_info;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); 1143 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations());
1126 } 1144 }
1127 1145
1128 // Verifies that the main job is resumed properly after a delay when the 1146 // Verifies that the main job is resumed properly after a delay when the
1129 // alternative proxy server job hangs. 1147 // alternative proxy server job hangs.
1130 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCPAlternativeProxy) { 1148 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCPAlternativeProxy) {
1131 // Overrides the main thread's message loop with a mock tick clock so that we 1149 // 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. 1150 // could verify the main job is resumed with appropriate delay.
1133 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; 1151 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner;
1134 1152
1135 // Using hanging resolver will cause the alternative job to hang indefinitely. 1153 auto failing_resolver = base::MakeUnique<MockHostResolver>();
1136 HangingResolver* resolver = new HangingResolver(); 1154 failing_resolver->set_ondemand_mode(true);
1137 session_deps_.host_resolver.reset(resolver); 1155 failing_resolver->rules()->AddSimulatedFailure("*myproxy.org");
1156 session_deps_.host_resolver = std::move(failing_resolver);
1138 1157
1139 UseAlternativeProxy(); 1158 UseAlternativeProxy();
1140 1159
1141 HttpRequestInfo request_info; 1160 HttpRequestInfo request_info;
1142 request_info.method = "GET"; 1161 request_info.method = "GET";
1143 request_info.url = GURL("http://mail.example.org/"); 1162 request_info.url = GURL("http://mail.example.org/");
1144 Initialize(request_info); 1163 Initialize(request_info);
1145 1164
1146 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); 1165 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic());
1147 1166
(...skipping 28 matching lines...) Expand all
1176 1195
1177 // Move forward the delay and verify the main job is resumed. 1196 // Move forward the delay and verify the main job is resumed.
1178 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); 1197 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1);
1179 test_task_runner->FastForwardBy(base::TimeDelta::FromMicroseconds(15)); 1198 test_task_runner->FastForwardBy(base::TimeDelta::FromMicroseconds(15));
1180 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_)); 1199 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_));
1181 1200
1182 test_task_runner->RunUntilIdle(); 1201 test_task_runner->RunUntilIdle();
1183 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); 1202 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid());
1184 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); 1203 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations());
1185 EXPECT_FALSE(test_task_runner->HasPendingTask()); 1204 EXPECT_FALSE(test_task_runner->HasPendingTask());
1205
1206 // Now unblock Resolver so that alternate job (and QuicStreamFactory::Job) can
1207 // be cleaned up.
1208 session_deps_.host_resolver->ResolveAllPending();
1209 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount());
1210 test_task_runner->FastForwardUntilNoTasksRemain();
1211 EXPECT_FALSE(job_controller_->alternative_job());
1186 } 1212 }
1187 1213
1188 // Verifies that the alternative proxy server job fails immediately, and the 1214 // Verifies that the alternative proxy server job fails immediately, and the
1189 // main job is not blocked. 1215 // main job is not blocked.
1190 TEST_F(HttpStreamFactoryImplJobControllerTest, FailAlternativeProxy) { 1216 TEST_F(HttpStreamFactoryImplJobControllerTest, FailAlternativeProxy) {
1191 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; 1217 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner;
1192 // Using failing resolver will cause the alternative job to fail. 1218 // Using failing resolver will cause the alternative job to fail.
1193 FailingHostResolver* resolver = new FailingHostResolver(); 1219 FailingHostResolver* resolver = new FailingHostResolver();
1194 session_deps_.host_resolver.reset(resolver); 1220 session_deps_.host_resolver.reset(resolver);
1195 1221
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 Preconnect(kNumPreconects); 1408 Preconnect(kNumPreconects);
1383 // If experiment is enabled, only 1 stream is requested. 1409 // If experiment is enabled, only 1 stream is requested.
1384 EXPECT_EQ( 1410 EXPECT_EQ(
1385 (int)actual_num_connects, 1411 (int)actual_num_connects,
1386 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); 1412 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job()));
1387 base::RunLoop().RunUntilIdle(); 1413 base::RunLoop().RunUntilIdle();
1388 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 1414 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
1389 } 1415 }
1390 1416
1391 } // namespace net 1417 } // 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