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

Side by Side Diff: net/quic/chromium/quic_network_transaction_unittest.cc

Issue 2856073003: Fix QuicNetworkTransactionTest.RetryMisdirectedRequest (Closed)
Patch Set: Created 3 years, 7 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 | no next file » | 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) 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 <memory> 5 #include <memory>
6 #include <ostream> 6 #include <ostream>
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 // Set up alternative service to use QUIC. 1054 // Set up alternative service to use QUIC.
1055 // Note that |origins_to_force_quic_on| cannot be used in this test, because 1055 // Note that |origins_to_force_quic_on| cannot be used in this test, because
1056 // that overrides |enable_alternative_services|. 1056 // that overrides |enable_alternative_services|.
1057 url::SchemeHostPort server(request_.url); 1057 url::SchemeHostPort server(request_.url);
1058 AlternativeService alternative_service(kProtoQUIC, kDefaultServerHostName, 1058 AlternativeService alternative_service(kProtoQUIC, kDefaultServerHostName,
1059 443); 1059 443);
1060 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 1060 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
1061 http_server_properties_.SetAlternativeService(server, alternative_service, 1061 http_server_properties_.SetAlternativeService(server, alternative_service,
1062 expiration); 1062 expiration);
1063 1063
1064 // First try: alternative job uses QUIC, gets 421 Misdirected Request error. 1064 // First try: The alternative job uses QUIC and reports an HTTP 421
1065 // Misdirected Request error. The main job uses TCP, but |http_data| below is
1066 // paused at Connect(), so it will never exit the socket pool. This ensures
1067 // that the alternate job always wins the race and keeps whether the
1068 // |http_data| exits the socket pool before the main job is aborted
1069 // deterministic. The first main job gets aborted with no socket.
Ryan Hamilton 2017/05/03 23:20:39 Hm. This comment seems to say: 1) The main job at
davidben 2017/05/03 23:33:13 (1) isn't quite true. The socket pools call Connec
Ryan Hamilton 2017/05/03 23:38:55 Ah. Ok, I think the test is fine. (no surprise the
davidben 2017/05/03 23:43:40 Done.
1065 MockQuicData mock_quic_data; 1070 MockQuicData mock_quic_data;
1066 QuicStreamOffset request_header_offset = 0; 1071 QuicStreamOffset request_header_offset = 0;
1067 mock_quic_data.AddWrite( 1072 mock_quic_data.AddWrite(
1068 ConstructInitialSettingsPacket(1, &request_header_offset)); 1073 ConstructInitialSettingsPacket(1, &request_header_offset));
1069 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( 1074 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket(
1070 2, kClientDataStreamId1, true, true, 1075 2, kClientDataStreamId1, true, true,
1071 GetRequestHeaders("GET", "https", "/"), &request_header_offset)); 1076 GetRequestHeaders("GET", "https", "/"), &request_header_offset));
1072 mock_quic_data.AddRead( 1077 mock_quic_data.AddRead(
1073 ConstructServerResponseHeadersPacket(1, kClientDataStreamId1, false, true, 1078 ConstructServerResponseHeadersPacket(1, kClientDataStreamId1, false, true,
1074 GetResponseHeaders("421"), nullptr)); 1079 GetResponseHeaders("421"), nullptr));
1075 mock_quic_data.AddWrite(ConstructClientAckAndRstPacket( 1080 mock_quic_data.AddWrite(ConstructClientAckAndRstPacket(
1076 3, kClientDataStreamId1, QUIC_STREAM_CANCELLED, 1, 1, 1)); 1081 3, kClientDataStreamId1, QUIC_STREAM_CANCELLED, 1, 1, 1));
1077 mock_quic_data.AddRead(ASYNC, OK); 1082 mock_quic_data.AddRead(ASYNC, OK);
1078 mock_quic_data.AddSocketDataToFactory(&socket_factory_); 1083 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
1079 1084
1080 // First try: main job uses TCP, connection fails. 1085 // Second try: The main job uses TCP, and there is no alternate job. Once the
1081 // (A hanging connection would not work here, because the main Job on the 1086 // Connect() is unblocked, |http_data| will leave the socket pool, binding to
1082 // second try would pool to that socket and hang.) 1087 // the main job of the second request. It then succeeds over HTTP/1.1.
1083 StaticSocketDataProvider failing_data;
1084 MockConnect failing_connect(SYNCHRONOUS, ERR_CONNECTION_CLOSED);
1085 failing_data.set_connect_data(failing_connect);
1086 socket_factory_.AddSocketDataProvider(&failing_data);
1087 socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
1088
1089 // Second try: there is only one job, which succeeds over HTTP/1.1.
1090 // There is no open TCP socket (the previous TCP connection got closed), so a
1091 // new one is opened.
1092 // Note that if there was an alternative QUIC Job created for the second try, 1088 // Note that if there was an alternative QUIC Job created for the second try,
1093 // that would read these data, and would fail with ERR_QUIC_PROTOCOL_ERROR. 1089 // that would read these data, and would fail with ERR_QUIC_PROTOCOL_ERROR.
1094 // Therefore this test ensures that no alternative Job is created on retry. 1090 // Therefore this test ensures that no alternative Job is created on retry.
1095 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello!"), 1091 MockWrite writes[] = {MockWrite(ASYNC, 0, "GET / HTTP/1.1\r\n"),
1096 MockRead(ASYNC, OK)}; 1092 MockWrite(ASYNC, 1, "Host: mail.example.org\r\n"),
1097 StaticSocketDataProvider http_data(reads, arraysize(reads), nullptr, 0); 1093 MockWrite(ASYNC, 2, "Connection: keep-alive\r\n\r\n")};
1094 MockRead reads[] = {MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"),
1095 MockRead(ASYNC, 4, "hello!"), MockRead(ASYNC, OK, 5)};
1096 SequencedSocketData http_data(MockConnect(ASYNC, ERR_IO_PENDING) /* pause */,
1097 reads, arraysize(reads), writes,
1098 arraysize(writes));
1098 socket_factory_.AddSocketDataProvider(&http_data); 1099 socket_factory_.AddSocketDataProvider(&http_data);
1099 socket_factory_.AddSSLSocketDataProvider(&ssl_data_); 1100 socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
1100 1101
1101 // Retry logic hides ERR_MISDIRECTED_REQUEST: transaction succeeds.
1102 CreateSession(); 1102 CreateSession();
1103 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); 1103 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get());
1104 RunTransaction(&trans); 1104
1105 // Run until |mock_quic_data| has failed and |http_data| has paused.
1106 TestCompletionCallback callback;
1107 int rv = trans.Start(&request_, callback.callback(), net_log_.bound());
1108 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1109 base::RunLoop().RunUntilIdle();
1110
1111 // |mock_quic_data| must have run to completion.
1112 EXPECT_TRUE(mock_quic_data.AllReadDataConsumed());
1113 EXPECT_TRUE(mock_quic_data.AllWriteDataConsumed());
1114
1115 // Now that the QUIC data has been consumed, unblock |http_data|.
1116 http_data.socket()->OnConnectComplete(MockConnect());
1117
1118 // The retry logic must hide the 421 status. The transaction succeeds on
1119 // |http_data|.
1120 EXPECT_THAT(callback.WaitForResult(), IsOk());
1105 CheckWasHttpResponse(&trans); 1121 CheckWasHttpResponse(&trans);
1106 CheckResponsePort(&trans, 443); 1122 CheckResponsePort(&trans, 443);
1107 CheckResponseData(&trans, "hello!"); 1123 CheckResponseData(&trans, "hello!");
1108 } 1124 }
1109 1125
1110 TEST_P(QuicNetworkTransactionTest, ForceQuicWithErrorConnecting) { 1126 TEST_P(QuicNetworkTransactionTest, ForceQuicWithErrorConnecting) {
1111 params_.origins_to_force_quic_on.insert( 1127 params_.origins_to_force_quic_on.insert(
1112 HostPortPair::FromString("mail.example.org:443")); 1128 HostPortPair::FromString("mail.example.org:443"));
1113 1129
1114 MockQuicData mock_quic_data1; 1130 MockQuicData mock_quic_data1;
(...skipping 3509 matching lines...) Expand 10 before | Expand all | Expand 10 after
4624 4640
4625 request_.url = GURL("https://mail.example.org/pushed.jpg"); 4641 request_.url = GURL("https://mail.example.org/pushed.jpg");
4626 ChunkedUploadDataStream upload_data(0); 4642 ChunkedUploadDataStream upload_data(0);
4627 upload_data.AppendData("1", 1, true); 4643 upload_data.AppendData("1", 1, true);
4628 request_.upload_data_stream = &upload_data; 4644 request_.upload_data_stream = &upload_data;
4629 SendRequestAndExpectQuicResponse("and hello!"); 4645 SendRequestAndExpectQuicResponse("and hello!");
4630 } 4646 }
4631 4647
4632 } // namespace test 4648 } // namespace test
4633 } // namespace net 4649 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698