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

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

Issue 2856073003: Fix QuicNetworkTransactionTest.RetryMisdirectedRequest (Closed)
Patch Set: rch comment 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 without the socket pool ever
1070 // dispensing the socket, making it available for the second try.
1065 MockQuicData mock_quic_data; 1071 MockQuicData mock_quic_data;
1066 QuicStreamOffset request_header_offset = 0; 1072 QuicStreamOffset request_header_offset = 0;
1067 mock_quic_data.AddWrite( 1073 mock_quic_data.AddWrite(
1068 ConstructInitialSettingsPacket(1, &request_header_offset)); 1074 ConstructInitialSettingsPacket(1, &request_header_offset));
1069 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( 1075 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket(
1070 2, kClientDataStreamId1, true, true, 1076 2, kClientDataStreamId1, true, true,
1071 GetRequestHeaders("GET", "https", "/"), &request_header_offset)); 1077 GetRequestHeaders("GET", "https", "/"), &request_header_offset));
1072 mock_quic_data.AddRead( 1078 mock_quic_data.AddRead(
1073 ConstructServerResponseHeadersPacket(1, kClientDataStreamId1, false, true, 1079 ConstructServerResponseHeadersPacket(1, kClientDataStreamId1, false, true,
1074 GetResponseHeaders("421"), nullptr)); 1080 GetResponseHeaders("421"), nullptr));
1075 mock_quic_data.AddWrite(ConstructClientAckAndRstPacket( 1081 mock_quic_data.AddWrite(ConstructClientAckAndRstPacket(
1076 3, kClientDataStreamId1, QUIC_STREAM_CANCELLED, 1, 1, 1)); 1082 3, kClientDataStreamId1, QUIC_STREAM_CANCELLED, 1, 1, 1));
1077 mock_quic_data.AddRead(ASYNC, OK); 1083 mock_quic_data.AddRead(ASYNC, OK);
1078 mock_quic_data.AddSocketDataToFactory(&socket_factory_); 1084 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
1079 1085
1080 // First try: main job uses TCP, connection fails. 1086 // 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 1087 // Connect() is unblocked, |http_data| will leave the socket pool, binding to
1082 // second try would pool to that socket and hang.) 1088 // 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, 1089 // 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. 1090 // 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. 1091 // 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!"), 1092 MockWrite writes[] = {MockWrite(ASYNC, 0, "GET / HTTP/1.1\r\n"),
1096 MockRead(ASYNC, OK)}; 1093 MockWrite(ASYNC, 1, "Host: mail.example.org\r\n"),
1097 StaticSocketDataProvider http_data(reads, arraysize(reads), nullptr, 0); 1094 MockWrite(ASYNC, 2, "Connection: keep-alive\r\n\r\n")};
1095 MockRead reads[] = {MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"),
1096 MockRead(ASYNC, 4, "hello!"), MockRead(ASYNC, OK, 5)};
1097 SequencedSocketData http_data(MockConnect(ASYNC, ERR_IO_PENDING) /* pause */,
1098 reads, arraysize(reads), writes,
1099 arraysize(writes));
1098 socket_factory_.AddSocketDataProvider(&http_data); 1100 socket_factory_.AddSocketDataProvider(&http_data);
1099 socket_factory_.AddSSLSocketDataProvider(&ssl_data_); 1101 socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
1100 1102
1101 // Retry logic hides ERR_MISDIRECTED_REQUEST: transaction succeeds.
1102 CreateSession(); 1103 CreateSession();
1103 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); 1104 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get());
1104 RunTransaction(&trans); 1105
1106 // Run until |mock_quic_data| has failed and |http_data| has paused.
1107 TestCompletionCallback callback;
1108 int rv = trans.Start(&request_, callback.callback(), net_log_.bound());
1109 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1110 base::RunLoop().RunUntilIdle();
1111
1112 // |mock_quic_data| must have run to completion.
1113 EXPECT_TRUE(mock_quic_data.AllReadDataConsumed());
1114 EXPECT_TRUE(mock_quic_data.AllWriteDataConsumed());
1115
1116 // Now that the QUIC data has been consumed, unblock |http_data|.
1117 http_data.socket()->OnConnectComplete(MockConnect());
1118
1119 // The retry logic must hide the 421 status. The transaction succeeds on
1120 // |http_data|.
1121 EXPECT_THAT(callback.WaitForResult(), IsOk());
1105 CheckWasHttpResponse(&trans); 1122 CheckWasHttpResponse(&trans);
1106 CheckResponsePort(&trans, 443); 1123 CheckResponsePort(&trans, 443);
1107 CheckResponseData(&trans, "hello!"); 1124 CheckResponseData(&trans, "hello!");
1108 } 1125 }
1109 1126
1110 TEST_P(QuicNetworkTransactionTest, ForceQuicWithErrorConnecting) { 1127 TEST_P(QuicNetworkTransactionTest, ForceQuicWithErrorConnecting) {
1111 params_.origins_to_force_quic_on.insert( 1128 params_.origins_to_force_quic_on.insert(
1112 HostPortPair::FromString("mail.example.org:443")); 1129 HostPortPair::FromString("mail.example.org:443"));
1113 1130
1114 MockQuicData mock_quic_data1; 1131 MockQuicData mock_quic_data1;
(...skipping 3509 matching lines...) Expand 10 before | Expand all | Expand 10 after
4624 4641
4625 request_.url = GURL("https://mail.example.org/pushed.jpg"); 4642 request_.url = GURL("https://mail.example.org/pushed.jpg");
4626 ChunkedUploadDataStream upload_data(0); 4643 ChunkedUploadDataStream upload_data(0);
4627 upload_data.AppendData("1", 1, true); 4644 upload_data.AppendData("1", 1, true);
4628 request_.upload_data_stream = &upload_data; 4645 request_.upload_data_stream = &upload_data;
4629 SendRequestAndExpectQuicResponse("and hello!"); 4646 SendRequestAndExpectQuicResponse("and hello!");
4630 } 4647 }
4631 4648
4632 } // namespace test 4649 } // namespace test
4633 } // namespace net 4650 } // 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