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

Side by Side Diff: net/quic/quic_stream_factory_test.cc

Issue 1613513003: Early connection migration in QUIC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@home
Patch Set: Rebased against merged cl. Created 4 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) 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_on_timeout_with_open_streams_(false), 221 disable_quic_on_timeout_with_open_streams_(false),
222 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), 222 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds),
223 migrate_sessions_on_network_change_(false) { 223 migrate_sessions_on_network_change_(false),
224 migrate_sessions_early_(false) {
224 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); 225 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1));
225 } 226 }
226 227
227 void Initialize() { 228 void Initialize() {
228 factory_.reset(new QuicStreamFactory( 229 factory_.reset(new QuicStreamFactory(
229 &host_resolver_, &socket_factory_, http_server_properties_.GetWeakPtr(), 230 &host_resolver_, &socket_factory_, http_server_properties_.GetWeakPtr(),
230 cert_verifier_.get(), nullptr, channel_id_service_.get(), 231 cert_verifier_.get(), nullptr, channel_id_service_.get(),
231 &transport_security_state_, cert_transparency_verifier_.get(), 232 &transport_security_state_, cert_transparency_verifier_.get(),
232 /*SocketPerformanceWatcherFactory*/ nullptr, 233 /*SocketPerformanceWatcherFactory*/ nullptr,
233 &crypto_client_stream_factory_, &random_generator_, clock_, 234 &crypto_client_stream_factory_, &random_generator_, clock_,
234 kDefaultMaxPacketSize, std::string(), 235 kDefaultMaxPacketSize, std::string(),
235 SupportedVersions(GetParam().version), enable_port_selection_, 236 SupportedVersions(GetParam().version), enable_port_selection_,
236 always_require_handshake_confirmation_, disable_connection_pooling_, 237 always_require_handshake_confirmation_, disable_connection_pooling_,
237 load_server_info_timeout_srtt_multiplier_, enable_connection_racing_, 238 load_server_info_timeout_srtt_multiplier_, enable_connection_racing_,
238 enable_non_blocking_io_, disable_disk_cache_, prefer_aes_, 239 enable_non_blocking_io_, disable_disk_cache_, prefer_aes_,
239 max_number_of_lossy_connections_, packet_loss_threshold_, 240 max_number_of_lossy_connections_, packet_loss_threshold_,
240 max_disabled_reasons_, threshold_timeouts_with_open_streams_, 241 max_disabled_reasons_, threshold_timeouts_with_open_streams_,
241 threshold_public_resets_post_handshake_, receive_buffer_size_, 242 threshold_public_resets_post_handshake_, receive_buffer_size_,
242 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, 243 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0,
243 close_sessions_on_ip_change_, 244 close_sessions_on_ip_change_,
244 disable_quic_on_timeout_with_open_streams_, 245 disable_quic_on_timeout_with_open_streams_,
245 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, 246 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_,
246 QuicTagVector())); 247 migrate_sessions_early_, QuicTagVector()));
247 factory_->set_require_confirmation(false); 248 factory_->set_require_confirmation(false);
248 EXPECT_FALSE(factory_->has_quic_server_info_factory()); 249 EXPECT_FALSE(factory_->has_quic_server_info_factory());
249 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); 250 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory());
250 EXPECT_TRUE(factory_->has_quic_server_info_factory()); 251 EXPECT_TRUE(factory_->has_quic_server_info_factory());
251 } 252 }
252 253
253 void InitializeConnectionMigrationTest( 254 void InitializeConnectionMigrationTest(
254 NetworkChangeNotifier::NetworkList connected_networks) { 255 NetworkChangeNotifier::NetworkList connected_networks) {
255 scoped_mock_network_change_notifier_.reset( 256 scoped_mock_network_change_notifier_.reset(
256 new ScopedMockNetworkChangeNotifier()); 257 new ScopedMockNetworkChangeNotifier());
257 MockNetworkChangeNotifier* mock_ncn = 258 MockNetworkChangeNotifier* mock_ncn =
258 scoped_mock_network_change_notifier_->mock_network_change_notifier(); 259 scoped_mock_network_change_notifier_->mock_network_change_notifier();
259 mock_ncn->ForceNetworkHandlesSupported(); 260 mock_ncn->ForceNetworkHandlesSupported();
260 mock_ncn->SetConnectedNetworksList(connected_networks); 261 mock_ncn->SetConnectedNetworksList(connected_networks);
261 migrate_sessions_on_network_change_ = true; 262 migrate_sessions_on_network_change_ = true;
263 migrate_sessions_early_ = true;
262 Initialize(); 264 Initialize();
263 } 265 }
264 266
265 bool HasActiveSession(const HostPortPair& host_port_pair) { 267 bool HasActiveSession(const HostPortPair& host_port_pair) {
266 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), 268 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(),
267 host_port_pair); 269 host_port_pair);
268 } 270 }
269 271
270 scoped_ptr<QuicHttpStream> CreateFromSession( 272 scoped_ptr<QuicHttpStream> CreateFromSession(
271 const HostPortPair& host_port_pair) { 273 const HostPortPair& host_port_pair) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 double packet_loss_threshold_; 414 double packet_loss_threshold_;
413 int max_disabled_reasons_; 415 int max_disabled_reasons_;
414 int threshold_timeouts_with_open_streams_; 416 int threshold_timeouts_with_open_streams_;
415 int threshold_public_resets_post_handshake_; 417 int threshold_public_resets_post_handshake_;
416 int receive_buffer_size_; 418 int receive_buffer_size_;
417 bool delay_tcp_race_; 419 bool delay_tcp_race_;
418 bool close_sessions_on_ip_change_; 420 bool close_sessions_on_ip_change_;
419 bool disable_quic_on_timeout_with_open_streams_; 421 bool disable_quic_on_timeout_with_open_streams_;
420 int idle_connection_timeout_seconds_; 422 int idle_connection_timeout_seconds_;
421 bool migrate_sessions_on_network_change_; 423 bool migrate_sessions_on_network_change_;
424 bool migrate_sessions_early_;
422 }; 425 };
423 426
424 INSTANTIATE_TEST_CASE_P(Version, 427 INSTANTIATE_TEST_CASE_P(Version,
425 QuicStreamFactoryTest, 428 QuicStreamFactoryTest,
426 ::testing::ValuesIn(GetTestParams())); 429 ::testing::ValuesIn(GetTestParams()));
427 430
428 TEST_P(QuicStreamFactoryTest, Create) { 431 TEST_P(QuicStreamFactoryTest, Create) {
429 Initialize(); 432 Initialize();
430 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); 433 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
431 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 434 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
(...skipping 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1852 scoped_mock_network_change_notifier_->mock_network_change_notifier() 1855 scoped_mock_network_change_notifier_->mock_network_change_notifier()
1853 ->NotifyNetworkDisconnected(kDefaultNetworkForTests); 1856 ->NotifyNetworkDisconnected(kDefaultNetworkForTests);
1854 1857
1855 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); 1858 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1856 EXPECT_FALSE(HasActiveSession(host_port_pair_)); 1859 EXPECT_FALSE(HasActiveSession(host_port_pair_));
1857 1860
1858 EXPECT_TRUE(socket_data.AllReadDataConsumed()); 1861 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1859 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); 1862 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1860 } 1863 }
1861 1864
1865 TEST_P(QuicStreamFactoryTest, MigrateSessionEarly) {
1866 InitializeConnectionMigrationTest(
1867 {kDefaultNetworkForTests, kNewNetworkForTests});
1868 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
1869 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1870 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1871
1872 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
1873 scoped_ptr<QuicEncryptedPacket> request_packet(
1874 ConstructGetRequestPacket(1, kClientDataStreamId1, true, true));
1875 MockWrite writes[] = {MockWrite(SYNCHRONOUS, request_packet->data(),
1876 request_packet->length(), 1)};
1877 SequencedSocketData socket_data(reads, arraysize(reads), writes,
1878 arraysize(writes));
1879 socket_factory_.AddSocketDataProvider(&socket_data);
1880
1881 // Create request and QuicHttpStream.
1882 QuicStreamRequest request(factory_.get());
1883 EXPECT_EQ(ERR_IO_PENDING,
1884 request.Request(host_port_pair_, privacy_mode_,
1885 /*cert_verify_flags=*/0, host_port_pair_.host(),
1886 "GET", net_log_, callback_.callback()));
1887 EXPECT_EQ(OK, callback_.WaitForResult());
1888 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1889 EXPECT_TRUE(stream.get());
1890
1891 // Cause QUIC stream to be created.
1892 HttpRequestInfo request_info;
1893 request_info.method = "GET";
1894 request_info.url = GURL("https://www.example.org/");
1895 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
1896 net_log_, CompletionCallback()));
1897
1898 // Ensure that session is alive and active.
1899 QuicChromiumClientSession* session =
1900 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_);
1901 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1902 EXPECT_TRUE(HasActiveSession(host_port_pair_));
1903
1904 // Send GET request on stream.
1905 HttpResponseInfo response;
1906 HttpRequestHeaders request_headers;
1907 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response,
1908 callback_.callback()));
1909
1910 // Set up second socket data provider that is used after migration.
1911 // The response to the earlier request is read on this new socket.
1912 scoped_ptr<QuicEncryptedPacket> ping(
1913 maker_.MakePingPacket(2, /*include_version=*/true));
1914 MockWrite writes1[] = {
1915 MockWrite(SYNCHRONOUS, ping->data(), ping->length(), 0)};
1916 scoped_ptr<QuicEncryptedPacket> response_headers_packet(
1917 ConstructOkResponsePacket(1, kClientDataStreamId1, false, false));
1918 MockRead reads1[] = {MockRead(ASYNC, response_headers_packet->data(),
1919 response_headers_packet->length(), 1),
1920 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2)};
1921 SequencedSocketData socket_data1(reads1, arraysize(reads1), writes1,
1922 arraysize(writes1));
1923 socket_factory_.AddSocketDataProvider(&socket_data1);
1924
1925 // Trigger early connection migration. This should cause a PING frame
1926 // to be emitted.
1927 session->OnPathDegrading();
1928
1929 // Run the message loop so that data queued in the new socket is read by the
1930 // packet reader.
1931 base::RunLoop().RunUntilIdle();
1932
1933 // The session should now be marked as going away. Ensure that
1934 // while it is still alive, it is no longer active.
1935 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1936 EXPECT_FALSE(HasActiveSession(host_port_pair_));
1937 EXPECT_EQ(1u, session->GetNumActiveStreams());
1938
1939 // Verify that response headers on the migrated socket were delivered to the
1940 // stream.
1941 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback()));
1942 EXPECT_EQ(200, response.headers->response_code());
1943
1944 // Create a new request for the same destination and verify that a
1945 // new session is created.
1946 MockRead reads2[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
1947 SequencedSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0);
1948 socket_factory_.AddSocketDataProvider(&socket_data2);
1949
1950 QuicStreamRequest request2(factory_.get());
1951 EXPECT_EQ(ERR_IO_PENDING,
1952 request2.Request(host_port_pair_, privacy_mode_,
1953 /*cert_verify_flags=*/0, host_port_pair_.host(),
1954 "GET", net_log_, callback_.callback()));
1955 EXPECT_EQ(OK, callback_.WaitForResult());
1956 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
1957 EXPECT_TRUE(stream2.get());
1958
1959 EXPECT_TRUE(
1960 QuicStreamFactoryPeer::HasActiveSession(factory_.get(), host_port_pair_));
1961 EXPECT_NE(session, QuicStreamFactoryPeer::GetActiveSession(factory_.get(),
1962 host_port_pair_));
1963
1964 // On a SOON_TO_DISCONNECT notification, nothing happens to the migrated
1965 // session.
1966 scoped_mock_network_change_notifier_->mock_network_change_notifier()
1967 ->NotifyNetworkSoonToDisconnect(kDefaultNetworkForTests);
1968 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1969 EXPECT_EQ(1u, session->GetNumActiveStreams());
1970
Ryan Hamilton 2016/02/05 01:32:55 Either here or below, could you test that the seco
Jana 2016/02/05 03:03:31 Done. Also added this check in an earlier connecti
1971 // On a DISCONNECTED notification, nothing happens to the migrated session.
1972 scoped_mock_network_change_notifier_->mock_network_change_notifier()
1973 ->NotifyNetworkDisconnected(kDefaultNetworkForTests);
1974 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1975 EXPECT_EQ(1u, session->GetNumActiveStreams());
1976
1977 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1978 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1979 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
1980 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
1981 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1982 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1983 }
1984
1985 TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyNoNewNetwork) {
1986 InitializeConnectionMigrationTest({kDefaultNetworkForTests});
1987 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
1988 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1989
1990 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
1991 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket(
1992 1, true, kClientDataStreamId1, QUIC_STREAM_CANCELLED));
1993 MockWrite writes[] = {
1994 MockWrite(SYNCHRONOUS, client_rst->data(), client_rst->length(), 1),
1995 };
1996 SequencedSocketData socket_data(reads, arraysize(reads), writes,
1997 arraysize(writes));
1998 socket_factory_.AddSocketDataProvider(&socket_data);
1999
2000 // Create request and QuicHttpStream.
2001 QuicStreamRequest request(factory_.get());
2002 EXPECT_EQ(ERR_IO_PENDING,
2003 request.Request(host_port_pair_, privacy_mode_,
2004 /*cert_verify_flags=*/0, host_port_pair_.host(),
2005 "GET", net_log_, callback_.callback()));
2006 EXPECT_EQ(OK, callback_.WaitForResult());
2007 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
2008 EXPECT_TRUE(stream.get());
2009
2010 // Cause QUIC stream to be created.
2011 HttpRequestInfo request_info;
2012 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
2013 net_log_, CompletionCallback()));
2014
2015 // Ensure that session is alive and active.
2016 QuicChromiumClientSession* session =
2017 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_);
2018 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2019 EXPECT_TRUE(HasActiveSession(host_port_pair_));
2020
2021 // Trigger connection migration. Since there are no networks
2022 // to migrate to, this should cause session to be continue but be marked as
2023 // going away.
2024 session->OnPathDegrading();
2025
2026 // Run the message loop so that data queued in the new socket is read by the
2027 // packet reader.
2028 base::RunLoop().RunUntilIdle();
2029
2030 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2031 EXPECT_TRUE(HasActiveSession(host_port_pair_));
2032 EXPECT_EQ(1u, session->GetNumActiveStreams());
2033
2034 stream.reset();
2035
2036 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2037 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2038 }
2039
1862 TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) { 2040 TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) {
1863 Initialize(); 2041 Initialize();
1864 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); 2042 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
1865 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 2043 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1866 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 2044 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1867 2045
1868 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; 2046 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
1869 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); 2047 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
1870 std::vector<MockWrite> writes; 2048 std::vector<MockWrite> writes;
1871 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); 2049 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
(...skipping 1477 matching lines...) Expand 10 before | Expand all | Expand 10 after
3349 EXPECT_EQ(1u, observer.executed_count()); 3527 EXPECT_EQ(1u, observer.executed_count());
3350 3528
3351 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); 3529 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
3352 EXPECT_TRUE(stream.get()); 3530 EXPECT_TRUE(stream.get());
3353 EXPECT_TRUE(socket_data.AllReadDataConsumed()); 3531 EXPECT_TRUE(socket_data.AllReadDataConsumed());
3354 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); 3532 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
3355 } 3533 }
3356 3534
3357 } // namespace test 3535 } // namespace test
3358 } // namespace net 3536 } // namespace net
OLDNEW
« net/quic/quic_stream_factory.cc ('K') | « net/quic/quic_stream_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698