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

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

Issue 2862563003: Landing Recent QUIC changes until Sat Apr 29 00:22:04 2017 +0000 (Closed)
Patch Set: rebase and fix test bugs detected by swarm bot. 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 | « net/quic/core/quic_session.cc ('k') | net/quic/core/quic_spdy_session.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/core/quic_session.h" 5 #include "net/quic/core/quic_session.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 session()->config()->ToHandshakeMessage(&msg); 65 session()->config()->ToHandshakeMessage(&msg);
66 const QuicErrorCode error = 66 const QuicErrorCode error =
67 session()->config()->ProcessPeerHello(msg, CLIENT, &error_details); 67 session()->config()->ProcessPeerHello(msg, CLIENT, &error_details);
68 EXPECT_EQ(QUIC_NO_ERROR, error); 68 EXPECT_EQ(QUIC_NO_ERROR, error);
69 session()->OnConfigNegotiated(); 69 session()->OnConfigNegotiated();
70 session()->connection()->SetDefaultEncryptionLevel( 70 session()->connection()->SetDefaultEncryptionLevel(
71 ENCRYPTION_FORWARD_SECURE); 71 ENCRYPTION_FORWARD_SECURE);
72 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED); 72 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED);
73 } 73 }
74 74
75 void set_encryption_established(bool value) {
76 encryption_established_ = value;
77 }
78
75 MOCK_METHOD0(OnCanWrite, void()); 79 MOCK_METHOD0(OnCanWrite, void());
76 }; 80 };
77 81
78 class TestHeadersStream : public QuicHeadersStream { 82 class TestHeadersStream : public QuicHeadersStream {
79 public: 83 public:
80 explicit TestHeadersStream(QuicSpdySession* session) 84 explicit TestHeadersStream(QuicSpdySession* session)
81 : QuicHeadersStream(session) {} 85 : QuicHeadersStream(session) {}
82 86
83 MOCK_METHOD0(OnCanWrite, void()); 87 MOCK_METHOD0(OnCanWrite, void());
84 }; 88 };
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 return stream; 156 return stream;
153 } 157 }
154 } 158 }
155 159
156 bool ShouldCreateIncomingDynamicStream(QuicStreamId /*id*/) override { 160 bool ShouldCreateIncomingDynamicStream(QuicStreamId /*id*/) override {
157 return true; 161 return true;
158 } 162 }
159 163
160 bool ShouldCreateOutgoingDynamicStream() override { return true; } 164 bool ShouldCreateOutgoingDynamicStream() override { return true; }
161 165
166 TestStream* MaybeCreateOutgoingDynamicStream(SpdyPriority priority) override {
167 return static_cast<TestStream*>(
168 QuicSpdySession::MaybeCreateOutgoingDynamicStream(priority));
169 }
170
171 std::unique_ptr<QuicStream> CreateStream(QuicStreamId id) override {
172 return QuicMakeUnique<TestStream>(id, this);
173 }
174
162 bool IsClosedStream(QuicStreamId id) { 175 bool IsClosedStream(QuicStreamId id) {
163 return QuicSession::IsClosedStream(id); 176 return QuicSession::IsClosedStream(id);
164 } 177 }
165 178
166 QuicStream* GetOrCreateDynamicStream(QuicStreamId stream_id) { 179 QuicStream* GetOrCreateDynamicStream(QuicStreamId stream_id) {
167 return QuicSpdySession::GetOrCreateDynamicStream(stream_id); 180 return QuicSpdySession::GetOrCreateDynamicStream(stream_id);
168 } 181 }
169 182
170 QuicConsumedData WritevData( 183 QuicConsumedData WritevData(
171 QuicStream* stream, 184 QuicStream* stream,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 "3Rs1UKCuBAF9g8rWNOFbxt8PSNSHFuIhOo2t6bJAVpCsMU5Laa6lewuTMYI8MzdQP" 269 "3Rs1UKCuBAF9g8rWNOFbxt8PSNSHFuIhOo2t6bJAVpCsMU5Laa6lewuTMYI8MzdQP"
257 "ARHKyW-koxuhMZHUnGBJAM1gJODe0cATO_KGoX4pbbFxxJ5IicRxOrWK_5rU3cdy6" 270 "ARHKyW-koxuhMZHUnGBJAM1gJODe0cATO_KGoX4pbbFxxJ5IicRxOrWK_5rU3cdy6"
258 "edlR9FsEdH6iujMcHkbE5l18ehJDwTWmBKBzVD87naobhMMrF6VvnDGxQVGp9Ir_b" 271 "edlR9FsEdH6iujMcHkbE5l18ehJDwTWmBKBzVD87naobhMMrF6VvnDGxQVGp9Ir_b"
259 "Rgj3RWUoPumQVCxtSOBdX0GlJOEcDTNCzQIm9BSfetog_eP_TfYubKudt5eMsXmN6" 272 "Rgj3RWUoPumQVCxtSOBdX0GlJOEcDTNCzQIm9BSfetog_eP_TfYubKudt5eMsXmN6"
260 "QnyXHeGeK2UINUzJ-D30AFcpqYgH9_1BvYSpi7fc7_ydBU8TaD8ZRxvtnzXqj0RfG" 273 "QnyXHeGeK2UINUzJ-D30AFcpqYgH9_1BvYSpi7fc7_ydBU8TaD8ZRxvtnzXqj0RfG"
261 "tuHghmv3aD-uzSYJ75XDdzKdizZ86IG6Fbn1XFhYZM-fbHhm3mVEXnyRW4ZuNOLFk" 274 "tuHghmv3aD-uzSYJ75XDdzKdizZ86IG6Fbn1XFhYZM-fbHhm3mVEXnyRW4ZuNOLFk"
262 "Fas6LMcVC6Q8QLlHYbXBpdNFuGbuZGUnav5C-2I_-46lL0NGg3GewxGKGHvHEfoyn" 275 "Fas6LMcVC6Q8QLlHYbXBpdNFuGbuZGUnav5C-2I_-46lL0NGg3GewxGKGHvHEfoyn"
263 "EFFlEYHsBQ98rXImL8ySDycdLEFvBPdtctPmWCfTxwmoSMLHU2SCVDhbqMWU5b0yr" 276 "EFFlEYHsBQ98rXImL8ySDycdLEFvBPdtctPmWCfTxwmoSMLHU2SCVDhbqMWU5b0yr"
264 "JBCScs_ejbKaqBDoB7ZGxTvqlrB__2ZmnHHjCr8RgMRtKNtIeuZAo "; 277 "JBCScs_ejbKaqBDoB7ZGxTvqlrB__2ZmnHHjCr8RgMRtKNtIeuZAo ";
265 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); 278 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1));
279 if (FLAGS_quic_reloadable_flag_quic_refactor_stream_creation) {
280 session_.GetMutableCryptoStream()->set_encryption_established(true);
281 }
266 } 282 }
267 283
268 void CheckClosedStreams() { 284 void CheckClosedStreams() {
269 for (QuicStreamId i = kCryptoStreamId; i < 100; i++) { 285 for (QuicStreamId i = kCryptoStreamId; i < 100; i++) {
270 if (!QuicContainsKey(closed_streams_, i)) { 286 if (!QuicContainsKey(closed_streams_, i)) {
271 EXPECT_FALSE(session_.IsClosedStream(i)) << " stream id: " << i; 287 EXPECT_FALSE(session_.IsClosedStream(i)) << " stream id: " << i;
272 } else { 288 } else {
273 EXPECT_TRUE(session_.IsClosedStream(i)) << " stream id: " << i; 289 EXPECT_TRUE(session_.IsClosedStream(i)) << " stream id: " << i;
274 } 290 }
275 } 291 }
276 } 292 }
277 293
278 void CloseStream(QuicStreamId id) { 294 void CloseStream(QuicStreamId id) {
279 EXPECT_CALL(*connection_, SendRstStream(id, _, _)); 295 EXPECT_CALL(*connection_, SendRstStream(id, _, _));
280 session_.CloseStream(id); 296 session_.CloseStream(id);
281 closed_streams_.insert(id); 297 closed_streams_.insert(id);
282 } 298 }
283 299
284 QuicVersion version() const { return connection_->version(); } 300 QuicVersion version() const { return connection_->version(); }
285 301
302 QuicStreamId GetNthClientInitiatedId(int n) {
303 return QuicSpdySessionPeer::GetNthClientInitiatedStreamId(session_, n);
304 }
305
306 QuicStreamId GetNthServerInitiatedId(int n) {
307 return QuicSpdySessionPeer::GetNthServerInitiatedStreamId(session_, n);
308 }
309
310 QuicStreamId NextId() { return QuicSpdySessionPeer::NextStreamId(session_); }
311
286 MockQuicConnectionHelper helper_; 312 MockQuicConnectionHelper helper_;
287 MockAlarmFactory alarm_factory_; 313 MockAlarmFactory alarm_factory_;
288 StrictMock<MockQuicConnection>* connection_; 314 StrictMock<MockQuicConnection>* connection_;
289 TestSession session_; 315 TestSession session_;
290 std::set<QuicStreamId> closed_streams_; 316 std::set<QuicStreamId> closed_streams_;
291 SpdyHeaderBlock headers_; 317 SpdyHeaderBlock headers_;
292 }; 318 };
293 319
294 class QuicSessionTestServer : public QuicSessionTestBase { 320 class QuicSessionTestServer : public QuicSessionTestBase {
295 protected: 321 protected:
(...skipping 27 matching lines...) Expand all
323 ASSERT_TRUE(session_.GetOrCreateDynamicStream(9) != nullptr); 349 ASSERT_TRUE(session_.GetOrCreateDynamicStream(9) != nullptr);
324 // Both 5 and 7 should be available. 350 // Both 5 and 7 should be available.
325 EXPECT_TRUE(QuicSessionPeer::IsStreamAvailable(&session_, 5)); 351 EXPECT_TRUE(QuicSessionPeer::IsStreamAvailable(&session_, 5));
326 EXPECT_TRUE(QuicSessionPeer::IsStreamAvailable(&session_, 7)); 352 EXPECT_TRUE(QuicSessionPeer::IsStreamAvailable(&session_, 7));
327 ASSERT_TRUE(session_.GetOrCreateDynamicStream(7) != nullptr); 353 ASSERT_TRUE(session_.GetOrCreateDynamicStream(7) != nullptr);
328 ASSERT_TRUE(session_.GetOrCreateDynamicStream(5) != nullptr); 354 ASSERT_TRUE(session_.GetOrCreateDynamicStream(5) != nullptr);
329 } 355 }
330 356
331 TEST_P(QuicSessionTestServer, IsClosedStreamLocallyCreated) { 357 TEST_P(QuicSessionTestServer, IsClosedStreamLocallyCreated) {
332 TestStream* stream2 = session_.CreateOutgoingDynamicStream(kDefaultPriority); 358 TestStream* stream2 = session_.CreateOutgoingDynamicStream(kDefaultPriority);
333 EXPECT_EQ(2u, stream2->id()); 359 EXPECT_EQ(GetNthServerInitiatedId(0), stream2->id());
334 TestStream* stream4 = session_.CreateOutgoingDynamicStream(kDefaultPriority); 360 QuicSpdyStream* stream4 =
335 EXPECT_EQ(4u, stream4->id()); 361 session_.CreateOutgoingDynamicStream(kDefaultPriority);
362 EXPECT_EQ(GetNthServerInitiatedId(1), stream4->id());
336 363
337 CheckClosedStreams(); 364 CheckClosedStreams();
338 CloseStream(4); 365 CloseStream(GetNthServerInitiatedId(0));
339 CheckClosedStreams(); 366 CheckClosedStreams();
340 CloseStream(2); 367 CloseStream(GetNthServerInitiatedId(1));
341 CheckClosedStreams(); 368 CheckClosedStreams();
342 } 369 }
343 370
344 TEST_P(QuicSessionTestServer, IsClosedStreamPeerCreated) { 371 TEST_P(QuicSessionTestServer, IsClosedStreamPeerCreated) {
345 QuicStreamId stream_id1 = kClientDataStreamId1; 372 QuicStreamId stream_id1 = GetNthClientInitiatedId(0);
346 QuicStreamId stream_id2 = kClientDataStreamId2; 373 QuicStreamId stream_id2 = GetNthClientInitiatedId(1);
347 session_.GetOrCreateDynamicStream(stream_id1); 374 session_.GetOrCreateDynamicStream(stream_id1);
348 session_.GetOrCreateDynamicStream(stream_id2); 375 session_.GetOrCreateDynamicStream(stream_id2);
349 376
350 CheckClosedStreams(); 377 CheckClosedStreams();
351 CloseStream(stream_id1); 378 CloseStream(stream_id1);
352 CheckClosedStreams(); 379 CheckClosedStreams();
353 CloseStream(stream_id2); 380 CloseStream(stream_id2);
354 // Create a stream, and make another available. 381 // Create a stream, and make another available.
355 QuicStream* stream3 = session_.GetOrCreateDynamicStream(stream_id2 + 4); 382 QuicStream* stream3 = session_.GetOrCreateDynamicStream(stream_id2 + 4);
356 CheckClosedStreams(); 383 CheckClosedStreams();
357 // Close one, but make sure the other is still not closed 384 // Close one, but make sure the other is still not closed
358 CloseStream(stream3->id()); 385 CloseStream(stream3->id());
359 CheckClosedStreams(); 386 CheckClosedStreams();
360 } 387 }
361 388
362 TEST_P(QuicSessionTestServer, MaximumAvailableOpenedStreams) { 389 TEST_P(QuicSessionTestServer, MaximumAvailableOpenedStreams) {
363 QuicStreamId stream_id = kClientDataStreamId1; 390 QuicStreamId stream_id = GetNthClientInitiatedId(0);
364 session_.GetOrCreateDynamicStream(stream_id); 391 session_.GetOrCreateDynamicStream(stream_id);
365 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); 392 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0);
366 EXPECT_NE(nullptr, 393 EXPECT_NE(nullptr,
367 session_.GetOrCreateDynamicStream( 394 session_.GetOrCreateDynamicStream(
368 stream_id + 2 * (session_.max_open_incoming_streams() - 1))); 395 stream_id + 2 * (session_.max_open_incoming_streams() - 1)));
369 } 396 }
370 397
371 TEST_P(QuicSessionTestServer, TooManyAvailableStreams) { 398 TEST_P(QuicSessionTestServer, TooManyAvailableStreams) {
372 QuicStreamId stream_id1 = kClientDataStreamId1; 399 QuicStreamId stream_id1 = GetNthClientInitiatedId(0);
373 QuicStreamId stream_id2; 400 QuicStreamId stream_id2;
374 EXPECT_NE(nullptr, session_.GetOrCreateDynamicStream(stream_id1)); 401 EXPECT_NE(nullptr, session_.GetOrCreateDynamicStream(stream_id1));
375 // A stream ID which is too large to create. 402 // A stream ID which is too large to create.
376 stream_id2 = stream_id1 + 2 * session_.MaxAvailableStreams() + 4; 403 stream_id2 = GetNthClientInitiatedId(2 * session_.MaxAvailableStreams() + 4);
377 EXPECT_CALL(*connection_, 404 EXPECT_CALL(*connection_,
378 CloseConnection(QUIC_TOO_MANY_AVAILABLE_STREAMS, _, _)); 405 CloseConnection(QUIC_TOO_MANY_AVAILABLE_STREAMS, _, _));
379 EXPECT_EQ(nullptr, session_.GetOrCreateDynamicStream(stream_id2)); 406 EXPECT_EQ(nullptr, session_.GetOrCreateDynamicStream(stream_id2));
380 } 407 }
381 408
382 TEST_P(QuicSessionTestServer, ManyAvailableStreams) { 409 TEST_P(QuicSessionTestServer, ManyAvailableStreams) {
383 // When max_open_streams_ is 200, should be able to create 200 streams 410 // When max_open_streams_ is 200, should be able to create 200 streams
384 // out-of-order, that is, creating the one with the largest stream ID first. 411 // out-of-order, that is, creating the one with the largest stream ID first.
385 QuicSessionPeer::SetMaxOpenIncomingStreams(&session_, 200); 412 QuicSessionPeer::SetMaxOpenIncomingStreams(&session_, 200);
386 QuicStreamId stream_id = kClientDataStreamId1; 413 QuicStreamId stream_id = GetNthClientInitiatedId(0);
387 // Create one stream. 414 // Create one stream.
388 session_.GetOrCreateDynamicStream(stream_id); 415 session_.GetOrCreateDynamicStream(stream_id);
389 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); 416 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0);
390 // Create the largest stream ID of a threatened total of 200 streams. 417 // Create the largest stream ID of a threatened total of 200 streams.
391 session_.GetOrCreateDynamicStream(stream_id + 2 * (200 - 1)); 418 session_.GetOrCreateDynamicStream(stream_id + 2 * (200 - 1));
392 } 419 }
393 420
394 TEST_P(QuicSessionTestServer, DebugDFatalIfMarkingClosedStreamWriteBlocked) { 421 TEST_P(QuicSessionTestServer, DebugDFatalIfMarkingClosedStreamWriteBlocked) {
395 TestStream* stream2 = session_.CreateOutgoingDynamicStream(kDefaultPriority); 422 TestStream* stream2 = session_.CreateOutgoingDynamicStream(kDefaultPriority);
396 QuicStreamId closed_stream_id = stream2->id(); 423 QuicStreamId closed_stream_id = stream2->id();
397 // Close the stream. 424 // Close the stream.
398 EXPECT_CALL(*connection_, SendRstStream(closed_stream_id, _, _)); 425 EXPECT_CALL(*connection_, SendRstStream(closed_stream_id, _, _));
399 stream2->Reset(QUIC_BAD_APPLICATION_PAYLOAD); 426 stream2->Reset(QUIC_BAD_APPLICATION_PAYLOAD);
427 string msg =
428 QuicStrCat("Marking unknown stream ", closed_stream_id, " blocked.");
400 EXPECT_QUIC_BUG(session_.MarkConnectionLevelWriteBlocked(closed_stream_id), 429 EXPECT_QUIC_BUG(session_.MarkConnectionLevelWriteBlocked(closed_stream_id),
401 "Marking unknown stream 2 blocked."); 430 msg);
402 } 431 }
403 432
404 TEST_P(QuicSessionTestServer, OnCanWrite) { 433 TEST_P(QuicSessionTestServer, OnCanWrite) {
405 session_.set_writev_consumes_all_data(true); 434 session_.set_writev_consumes_all_data(true);
406 TestStream* stream2 = session_.CreateOutgoingDynamicStream(kDefaultPriority); 435 TestStream* stream2 = session_.CreateOutgoingDynamicStream(kDefaultPriority);
407 TestStream* stream4 = session_.CreateOutgoingDynamicStream(kDefaultPriority); 436 TestStream* stream4 = session_.CreateOutgoingDynamicStream(kDefaultPriority);
408 TestStream* stream6 = session_.CreateOutgoingDynamicStream(kDefaultPriority); 437 TestStream* stream6 = session_.CreateOutgoingDynamicStream(kDefaultPriority);
409 438
410 session_.MarkConnectionLevelWriteBlocked(stream2->id()); 439 session_.MarkConnectionLevelWriteBlocked(stream2->id());
411 session_.MarkConnectionLevelWriteBlocked(stream6->id()); 440 session_.MarkConnectionLevelWriteBlocked(stream6->id());
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 EXPECT_EQ(kInitialIdleTimeoutSecs + 3, 822 EXPECT_EQ(kInitialIdleTimeoutSecs + 3,
794 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); 823 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds());
795 CryptoHandshakeMessage msg; 824 CryptoHandshakeMessage msg;
796 session_.GetMutableCryptoStream()->OnHandshakeMessage(msg); 825 session_.GetMutableCryptoStream()->OnHandshakeMessage(msg);
797 EXPECT_EQ(kMaximumIdleTimeoutSecs + 3, 826 EXPECT_EQ(kMaximumIdleTimeoutSecs + 3,
798 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); 827 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds());
799 } 828 }
800 829
801 TEST_P(QuicSessionTestServer, RstStreamBeforeHeadersDecompressed) { 830 TEST_P(QuicSessionTestServer, RstStreamBeforeHeadersDecompressed) {
802 // Send two bytes of payload. 831 // Send two bytes of payload.
803 QuicStreamFrame data1(kClientDataStreamId1, false, 0, QuicStringPiece("HT")); 832 QuicStreamFrame data1(GetNthClientInitiatedId(0), false, 0,
833 QuicStringPiece("HT"));
804 session_.OnStreamFrame(data1); 834 session_.OnStreamFrame(data1);
805 EXPECT_EQ(1u, session_.GetNumOpenIncomingStreams()); 835 EXPECT_EQ(1u, session_.GetNumOpenIncomingStreams());
806 836
807 EXPECT_CALL(*connection_, SendRstStream(kClientDataStreamId1, _, _)); 837 EXPECT_CALL(*connection_, SendRstStream(GetNthClientInitiatedId(0), _, _));
808 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, 838 QuicRstStreamFrame rst1(GetNthClientInitiatedId(0),
809 0); 839 QUIC_ERROR_PROCESSING_STREAM, 0);
810 session_.OnRstStream(rst1); 840 session_.OnRstStream(rst1);
811 EXPECT_EQ(0u, session_.GetNumOpenIncomingStreams()); 841 EXPECT_EQ(0u, session_.GetNumOpenIncomingStreams());
812 // Connection should remain alive. 842 // Connection should remain alive.
813 EXPECT_TRUE(connection_->connected()); 843 EXPECT_TRUE(connection_->connected());
814 } 844 }
815 845
816 TEST_P(QuicSessionTestServer, HandshakeUnblocksFlowControlBlockedStream) { 846 TEST_P(QuicSessionTestServer, HandshakeUnblocksFlowControlBlockedStream) {
817 // Test that if a stream is flow control blocked, then on receipt of the SHLO 847 // Test that if a stream is flow control blocked, then on receipt of the SHLO
818 // containing a suitable send window offset, the stream becomes unblocked. 848 // containing a suitable send window offset, the stream becomes unblocked.
819 849
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked()); 1178 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
1149 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); 1179 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
1150 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); 1180 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
1151 } 1181 }
1152 1182
1153 TEST_P(QuicSessionTestServer, TooManyUnfinishedStreamsCauseServerRejectStream) { 1183 TEST_P(QuicSessionTestServer, TooManyUnfinishedStreamsCauseServerRejectStream) {
1154 // If a buggy/malicious peer creates too many streams that are not ended 1184 // If a buggy/malicious peer creates too many streams that are not ended
1155 // with a FIN or RST then we send an RST to refuse streams. 1185 // with a FIN or RST then we send an RST to refuse streams.
1156 const QuicStreamId kMaxStreams = 5; 1186 const QuicStreamId kMaxStreams = 5;
1157 QuicSessionPeer::SetMaxOpenIncomingStreams(&session_, kMaxStreams); 1187 QuicSessionPeer::SetMaxOpenIncomingStreams(&session_, kMaxStreams);
1158 const QuicStreamId kFirstStreamId = kClientDataStreamId1; 1188 const QuicStreamId kFirstStreamId = GetNthClientInitiatedId(0);
1159 const QuicStreamId kFinalStreamId = kClientDataStreamId1 + 2 * kMaxStreams; 1189 const QuicStreamId kFinalStreamId = GetNthClientInitiatedId(kMaxStreams);
1160
1161 // Create kMaxStreams data streams, and close them all without receiving a 1190 // Create kMaxStreams data streams, and close them all without receiving a
1162 // FIN or a RST_STREAM from the client. 1191 // FIN or a RST_STREAM from the client.
1163 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) { 1192 const QuicStreamId kNextId = QuicSpdySessionPeer::NextStreamId(session_);
1193 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += kNextId) {
1164 QuicStreamFrame data1(i, false, 0, QuicStringPiece("HT")); 1194 QuicStreamFrame data1(i, false, 0, QuicStringPiece("HT"));
1165 session_.OnStreamFrame(data1); 1195 session_.OnStreamFrame(data1);
1166 // EXPECT_EQ(1u, session_.GetNumOpenStreams()); 1196 // EXPECT_EQ(1u, session_.GetNumOpenStreams());
1167 EXPECT_CALL(*connection_, SendRstStream(i, _, _)); 1197 EXPECT_CALL(*connection_, SendRstStream(i, _, _));
1168 session_.CloseStream(i); 1198 session_.CloseStream(i);
1169 } 1199 }
1170 1200
1171 EXPECT_CALL(*connection_, 1201 EXPECT_CALL(*connection_,
1172 SendRstStream(kFinalStreamId, QUIC_REFUSED_STREAM, _)) 1202 SendRstStream(kFinalStreamId, QUIC_REFUSED_STREAM, _))
1173 .Times(1); 1203 .Times(1);
1174 // Create one more data streams to exceed limit of open stream. 1204 // Create one more data streams to exceed limit of open stream.
1175 QuicStreamFrame data1(kFinalStreamId, false, 0, QuicStringPiece("HT")); 1205 QuicStreamFrame data1(kFinalStreamId, false, 0, QuicStringPiece("HT"));
1176 session_.OnStreamFrame(data1); 1206 session_.OnStreamFrame(data1);
1177 1207
1178 // Called after any new data is received by the session, and triggers the 1208 // Called after any new data is received by the session, and triggers the
1179 // call to close the connection. 1209 // call to close the connection.
1180 session_.PostProcessAfterData(); 1210 session_.PostProcessAfterData();
1181 } 1211 }
1182 1212
1183 TEST_P(QuicSessionTestServer, DrainingStreamsDoNotCountAsOpened) { 1213 TEST_P(QuicSessionTestServer, DrainingStreamsDoNotCountAsOpened) {
1184 // Verify that a draining stream (which has received a FIN but not consumed 1214 // Verify that a draining stream (which has received a FIN but not consumed
1185 // it) does not count against the open quota (because it is closed from the 1215 // it) does not count against the open quota (because it is closed from the
1186 // protocol point of view). 1216 // protocol point of view).
1187 EXPECT_CALL(*connection_, SendRstStream(_, QUIC_REFUSED_STREAM, _)).Times(0); 1217 EXPECT_CALL(*connection_, SendRstStream(_, QUIC_REFUSED_STREAM, _)).Times(0);
1188 const QuicStreamId kMaxStreams = 5; 1218 const QuicStreamId kMaxStreams = 5;
1189 QuicSessionPeer::SetMaxOpenIncomingStreams(&session_, kMaxStreams); 1219 QuicSessionPeer::SetMaxOpenIncomingStreams(&session_, kMaxStreams);
1190 1220
1191 // Create kMaxStreams + 1 data streams, and mark them draining. 1221 // Create kMaxStreams + 1 data streams, and mark them draining.
1192 const QuicStreamId kFirstStreamId = kClientDataStreamId1; 1222 const QuicStreamId kFirstStreamId = GetNthClientInitiatedId(0);
1193 const QuicStreamId kFinalStreamId = 1223 const QuicStreamId kFinalStreamId =
1194 kClientDataStreamId1 + 2 * kMaxStreams + 1; 1224 GetNthClientInitiatedId(2 * kMaxStreams + 1);
1195 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += 2) { 1225 for (QuicStreamId i = kFirstStreamId; i < kFinalStreamId; i += NextId()) {
1196 QuicStreamFrame data1(i, true, 0, QuicStringPiece("HT")); 1226 QuicStreamFrame data1(i, true, 0, QuicStringPiece("HT"));
1197 session_.OnStreamFrame(data1); 1227 session_.OnStreamFrame(data1);
1198 EXPECT_EQ(1u, session_.GetNumOpenIncomingStreams()); 1228 EXPECT_EQ(1u, session_.GetNumOpenIncomingStreams());
1199 session_.StreamDraining(i); 1229 session_.StreamDraining(i);
1200 EXPECT_EQ(0u, session_.GetNumOpenIncomingStreams()); 1230 EXPECT_EQ(0u, session_.GetNumOpenIncomingStreams());
1201 } 1231 }
1202 1232
1203 // Called after any new data is received by the session, and triggers the call 1233 // Called after any new data is received by the session, and triggers the call
1204 // to close the connection. 1234 // to close the connection.
1205 session_.PostProcessAfterData(); 1235 session_.PostProcessAfterData();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 if (version() != QUIC_VERSION_36) { 1342 if (version() != QUIC_VERSION_36) {
1313 EXPECT_FALSE(session_.force_hol_blocking()); 1343 EXPECT_FALSE(session_.force_hol_blocking());
1314 } else { 1344 } else {
1315 EXPECT_TRUE(session_.force_hol_blocking()); 1345 EXPECT_TRUE(session_.force_hol_blocking());
1316 } 1346 }
1317 } 1347 }
1318 1348
1319 } // namespace 1349 } // namespace
1320 } // namespace test 1350 } // namespace test
1321 } // namespace net 1351 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_session.cc ('k') | net/quic/core/quic_spdy_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698