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

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

Issue 1651153005: changes QUIC negotiation about max open streams which effects server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@113042237
Patch Set: 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
« no previous file with comments | « net/quic/quic_session.cc ('k') | net/quic/test_tools/quic_session_peer.h » ('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) 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_session.h" 5 #include "net/quic/quic_session.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 128
129 TestStream* CreateOutgoingDynamicStream(SpdyPriority priority) override { 129 TestStream* CreateOutgoingDynamicStream(SpdyPriority priority) override {
130 TestStream* stream = new TestStream(GetNextOutgoingStreamId(), this); 130 TestStream* stream = new TestStream(GetNextOutgoingStreamId(), this);
131 stream->SetPriority(priority); 131 stream->SetPriority(priority);
132 ActivateStream(stream); 132 ActivateStream(stream);
133 return stream; 133 return stream;
134 } 134 }
135 135
136 TestStream* CreateIncomingDynamicStream(QuicStreamId id) override { 136 TestStream* CreateIncomingDynamicStream(QuicStreamId id) override {
137 // Enforce the limit on the number of open streams. 137 // Enforce the limit on the number of open streams.
138 if (GetNumOpenIncomingStreams() + 1 > get_max_open_streams()) { 138 if (GetNumOpenIncomingStreams() + 1 > max_open_incoming_streams()) {
139 connection()->SendConnectionCloseWithDetails(QUIC_TOO_MANY_OPEN_STREAMS, 139 connection()->SendConnectionCloseWithDetails(QUIC_TOO_MANY_OPEN_STREAMS,
140 "Too many streams!"); 140 "Too many streams!");
141 return nullptr; 141 return nullptr;
142 } else { 142 } else {
143 return new TestStream(id, this); 143 return new TestStream(id, this);
144 } 144 }
145 } 145 }
146 146
147 bool IsClosedStream(QuicStreamId id) { 147 bool IsClosedStream(QuicStreamId id) {
148 return QuicSession::IsClosedStream(id); 148 return QuicSession::IsClosedStream(id);
149 } 149 }
150 150
151 ReliableQuicStream* GetOrCreateDynamicStream(QuicStreamId stream_id) { 151 ReliableQuicStream* GetOrCreateDynamicStream(QuicStreamId stream_id) {
152 return QuicSpdySession::GetOrCreateDynamicStream(stream_id); 152 return QuicSpdySession::GetOrCreateDynamicStream(stream_id);
153 } 153 }
154 154
155 QuicConsumedData WritevData( 155 QuicConsumedData WritevData(
156 QuicStreamId id, 156 QuicStreamId id,
157 QuicIOVector data, 157 QuicIOVector data,
158 QuicStreamOffset offset, 158 QuicStreamOffset offset,
159 bool fin, 159 bool fin,
160 FecProtection fec_protection, 160 FecProtection fec_protection,
161 QuicAckListenerInterface* ack_notifier_delegate) override { 161 QuicAckListenerInterface* ack_notifier_delegate) override {
162 QuicConsumedData consumed(data.total_length, fin); 162 QuicConsumedData consumed(data.total_length, fin);
163 if (!writev_consumes_all_data_) { 163 if (!writev_consumes_all_data_) {
164 consumed = QuicSession::WritevData(id, data, offset, fin, fec_protection, 164 consumed = QuicSession::WritevData(id, data, offset, fin, fec_protection,
165 ack_notifier_delegate); 165 ack_notifier_delegate);
166 } 166 }
167 QuicSessionPeer::GetWriteBlockedStreams(this) 167 QuicSessionPeer::GetWriteBlockedStreams(this)->UpdateBytesForStream(
168 ->UpdateBytesForStream(id, consumed.bytes_consumed); 168 id, consumed.bytes_consumed);
169 return consumed; 169 return consumed;
170 } 170 }
171 171
172 void set_writev_consumes_all_data(bool val) { 172 void set_writev_consumes_all_data(bool val) {
173 writev_consumes_all_data_ = val; 173 writev_consumes_all_data_ = val;
174 } 174 }
175 175
176 QuicConsumedData SendStreamData(QuicStreamId id) { 176 QuicConsumedData SendStreamData(QuicStreamId id) {
177 struct iovec iov; 177 struct iovec iov;
178 return WritevData(id, MakeIOVector("not empty", &iov), 0, true, 178 return WritevData(id, MakeIOVector("not empty", &iov), 0, true,
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 CloseStream(stream3->id()); 334 CloseStream(stream3->id());
335 CheckClosedStreams(); 335 CheckClosedStreams();
336 } 336 }
337 337
338 TEST_P(QuicSessionTestServer, MaximumAvailableOpenedStreams) { 338 TEST_P(QuicSessionTestServer, MaximumAvailableOpenedStreams) {
339 QuicStreamId stream_id = kClientDataStreamId1; 339 QuicStreamId stream_id = kClientDataStreamId1;
340 session_.GetOrCreateDynamicStream(stream_id); 340 session_.GetOrCreateDynamicStream(stream_id);
341 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(_, _)).Times(0); 341 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(_, _)).Times(0);
342 EXPECT_NE(nullptr, 342 EXPECT_NE(nullptr,
343 session_.GetOrCreateDynamicStream( 343 session_.GetOrCreateDynamicStream(
344 stream_id + 2 * (session_.get_max_open_streams() - 1))); 344 stream_id + 2 * (session_.max_open_incoming_streams() - 1)));
345 } 345 }
346 346
347 TEST_P(QuicSessionTestServer, TooManyAvailableStreams) { 347 TEST_P(QuicSessionTestServer, TooManyAvailableStreams) {
348 QuicStreamId stream_id1 = kClientDataStreamId1; 348 QuicStreamId stream_id1 = kClientDataStreamId1;
349 QuicStreamId stream_id2; 349 QuicStreamId stream_id2;
350 EXPECT_NE(nullptr, session_.GetOrCreateDynamicStream(stream_id1)); 350 EXPECT_NE(nullptr, session_.GetOrCreateDynamicStream(stream_id1));
351 // A stream ID which is too large to create. 351 // A stream ID which is too large to create.
352 stream_id2 = stream_id1 + 2 * session_.get_max_available_streams() + 4; 352 stream_id2 = stream_id1 + 2 * session_.MaxAvailableStreams() + 4;
353 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( 353 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(
354 QUIC_TOO_MANY_AVAILABLE_STREAMS, _)); 354 QUIC_TOO_MANY_AVAILABLE_STREAMS, _));
355 EXPECT_EQ(nullptr, session_.GetOrCreateDynamicStream(stream_id2)); 355 EXPECT_EQ(nullptr, session_.GetOrCreateDynamicStream(stream_id2));
356 } 356 }
357 357
358 TEST_P(QuicSessionTestServer, ManyAvailableStreams) { 358 TEST_P(QuicSessionTestServer, ManyAvailableStreams) {
359 // When max_open_streams_ is 200, should be able to create 200 streams 359 // When max_open_streams_ is 200, should be able to create 200 streams
360 // out-of-order, that is, creating the one with the largest stream ID first. 360 // out-of-order, that is, creating the one with the largest stream ID first.
361 QuicSessionPeer::SetMaxOpenStreams(&session_, 200); 361 QuicSessionPeer::SetMaxOpenIncomingStreams(&session_, 200);
362 QuicStreamId stream_id = kClientDataStreamId1; 362 QuicStreamId stream_id = kClientDataStreamId1;
363 // Create one stream. 363 // Create one stream.
364 session_.GetOrCreateDynamicStream(stream_id); 364 session_.GetOrCreateDynamicStream(stream_id);
365 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(_, _)).Times(0); 365 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(_, _)).Times(0);
366 // Create the largest stream ID of a threatened total of 200 streams. 366 // Create the largest stream ID of a threatened total of 200 streams.
367 session_.GetOrCreateDynamicStream(stream_id + 2 * (200 - 1)); 367 session_.GetOrCreateDynamicStream(stream_id + 2 * (200 - 1));
368 } 368 }
369 369
370 TEST_P(QuicSessionTestServer, DebugDFatalIfMarkingClosedStreamWriteBlocked) { 370 TEST_P(QuicSessionTestServer, DebugDFatalIfMarkingClosedStreamWriteBlocked) {
371 TestStream* stream2 = session_.CreateOutgoingDynamicStream(kDefaultPriority); 371 TestStream* stream2 = session_.CreateOutgoingDynamicStream(kDefaultPriority);
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked()); 1071 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
1072 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); 1072 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
1073 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); 1073 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
1074 } 1074 }
1075 1075
1076 TEST_P(QuicSessionTestServer, TooManyUnfinishedStreamsCauseServerRejectStream) { 1076 TEST_P(QuicSessionTestServer, TooManyUnfinishedStreamsCauseServerRejectStream) {
1077 // If a buggy/malicious peer creates too many streams that are not ended 1077 // If a buggy/malicious peer creates too many streams that are not ended
1078 // with a FIN or RST then we send a connection close or an RST to 1078 // with a FIN or RST then we send a connection close or an RST to
1079 // refuse streams. 1079 // refuse streams.
1080 const QuicStreamId kMaxStreams = 5; 1080 const QuicStreamId kMaxStreams = 5;
1081 QuicSessionPeer::SetMaxOpenStreams(&session_, kMaxStreams); 1081 QuicSessionPeer::SetMaxOpenIncomingStreams(&session_, kMaxStreams);
1082 const QuicStreamId kFirstStreamId = kClientDataStreamId1; 1082 const QuicStreamId kFirstStreamId = kClientDataStreamId1;
1083 const QuicStreamId kFinalStreamId = kClientDataStreamId1 + 2 * kMaxStreams; 1083 const QuicStreamId kFinalStreamId = kClientDataStreamId1 + 2 * kMaxStreams;
1084 1084
1085 // Create kMaxStreams data streams, and close them all without receiving a 1085 // Create kMaxStreams data streams, and close them all without receiving a
1086 // FIN or a RST_STREAM from the client. 1086 // FIN or a RST_STREAM from the client.
1087 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) { 1087 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) {
1088 QuicStreamFrame data1(i, false, 0, StringPiece("HT")); 1088 QuicStreamFrame data1(i, false, 0, StringPiece("HT"));
1089 session_.OnStreamFrame(data1); 1089 session_.OnStreamFrame(data1);
1090 // EXPECT_EQ(1u, session_.GetNumOpenStreams()); 1090 // EXPECT_EQ(1u, session_.GetNumOpenStreams());
1091 EXPECT_CALL(*connection_, SendRstStream(i, _, _)); 1091 EXPECT_CALL(*connection_, SendRstStream(i, _, _));
(...skipping 24 matching lines...) Expand all
1116 // protocol point of view). 1116 // protocol point of view).
1117 if (GetParam() <= QUIC_VERSION_27) { 1117 if (GetParam() <= QUIC_VERSION_27) {
1118 EXPECT_CALL(*connection_, 1118 EXPECT_CALL(*connection_,
1119 SendConnectionCloseWithDetails(QUIC_TOO_MANY_OPEN_STREAMS, _)) 1119 SendConnectionCloseWithDetails(QUIC_TOO_MANY_OPEN_STREAMS, _))
1120 .Times(0); 1120 .Times(0);
1121 } else { 1121 } else {
1122 EXPECT_CALL(*connection_, SendRstStream(_, QUIC_REFUSED_STREAM, _)) 1122 EXPECT_CALL(*connection_, SendRstStream(_, QUIC_REFUSED_STREAM, _))
1123 .Times(0); 1123 .Times(0);
1124 } 1124 }
1125 const QuicStreamId kMaxStreams = 5; 1125 const QuicStreamId kMaxStreams = 5;
1126 QuicSessionPeer::SetMaxOpenStreams(&session_, kMaxStreams); 1126 QuicSessionPeer::SetMaxOpenIncomingStreams(&session_, kMaxStreams);
1127 1127
1128 // Create kMaxStreams + 1 data streams, and mark them draining. 1128 // Create kMaxStreams + 1 data streams, and mark them draining.
1129 const QuicStreamId kFirstStreamId = kClientDataStreamId1; 1129 const QuicStreamId kFirstStreamId = kClientDataStreamId1;
1130 const QuicStreamId kFinalStreamId = 1130 const QuicStreamId kFinalStreamId =
1131 kClientDataStreamId1 + 2 * kMaxStreams + 1; 1131 kClientDataStreamId1 + 2 * kMaxStreams + 1;
1132 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) { 1132 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) {
1133 QuicStreamFrame data1(i, true, 0, StringPiece("HT")); 1133 QuicStreamFrame data1(i, true, 0, StringPiece("HT"));
1134 session_.OnStreamFrame(data1); 1134 session_.OnStreamFrame(data1);
1135 EXPECT_EQ(1u, session_.GetNumOpenIncomingStreams()); 1135 EXPECT_EQ(1u, session_.GetNumOpenIncomingStreams());
1136 session_.StreamDraining(i); 1136 session_.StreamDraining(i);
1137 EXPECT_EQ(0u, session_.GetNumOpenIncomingStreams()); 1137 EXPECT_EQ(0u, session_.GetNumOpenIncomingStreams());
1138 } 1138 }
1139 1139
1140 // Called after any new data is received by the session, and triggers the call 1140 // Called after any new data is received by the session, and triggers the call
1141 // to close the connection. 1141 // to close the connection.
1142 session_.PostProcessAfterData(); 1142 session_.PostProcessAfterData();
1143 } 1143 }
1144 1144
1145 TEST_P(QuicSessionTestServer, TestMaxIncomingAndOutgoingStreamsAllowed) {
1146 // Tests that on server side, the value of max_open_incoming/outgoing streams
1147 // are setup correctly during negotiation.
1148 // When FLAGS_quic_different_max_num_open_streams is off, both of them are a
1149 // little larger than negotiated values. When flag is true, the value for
1150 // outgoing stream is limited to negotiated value and for incoming stream it
1151 // is set to be larger than that.
1152 session_.OnConfigNegotiated();
1153 if (FLAGS_quic_different_max_num_open_streams) {
1154 // The max number of open outgoing streams is less than that of incoming
1155 // streams, and it should be same as negotiated value.
1156 EXPECT_LT(session_.max_open_outgoing_streams(),
1157 session_.max_open_incoming_streams());
1158 EXPECT_EQ(session_.max_open_outgoing_streams(),
1159 kDefaultMaxStreamsPerConnection);
1160 } else {
1161 // The max number of outgoing/incoming streams are the same.
1162 EXPECT_EQ(session_.max_open_outgoing_streams(),
1163 session_.max_open_incoming_streams());
1164 }
1165
1166 EXPECT_GT(session_.max_open_incoming_streams(),
1167 kDefaultMaxStreamsPerConnection);
1168 }
1169
1145 class QuicSessionTestClient : public QuicSessionTestBase { 1170 class QuicSessionTestClient : public QuicSessionTestBase {
1146 protected: 1171 protected:
1147 QuicSessionTestClient() : QuicSessionTestBase(Perspective::IS_CLIENT) {} 1172 QuicSessionTestClient() : QuicSessionTestBase(Perspective::IS_CLIENT) {}
1148 }; 1173 };
1149 1174
1150 INSTANTIATE_TEST_CASE_P(Tests, 1175 INSTANTIATE_TEST_CASE_P(Tests,
1151 QuicSessionTestClient, 1176 QuicSessionTestClient,
1152 ::testing::ValuesIn(QuicSupportedVersions())); 1177 ::testing::ValuesIn(QuicSupportedVersions()));
1153 1178
1154 TEST_P(QuicSessionTestClient, AvailableStreamsClient) { 1179 TEST_P(QuicSessionTestClient, AvailableStreamsClient) {
(...skipping 28 matching lines...) Expand all
1183 EXPECT_TRUE(ReliableQuicStreamPeer::read_side_closed(stream)); 1208 EXPECT_TRUE(ReliableQuicStreamPeer::read_side_closed(stream));
1184 1209
1185 // Allow the session to delete the stream object. 1210 // Allow the session to delete the stream object.
1186 session_.PostProcessAfterData(); 1211 session_.PostProcessAfterData();
1187 EXPECT_TRUE(connection_->connected()); 1212 EXPECT_TRUE(connection_->connected());
1188 EXPECT_TRUE(QuicSessionPeer::IsStreamClosed(&session_, stream_id)); 1213 EXPECT_TRUE(QuicSessionPeer::IsStreamClosed(&session_, stream_id));
1189 EXPECT_EQ(nullptr, QuicSessionPeer::dynamic_streams(&session_)[stream_id]); 1214 EXPECT_EQ(nullptr, QuicSessionPeer::dynamic_streams(&session_)[stream_id]);
1190 1215
1191 // The stream is not waiting for the arrival of the peer's final offset as it 1216 // The stream is not waiting for the arrival of the peer's final offset as it
1192 // was received with the FIN earlier. 1217 // was received with the FIN earlier.
1193 EXPECT_EQ(0u, QuicSessionPeer::GetLocallyClosedStreamsHighestOffset(&session_) 1218 EXPECT_EQ(
1194 .size()); 1219 0u,
1220 QuicSessionPeer::GetLocallyClosedStreamsHighestOffset(&session_).size());
1221 }
1222
1223 TEST_P(QuicSessionTestClient, TestMaxIncomingAndOutgoingStreamsAllowed) {
1224 // Tests that on client side, the value of max_open_incoming/outgoing streams
1225 // are setup correctly during negotiation.
1226 // When FLAGS_quic_different_max_num_open_streams is off, both of them are
1227 // same as negotiated value. When flag is true, the value for outgoing stream
1228 // is limited to negotiated value and for incoming stream it is set to be
1229 // larger than that.
1230 session_.OnConfigNegotiated();
1231 if (FLAGS_quic_different_max_num_open_streams) {
1232 EXPECT_LT(session_.max_open_outgoing_streams(),
1233 session_.max_open_incoming_streams());
1234 } else {
1235 EXPECT_EQ(session_.max_open_outgoing_streams(),
1236 session_.max_open_incoming_streams());
1237 }
1238
1239 EXPECT_EQ(session_.max_open_outgoing_streams(),
1240 kDefaultMaxStreamsPerConnection);
1195 } 1241 }
1196 1242
1197 } // namespace 1243 } // namespace
1198 } // namespace test 1244 } // namespace test
1199 } // namespace net 1245 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_session.cc ('k') | net/quic/test_tools/quic_session_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698