OLD | NEW |
---|---|
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/quic/quic_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "net/base/test_data_directory.h" | 10 #include "net/base/test_data_directory.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 disable_disk_cache_(false), | 211 disable_disk_cache_(false), |
212 prefer_aes_(false), | 212 prefer_aes_(false), |
213 max_number_of_lossy_connections_(0), | 213 max_number_of_lossy_connections_(0), |
214 packet_loss_threshold_(1.0f), | 214 packet_loss_threshold_(1.0f), |
215 max_disabled_reasons_(3), | 215 max_disabled_reasons_(3), |
216 threshold_timeouts_with_open_streams_(2), | 216 threshold_timeouts_with_open_streams_(2), |
217 threshold_public_resets_post_handshake_(2), | 217 threshold_public_resets_post_handshake_(2), |
218 receive_buffer_size_(0), | 218 receive_buffer_size_(0), |
219 delay_tcp_race_(false), | 219 delay_tcp_race_(false), |
220 close_sessions_on_ip_change_(false), | 220 close_sessions_on_ip_change_(false), |
221 disable_quic_when_connection_times_out_with_open_streams_(false), | |
221 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), | 222 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), |
222 migrate_sessions_on_network_change_(false) { | 223 migrate_sessions_on_network_change_(false) { |
223 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 224 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
224 } | 225 } |
225 | 226 |
226 void Initialize() { | 227 void Initialize() { |
227 factory_.reset(new QuicStreamFactory( | 228 factory_.reset(new QuicStreamFactory( |
228 &host_resolver_, &socket_factory_, http_server_properties_.GetWeakPtr(), | 229 &host_resolver_, &socket_factory_, http_server_properties_.GetWeakPtr(), |
229 cert_verifier_.get(), nullptr, channel_id_service_.get(), | 230 cert_verifier_.get(), nullptr, channel_id_service_.get(), |
230 &transport_security_state_, cert_transparency_verifier_.get(), | 231 &transport_security_state_, cert_transparency_verifier_.get(), |
231 /*SocketPerformanceWatcherFactory*/ nullptr, | 232 /*SocketPerformanceWatcherFactory*/ nullptr, |
232 &crypto_client_stream_factory_, &random_generator_, clock_, | 233 &crypto_client_stream_factory_, &random_generator_, clock_, |
233 kDefaultMaxPacketSize, std::string(), | 234 kDefaultMaxPacketSize, std::string(), |
234 SupportedVersions(GetParam().version), enable_port_selection_, | 235 SupportedVersions(GetParam().version), enable_port_selection_, |
235 always_require_handshake_confirmation_, disable_connection_pooling_, | 236 always_require_handshake_confirmation_, disable_connection_pooling_, |
236 load_server_info_timeout_srtt_multiplier_, enable_connection_racing_, | 237 load_server_info_timeout_srtt_multiplier_, enable_connection_racing_, |
237 enable_non_blocking_io_, disable_disk_cache_, prefer_aes_, | 238 enable_non_blocking_io_, disable_disk_cache_, prefer_aes_, |
238 max_number_of_lossy_connections_, packet_loss_threshold_, | 239 max_number_of_lossy_connections_, packet_loss_threshold_, |
239 max_disabled_reasons_, threshold_timeouts_with_open_streams_, | 240 max_disabled_reasons_, threshold_timeouts_with_open_streams_, |
240 threshold_public_resets_post_handshake_, receive_buffer_size_, | 241 threshold_public_resets_post_handshake_, receive_buffer_size_, |
241 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, | 242 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, |
242 close_sessions_on_ip_change_, idle_connection_timeout_seconds_, | 243 close_sessions_on_ip_change_, |
243 migrate_sessions_on_network_change_, QuicTagVector())); | 244 disable_quic_when_connection_times_out_with_open_streams_, |
245 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, | |
246 QuicTagVector())); | |
244 factory_->set_require_confirmation(false); | 247 factory_->set_require_confirmation(false); |
245 EXPECT_FALSE(factory_->has_quic_server_info_factory()); | 248 EXPECT_FALSE(factory_->has_quic_server_info_factory()); |
246 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); | 249 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); |
247 EXPECT_TRUE(factory_->has_quic_server_info_factory()); | 250 EXPECT_TRUE(factory_->has_quic_server_info_factory()); |
248 } | 251 } |
249 | 252 |
250 void InitializeConnectionMigrationTest( | 253 void InitializeConnectionMigrationTest( |
251 NetworkChangeNotifier::NetworkList connected_networks) { | 254 NetworkChangeNotifier::NetworkList connected_networks) { |
252 scoped_mock_network_change_notifier_.reset( | 255 scoped_mock_network_change_notifier_.reset( |
253 new ScopedMockNetworkChangeNotifier()); | 256 new ScopedMockNetworkChangeNotifier()); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 bool disable_disk_cache_; | 409 bool disable_disk_cache_; |
407 bool prefer_aes_; | 410 bool prefer_aes_; |
408 int max_number_of_lossy_connections_; | 411 int max_number_of_lossy_connections_; |
409 double packet_loss_threshold_; | 412 double packet_loss_threshold_; |
410 int max_disabled_reasons_; | 413 int max_disabled_reasons_; |
411 int threshold_timeouts_with_open_streams_; | 414 int threshold_timeouts_with_open_streams_; |
412 int threshold_public_resets_post_handshake_; | 415 int threshold_public_resets_post_handshake_; |
413 int receive_buffer_size_; | 416 int receive_buffer_size_; |
414 bool delay_tcp_race_; | 417 bool delay_tcp_race_; |
415 bool close_sessions_on_ip_change_; | 418 bool close_sessions_on_ip_change_; |
419 bool disable_quic_when_connection_times_out_with_open_streams_; | |
416 int idle_connection_timeout_seconds_; | 420 int idle_connection_timeout_seconds_; |
417 bool migrate_sessions_on_network_change_; | 421 bool migrate_sessions_on_network_change_; |
418 }; | 422 }; |
419 | 423 |
420 INSTANTIATE_TEST_CASE_P(Version, | 424 INSTANTIATE_TEST_CASE_P(Version, |
421 QuicStreamFactoryTest, | 425 QuicStreamFactoryTest, |
422 ::testing::ValuesIn(GetTestParams())); | 426 ::testing::ValuesIn(GetTestParams())); |
423 | 427 |
424 TEST_P(QuicStreamFactoryTest, Create) { | 428 TEST_P(QuicStreamFactoryTest, Create) { |
425 Initialize(); | 429 Initialize(); |
(...skipping 2329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2755 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | 2759 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
2756 EXPECT_TRUE(stream2.get()); | 2760 EXPECT_TRUE(stream2.get()); |
2757 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 2761 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
2758 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 2762 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
2759 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); | 2763 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
2760 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); | 2764 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
2761 EXPECT_TRUE(socket_data3.AllReadDataConsumed()); | 2765 EXPECT_TRUE(socket_data3.AllReadDataConsumed()); |
2762 EXPECT_TRUE(socket_data3.AllWriteDataConsumed()); | 2766 EXPECT_TRUE(socket_data3.AllWriteDataConsumed()); |
2763 } | 2767 } |
2764 | 2768 |
2769 TEST_P(QuicStreamFactoryTest, DisableQuicWhenTimeoutsWithOpenStreams) { | |
2770 disable_disk_cache_ = true; | |
2771 disable_quic_when_connection_times_out_with_open_streams_ = true; | |
2772 Initialize(); | |
2773 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | |
2774 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | |
2775 QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); | |
2776 | |
2777 EXPECT_FALSE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get(), | |
2778 host_port_pair_.port())); | |
2779 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections( | |
2780 factory_.get(), host_port_pair_.port())); | |
2781 | |
2782 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | |
2783 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0); | |
2784 socket_factory_.AddSocketDataProvider(&socket_data); | |
2785 | |
2786 crypto_client_stream_factory_.set_handshake_mode( | |
2787 MockCryptoClientStream::CONFIRM_HANDSHAKE); | |
2788 host_resolver_.set_synchronous_mode(true); | |
2789 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), | |
2790 "192.168.0.1", ""); | |
2791 | |
2792 // Test first timeouts with open streams will disable QUIC. | |
2793 QuicStreamRequest request(factory_.get()); | |
2794 EXPECT_EQ(OK, request.Request(host_port_pair_, privacy_mode_, | |
2795 /*cert_verify_flags=*/0, host_port_pair_.host(), | |
2796 "GET", net_log_, callback_.callback())); | |
2797 | |
2798 QuicChromiumClientSession* session = | |
2799 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); | |
2800 | |
2801 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | |
2802 EXPECT_TRUE(stream.get()); | |
2803 HttpRequestInfo request_info; | |
2804 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, | |
2805 net_log_, CompletionCallback())); | |
2806 | |
2807 DVLOG(1) | |
2808 << "Created 1st session and initialized a stream. Now trigger timeout." | |
2809 << "Will disable QUIC."; | |
2810 session->connection()->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false); | |
Ryan Hamilton
2016/01/21 15:12:31
Does this take 30 seconds to run? If so, let's try
Zhongyi Shi
2016/01/21 19:55:21
It takes 150ms to run a single test. Not too painf
| |
2811 // Need to spin the loop now to ensure that | |
2812 // QuicStreamFactory::OnSessionClosed() runs. | |
2813 base::RunLoop run_loop; | |
2814 run_loop.RunUntilIdle(); | |
2815 | |
2816 EXPECT_EQ( | |
2817 1, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(factory_.get())); | |
2818 EXPECT_TRUE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get(), | |
2819 host_port_pair_.port())); | |
2820 | |
2821 EXPECT_EQ(QuicChromiumClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS, | |
2822 factory_->QuicDisabledReason(host_port_pair_.port())); | |
2823 | |
2824 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | |
2825 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | |
2826 } | |
2827 | |
2765 TEST_P(QuicStreamFactoryTest, PublicResetPostHandshakeTwoOfFour) { | 2828 TEST_P(QuicStreamFactoryTest, PublicResetPostHandshakeTwoOfFour) { |
2766 disable_disk_cache_ = true; | 2829 disable_disk_cache_ = true; |
2767 threshold_public_resets_post_handshake_ = 2; | 2830 threshold_public_resets_post_handshake_ = 2; |
2768 Initialize(); | 2831 Initialize(); |
2769 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | 2832 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
2770 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 2833 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
2771 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 2834 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
2772 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 2835 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
2773 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 2836 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
2774 QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); | 2837 QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3282 EXPECT_EQ(1u, observer.executed_count()); | 3345 EXPECT_EQ(1u, observer.executed_count()); |
3283 | 3346 |
3284 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 3347 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
3285 EXPECT_TRUE(stream.get()); | 3348 EXPECT_TRUE(stream.get()); |
3286 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 3349 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
3287 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 3350 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
3288 } | 3351 } |
3289 | 3352 |
3290 } // namespace test | 3353 } // namespace test |
3291 } // namespace net | 3354 } // namespace net |
OLD | NEW |