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

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

Issue 1781043004: Remove the force param from QuicPacketGenerator::SetMaxPacketLength because path MTU packets should… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@116272960
Patch Set: Created 4 years, 9 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_packet_generator.cc ('k') | 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 "net/quic/quic_packet_generator.h" 5 #include "net/quic/quic_packet_generator.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "net/quic/crypto/crypto_protocol.h" 10 #include "net/quic/crypto/crypto_protocol.h"
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 // but not enough for a stream frame of 0 offset and one with non-zero offset. 442 // but not enough for a stream frame of 0 offset and one with non-zero offset.
443 size_t length = 443 size_t length =
444 NullEncrypter().GetCiphertextSize(0) + 444 NullEncrypter().GetCiphertextSize(0) +
445 GetPacketHeaderSize( 445 GetPacketHeaderSize(
446 creator_->connection_id_length(), kIncludeVersion, !kIncludePathId, 446 creator_->connection_id_length(), kIncludeVersion, !kIncludePathId,
447 QuicPacketCreatorPeer::NextPacketNumberLength(creator_)) + 447 QuicPacketCreatorPeer::NextPacketNumberLength(creator_)) +
448 // Add an extra 3 bytes for the payload and 1 byte so BytesFree is larger 448 // Add an extra 3 bytes for the payload and 1 byte so BytesFree is larger
449 // than the GetMinStreamFrameSize. 449 // than the GetMinStreamFrameSize.
450 QuicFramer::GetMinStreamFrameSize(1, 0, false) + 3 + 450 QuicFramer::GetMinStreamFrameSize(1, 0, false) + 3 +
451 QuicFramer::GetMinStreamFrameSize(1, 0, true) + 1; 451 QuicFramer::GetMinStreamFrameSize(1, 0, true) + 1;
452 generator_.SetMaxPacketLength(length, /*force=*/false); 452 generator_.SetMaxPacketLength(length);
453 delegate_.SetCanWriteAnything(); 453 delegate_.SetCanWriteAnything();
454 { 454 {
455 InSequence dummy; 455 InSequence dummy;
456 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 456 EXPECT_CALL(delegate_, OnSerializedPacket(_))
457 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 457 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
458 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 458 EXPECT_CALL(delegate_, OnSerializedPacket(_))
459 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 459 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
460 } 460 }
461 generator_.StartBatchOperations(); 461 generator_.StartBatchOperations();
462 // Queue enough data to prevent a stream frame with a non-zero offset from 462 // Queue enough data to prevent a stream frame with a non-zero offset from
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 589
590 // Test whether SetMaxPacketLength() works in the situation when the queue is 590 // Test whether SetMaxPacketLength() works in the situation when the queue is
591 // empty, and we send three packets worth of data. 591 // empty, and we send three packets worth of data.
592 TEST_F(QuicPacketGeneratorTest, SetMaxPacketLength_Initial) { 592 TEST_F(QuicPacketGeneratorTest, SetMaxPacketLength_Initial) {
593 delegate_.SetCanWriteAnything(); 593 delegate_.SetCanWriteAnything();
594 594
595 // Send enough data for three packets. 595 // Send enough data for three packets.
596 size_t data_len = 3 * kDefaultMaxPacketSize + 1; 596 size_t data_len = 3 * kDefaultMaxPacketSize + 1;
597 size_t packet_len = kDefaultMaxPacketSize + 100; 597 size_t packet_len = kDefaultMaxPacketSize + 100;
598 ASSERT_LE(packet_len, kMaxPacketSize); 598 ASSERT_LE(packet_len, kMaxPacketSize);
599 generator_.SetMaxPacketLength(packet_len, /*force=*/false); 599 generator_.SetMaxPacketLength(packet_len);
600 EXPECT_EQ(packet_len, generator_.GetCurrentMaxPacketLength()); 600 EXPECT_EQ(packet_len, generator_.GetCurrentMaxPacketLength());
601 601
602 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 602 EXPECT_CALL(delegate_, OnSerializedPacket(_))
603 .Times(3) 603 .Times(3)
604 .WillRepeatedly(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 604 .WillRepeatedly(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
605 QuicConsumedData consumed = 605 QuicConsumedData consumed =
606 generator_.ConsumeData(kHeadersStreamId, CreateData(data_len), 606 generator_.ConsumeData(kHeadersStreamId, CreateData(data_len),
607 /*offset=*/2, 607 /*offset=*/2,
608 /*fin=*/true, nullptr); 608 /*fin=*/true, nullptr);
609 EXPECT_EQ(data_len, consumed.bytes_consumed); 609 EXPECT_EQ(data_len, consumed.bytes_consumed);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 /*offset=*/2, 642 /*offset=*/2,
643 /*fin=*/false, nullptr); 643 /*fin=*/false, nullptr);
644 EXPECT_EQ(data_len, consumed.bytes_consumed); 644 EXPECT_EQ(data_len, consumed.bytes_consumed);
645 EXPECT_FALSE(consumed.fin_consumed); 645 EXPECT_FALSE(consumed.fin_consumed);
646 EXPECT_FALSE(generator_.HasQueuedFrames()); 646 EXPECT_FALSE(generator_.HasQueuedFrames());
647 647
648 // Make sure we already have two packets. 648 // Make sure we already have two packets.
649 ASSERT_EQ(2u, packets_.size()); 649 ASSERT_EQ(2u, packets_.size());
650 650
651 // Increase packet size. 651 // Increase packet size.
652 generator_.SetMaxPacketLength(packet_len, /*force=*/false); 652 generator_.SetMaxPacketLength(packet_len);
653 EXPECT_EQ(packet_len, generator_.GetCurrentMaxPacketLength()); 653 EXPECT_EQ(packet_len, generator_.GetCurrentMaxPacketLength());
654 654
655 // Send a packet after packet size change. 655 // Send a packet after packet size change.
656 consumed = generator_.ConsumeData(kHeadersStreamId, CreateData(data_len), 656 consumed = generator_.ConsumeData(kHeadersStreamId, CreateData(data_len),
657 2 + data_len, 657 2 + data_len,
658 /*fin=*/true, nullptr); 658 /*fin=*/true, nullptr);
659 EXPECT_EQ(data_len, consumed.bytes_consumed); 659 EXPECT_EQ(data_len, consumed.bytes_consumed);
660 EXPECT_TRUE(consumed.fin_consumed); 660 EXPECT_TRUE(consumed.fin_consumed);
661 EXPECT_FALSE(generator_.HasQueuedFrames()); 661 EXPECT_FALSE(generator_.HasQueuedFrames());
662 662
(...skipping 23 matching lines...) Expand all
686 /*offset=*/2, 686 /*offset=*/2,
687 /*fin=*/false, nullptr); 687 /*fin=*/false, nullptr);
688 EXPECT_EQ(first_write_len, consumed.bytes_consumed); 688 EXPECT_EQ(first_write_len, consumed.bytes_consumed);
689 EXPECT_FALSE(consumed.fin_consumed); 689 EXPECT_FALSE(consumed.fin_consumed);
690 EXPECT_TRUE(generator_.HasQueuedFrames()); 690 EXPECT_TRUE(generator_.HasQueuedFrames());
691 691
692 // Make sure we have no packets so far. 692 // Make sure we have no packets so far.
693 ASSERT_EQ(0u, packets_.size()); 693 ASSERT_EQ(0u, packets_.size());
694 694
695 // Increase packet size. Ensure it's not immediately enacted. 695 // Increase packet size. Ensure it's not immediately enacted.
696 generator_.SetMaxPacketLength(packet_len, /*force=*/false); 696 generator_.SetMaxPacketLength(packet_len);
697 EXPECT_EQ(packet_len, generator_.GetMaxPacketLength()); 697 EXPECT_EQ(packet_len, generator_.GetMaxPacketLength());
698 EXPECT_EQ(kDefaultMaxPacketSize, generator_.GetCurrentMaxPacketLength()); 698 EXPECT_EQ(kDefaultMaxPacketSize, generator_.GetCurrentMaxPacketLength());
699 699
700 // We expect to see exactly one packet serialized after that, since we are in 700 // We expect to see exactly one packet serialized after that, since we are in
701 // batch mode and we have sent approximately 3/2 of our MTU. 701 // batch mode and we have sent approximately 3/2 of our MTU.
702 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 702 EXPECT_CALL(delegate_, OnSerializedPacket(_))
703 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 703 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
704 704
705 // Send a packet worth of data to the same stream. This should trigger 705 // Send a packet worth of data to the same stream. This should trigger
706 // serialization of other packet. 706 // serialization of other packet.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 EXPECT_FALSE(consumed.fin_consumed); 743 EXPECT_FALSE(consumed.fin_consumed);
744 EXPECT_TRUE(generator_.HasQueuedFrames()); 744 EXPECT_TRUE(generator_.HasQueuedFrames());
745 745
746 // Make sure we have no packets so far. 746 // Make sure we have no packets so far.
747 ASSERT_EQ(0u, packets_.size()); 747 ASSERT_EQ(0u, packets_.size());
748 748
749 // Expect a packet to be flushed. 749 // Expect a packet to be flushed.
750 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 750 EXPECT_CALL(delegate_, OnSerializedPacket(_))
751 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 751 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
752 752
753 // Increase packet size. Ensure it's immediately enacted. 753 // Increase packet size after flushing all frames.
754 generator_.SetMaxPacketLength(packet_len, /*force=*/true); 754 // Ensure it's immediately enacted.
755 generator_.FlushAllQueuedFrames();
756 generator_.SetMaxPacketLength(packet_len);
755 EXPECT_EQ(packet_len, generator_.GetMaxPacketLength()); 757 EXPECT_EQ(packet_len, generator_.GetMaxPacketLength());
756 EXPECT_EQ(packet_len, generator_.GetCurrentMaxPacketLength()); 758 EXPECT_EQ(packet_len, generator_.GetCurrentMaxPacketLength());
757 EXPECT_FALSE(generator_.HasQueuedFrames()); 759 EXPECT_FALSE(generator_.HasQueuedFrames());
758 760
759 // We expect to see exactly one packet serialized after that, because we send 761 // We expect to see exactly one packet serialized after that, because we send
760 // a value somewhat exceeding new max packet size, and the tail data does not 762 // a value somewhat exceeding new max packet size, and the tail data does not
761 // get serialized because we are still in the batch mode. 763 // get serialized because we are still in the batch mode.
762 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 764 EXPECT_CALL(delegate_, OnSerializedPacket(_))
763 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 765 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
764 766
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 911 EXPECT_CALL(delegate_, OnSerializedPacket(_))
910 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 912 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
911 generator_.FlushAllQueuedFrames(); 913 generator_.FlushAllQueuedFrames();
912 EXPECT_FALSE(generator_.HasQueuedFrames()); 914 EXPECT_FALSE(generator_.HasQueuedFrames());
913 generator_.SetCurrentPath(kTestPathId1, 1, 0); 915 generator_.SetCurrentPath(kTestPathId1, 1, 0);
914 EXPECT_EQ(kTestPathId1, QuicPacketCreatorPeer::GetCurrentPath(creator_)); 916 EXPECT_EQ(kTestPathId1, QuicPacketCreatorPeer::GetCurrentPath(creator_));
915 } 917 }
916 918
917 } // namespace test 919 } // namespace test
918 } // namespace net 920 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_packet_generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698