| OLD | NEW |
| 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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 | 434 |
| 435 StreamBlocker stream2_blocker(&session_, stream2->id()); | 435 StreamBlocker stream2_blocker(&session_, stream2->id()); |
| 436 StreamBlocker stream4_blocker(&session_, stream4->id()); | 436 StreamBlocker stream4_blocker(&session_, stream4->id()); |
| 437 StreamBlocker stream6_blocker(&session_, stream6->id()); | 437 StreamBlocker stream6_blocker(&session_, stream6->id()); |
| 438 // With two sessions blocked, we should get two write calls. They should both | 438 // With two sessions blocked, we should get two write calls. They should both |
| 439 // go to the first stream as it will only write 6k and mark itself blocked | 439 // go to the first stream as it will only write 6k and mark itself blocked |
| 440 // again. | 440 // again. |
| 441 InSequence s; | 441 InSequence s; |
| 442 EXPECT_CALL(*stream2, OnCanWrite()) | 442 EXPECT_CALL(*stream2, OnCanWrite()) |
| 443 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( | 443 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( |
| 444 &session_, &TestSession::SendLargeFakeData, | 444 &TestSession::SendLargeFakeData, |
| 445 base::Unretained(&session_), |
| 445 stream2->id(), 6000))), | 446 stream2->id(), 6000))), |
| 446 Invoke(&stream2_blocker, | 447 Invoke(&stream2_blocker, |
| 447 &StreamBlocker::MarkConnectionLevelWriteBlocked))); | 448 &StreamBlocker::MarkConnectionLevelWriteBlocked))); |
| 448 EXPECT_CALL(*stream2, OnCanWrite()) | 449 EXPECT_CALL(*stream2, OnCanWrite()) |
| 449 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( | 450 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( |
| 450 &session_, &TestSession::SendLargeFakeData, | 451 &TestSession::SendLargeFakeData, |
| 452 base::Unretained(&session_), |
| 451 stream2->id(), 6000))), | 453 stream2->id(), 6000))), |
| 452 Invoke(&stream2_blocker, | 454 Invoke(&stream2_blocker, |
| 453 &StreamBlocker::MarkConnectionLevelWriteBlocked))); | 455 &StreamBlocker::MarkConnectionLevelWriteBlocked))); |
| 454 session_.OnCanWrite(); | 456 session_.OnCanWrite(); |
| 455 | 457 |
| 456 // We should get one more call for stream2, at which point it has used its | 458 // We should get one more call for stream2, at which point it has used its |
| 457 // write quota and we move over to stream 4. | 459 // write quota and we move over to stream 4. |
| 458 EXPECT_CALL(*stream2, OnCanWrite()) | 460 EXPECT_CALL(*stream2, OnCanWrite()) |
| 459 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( | 461 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( |
| 460 &session_, &TestSession::SendLargeFakeData, | 462 &TestSession::SendLargeFakeData, |
| 463 base::Unretained(&session_), |
| 461 stream2->id(), 6000))), | 464 stream2->id(), 6000))), |
| 462 Invoke(&stream2_blocker, | 465 Invoke(&stream2_blocker, |
| 463 &StreamBlocker::MarkConnectionLevelWriteBlocked))); | 466 &StreamBlocker::MarkConnectionLevelWriteBlocked))); |
| 464 EXPECT_CALL(*stream4, OnCanWrite()) | 467 EXPECT_CALL(*stream4, OnCanWrite()) |
| 465 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( | 468 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( |
| 466 &session_, &TestSession::SendLargeFakeData, | 469 &TestSession::SendLargeFakeData, |
| 470 base::Unretained(&session_), |
| 467 stream4->id(), 6000))), | 471 stream4->id(), 6000))), |
| 468 Invoke(&stream4_blocker, | 472 Invoke(&stream4_blocker, |
| 469 &StreamBlocker::MarkConnectionLevelWriteBlocked))); | 473 &StreamBlocker::MarkConnectionLevelWriteBlocked))); |
| 470 session_.OnCanWrite(); | 474 session_.OnCanWrite(); |
| 471 | 475 |
| 472 // Now let stream 4 do the 2nd of its 3 writes, but add a block for a high | 476 // Now let stream 4 do the 2nd of its 3 writes, but add a block for a high |
| 473 // priority stream 6. 4 should be preempted. 6 will write but *not* block so | 477 // priority stream 6. 4 should be preempted. 6 will write but *not* block so |
| 474 // will cede back to 4. | 478 // will cede back to 4. |
| 475 stream6->SetPriority(kHighestPriority); | 479 stream6->SetPriority(kHighestPriority); |
| 476 EXPECT_CALL(*stream4, OnCanWrite()) | 480 EXPECT_CALL(*stream4, OnCanWrite()) |
| 477 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( | 481 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( |
| 478 &session_, &TestSession::SendLargeFakeData, | 482 &TestSession::SendLargeFakeData, |
| 483 base::Unretained(&session_), |
| 479 stream4->id(), 6000))), | 484 stream4->id(), 6000))), |
| 480 Invoke(&stream4_blocker, | 485 Invoke(&stream4_blocker, |
| 481 &StreamBlocker::MarkConnectionLevelWriteBlocked), | 486 &StreamBlocker::MarkConnectionLevelWriteBlocked), |
| 482 Invoke(&stream6_blocker, | 487 Invoke(&stream6_blocker, |
| 483 &StreamBlocker::MarkHighPriorityWriteBlocked))); | 488 &StreamBlocker::MarkHighPriorityWriteBlocked))); |
| 484 EXPECT_CALL(*stream6, OnCanWrite()) | 489 EXPECT_CALL(*stream6, OnCanWrite()) |
| 485 .WillOnce(testing::IgnoreResult(Invoke(CreateFunctor( | 490 .WillOnce(testing::IgnoreResult(Invoke(CreateFunctor( |
| 486 &session_, &TestSession::SendLargeFakeData, stream4->id(), 6000)))); | 491 &TestSession::SendLargeFakeData, |
| 492 base::Unretained(&session_), stream4->id(), 6000)))); |
| 487 session_.OnCanWrite(); | 493 session_.OnCanWrite(); |
| 488 | 494 |
| 489 // Stream4 alread did 6k worth of writes, so after doing another 12k it should | 495 // Stream4 alread did 6k worth of writes, so after doing another 12k it should |
| 490 // cede and 2 should resume. | 496 // cede and 2 should resume. |
| 491 EXPECT_CALL(*stream4, OnCanWrite()) | 497 EXPECT_CALL(*stream4, OnCanWrite()) |
| 492 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( | 498 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( |
| 493 &session_, &TestSession::SendLargeFakeData, | 499 &TestSession::SendLargeFakeData, |
| 500 base::Unretained(&session_), |
| 494 stream4->id(), 12000))), | 501 stream4->id(), 12000))), |
| 495 Invoke(&stream4_blocker, | 502 Invoke(&stream4_blocker, |
| 496 &StreamBlocker::MarkConnectionLevelWriteBlocked))); | 503 &StreamBlocker::MarkConnectionLevelWriteBlocked))); |
| 497 EXPECT_CALL(*stream2, OnCanWrite()) | 504 EXPECT_CALL(*stream2, OnCanWrite()) |
| 498 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( | 505 .WillOnce(DoAll(testing::IgnoreResult(Invoke(CreateFunctor( |
| 499 &session_, &TestSession::SendLargeFakeData, | 506 &TestSession::SendLargeFakeData, |
| 507 base::Unretained(&session_), |
| 500 stream2->id(), 6000))), | 508 stream2->id(), 6000))), |
| 501 Invoke(&stream2_blocker, | 509 Invoke(&stream2_blocker, |
| 502 &StreamBlocker::MarkConnectionLevelWriteBlocked))); | 510 &StreamBlocker::MarkConnectionLevelWriteBlocked))); |
| 503 session_.OnCanWrite(); | 511 session_.OnCanWrite(); |
| 504 } | 512 } |
| 505 | 513 |
| 506 TEST_P(QuicSessionTestServer, OnCanWriteBundlesStreams) { | 514 TEST_P(QuicSessionTestServer, OnCanWriteBundlesStreams) { |
| 507 // Encryption needs to be established before data can be sent. | 515 // Encryption needs to be established before data can be sent. |
| 508 CryptoHandshakeMessage msg; | 516 CryptoHandshakeMessage msg; |
| 509 session_.GetCryptoStream()->OnHandshakeMessage(msg); | 517 session_.GetCryptoStream()->OnHandshakeMessage(msg); |
| 510 | 518 |
| 511 // Drive congestion control manually. | 519 // Drive congestion control manually. |
| 512 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; | 520 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; |
| 513 QuicConnectionPeer::SetSendAlgorithm(session_.connection(), send_algorithm); | 521 QuicConnectionPeer::SetSendAlgorithm(session_.connection(), send_algorithm); |
| 514 | 522 |
| 515 TestStream* stream2 = session_.CreateOutgoingDynamicStream(kDefaultPriority); | 523 TestStream* stream2 = session_.CreateOutgoingDynamicStream(kDefaultPriority); |
| 516 TestStream* stream4 = session_.CreateOutgoingDynamicStream(kDefaultPriority); | 524 TestStream* stream4 = session_.CreateOutgoingDynamicStream(kDefaultPriority); |
| 517 TestStream* stream6 = session_.CreateOutgoingDynamicStream(kDefaultPriority); | 525 TestStream* stream6 = session_.CreateOutgoingDynamicStream(kDefaultPriority); |
| 518 | 526 |
| 519 session_.MarkConnectionLevelWriteBlocked(stream2->id(), kDefaultPriority); | 527 session_.MarkConnectionLevelWriteBlocked(stream2->id(), kDefaultPriority); |
| 520 session_.MarkConnectionLevelWriteBlocked(stream6->id(), kDefaultPriority); | 528 session_.MarkConnectionLevelWriteBlocked(stream6->id(), kDefaultPriority); |
| 521 session_.MarkConnectionLevelWriteBlocked(stream4->id(), kDefaultPriority); | 529 session_.MarkConnectionLevelWriteBlocked(stream4->id(), kDefaultPriority); |
| 522 | 530 |
| 523 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _)) | 531 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _)) |
| 524 .WillRepeatedly(Return(QuicTime::Delta::Zero())); | 532 .WillRepeatedly(Return(QuicTime::Delta::Zero())); |
| 525 EXPECT_CALL(*send_algorithm, GetCongestionWindow()) | 533 EXPECT_CALL(*send_algorithm, GetCongestionWindow()) |
| 526 .WillRepeatedly(Return(kMaxPacketSize * 10)); | 534 .WillRepeatedly(Return(kMaxPacketSize * 10)); |
| 527 EXPECT_CALL(*stream2, OnCanWrite()) | 535 EXPECT_CALL(*stream2, OnCanWrite()) |
| 528 .WillOnce(testing::IgnoreResult(Invoke(CreateFunctor( | 536 .WillOnce(testing::IgnoreResult(Invoke(CreateFunctor( |
| 529 &session_, &TestSession::SendStreamData, stream2->id())))); | 537 &TestSession::SendStreamData, |
| 538 base::Unretained(&session_), stream2->id())))); |
| 530 EXPECT_CALL(*stream4, OnCanWrite()) | 539 EXPECT_CALL(*stream4, OnCanWrite()) |
| 531 .WillOnce(testing::IgnoreResult(Invoke(CreateFunctor( | 540 .WillOnce(testing::IgnoreResult(Invoke(CreateFunctor( |
| 532 &session_, &TestSession::SendStreamData, stream4->id())))); | 541 &TestSession::SendStreamData, |
| 542 base::Unretained(&session_), |
| 543 stream4->id())))); |
| 533 EXPECT_CALL(*stream6, OnCanWrite()) | 544 EXPECT_CALL(*stream6, OnCanWrite()) |
| 534 .WillOnce(testing::IgnoreResult(Invoke(CreateFunctor( | 545 .WillOnce(testing::IgnoreResult(Invoke(CreateFunctor( |
| 535 &session_, &TestSession::SendStreamData, stream6->id())))); | 546 &TestSession::SendStreamData, |
| 547 base::Unretained(&session_), |
| 548 stream6->id())))); |
| 536 | 549 |
| 537 // Expect that we only send one packet, the writes from different streams | 550 // Expect that we only send one packet, the writes from different streams |
| 538 // should be bundled together. | 551 // should be bundled together. |
| 539 MockPacketWriter* writer = static_cast<MockPacketWriter*>( | 552 MockPacketWriter* writer = static_cast<MockPacketWriter*>( |
| 540 QuicConnectionPeer::GetWriter(session_.connection())); | 553 QuicConnectionPeer::GetWriter(session_.connection())); |
| 541 EXPECT_CALL(*writer, WritePacket(_, _, _, _, _)) | 554 EXPECT_CALL(*writer, WritePacket(_, _, _, _, _)) |
| 542 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); | 555 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); |
| 543 EXPECT_CALL(*send_algorithm, OnPacketSent(_, _, _, _, _)); | 556 EXPECT_CALL(*send_algorithm, OnPacketSent(_, _, _, _, _)); |
| 544 session_.OnCanWrite(); | 557 session_.OnCanWrite(); |
| 545 EXPECT_FALSE(session_.WillingAndAbleToWrite()); | 558 EXPECT_FALSE(session_.WillingAndAbleToWrite()); |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 session_.max_open_incoming_streams()); | 1249 session_.max_open_incoming_streams()); |
| 1237 } | 1250 } |
| 1238 | 1251 |
| 1239 EXPECT_EQ(session_.max_open_outgoing_streams(), | 1252 EXPECT_EQ(session_.max_open_outgoing_streams(), |
| 1240 kDefaultMaxStreamsPerConnection); | 1253 kDefaultMaxStreamsPerConnection); |
| 1241 } | 1254 } |
| 1242 | 1255 |
| 1243 } // namespace | 1256 } // namespace |
| 1244 } // namespace test | 1257 } // namespace test |
| 1245 } // namespace net | 1258 } // namespace net |
| OLD | NEW |