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

Unified Diff: net/quic/core/quic_stream_sequencer_buffer_test.cc

Issue 2387753002: Release read buffer of QuicCryptoStream when incoming message become less frequent. Protected by --… (Closed)
Patch Set: enable quic crypto stream release buffer Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/core/quic_stream_sequencer.cc ('k') | net/quic/test_tools/quic_stream_sequencer_buffer_peer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/core/quic_stream_sequencer_buffer_test.cc
diff --git a/net/quic/core/quic_stream_sequencer_buffer_test.cc b/net/quic/core/quic_stream_sequencer_buffer_test.cc
index 944b41a91214d464e66f16cab51705c2a2b65e78..6db66a6da6dfed7630a80bb630d3015802acdbe3 100644
--- a/net/quic/core/quic_stream_sequencer_buffer_test.cc
+++ b/net/quic/core/quic_stream_sequencer_buffer_test.cc
@@ -13,6 +13,7 @@
#include "base/macros.h"
#include "base/rand_util.h"
#include "net/quic/test_tools/mock_clock.h"
+#include "net/quic/test_tools/quic_stream_sequencer_buffer_peer.h"
#include "net/quic/test_tools/quic_test_utils.h"
#include "net/test/gtest_util.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -55,116 +56,6 @@ typedef QuicStreamSequencerBuffer::BufferBlock BufferBlock;
typedef QuicStreamSequencerBuffer::Gap Gap;
typedef QuicStreamSequencerBuffer::FrameInfo FrameInfo;
-class QuicStreamSequencerBufferPeer {
- public:
- explicit QuicStreamSequencerBufferPeer(QuicStreamSequencerBuffer* buffer)
- : buffer_(buffer) {}
-
- // Read from this buffer_ into the given destination buffer_ up to the
- // size of the destination. Returns the number of bytes read. Reading from
- // an empty buffer_->returns 0.
- size_t Read(char* dest_buffer, size_t size) {
- iovec dest;
- dest.iov_base = dest_buffer, dest.iov_len = size;
- size_t bytes_read;
- string error_details;
- EXPECT_EQ(QUIC_NO_ERROR,
- buffer_->Readv(&dest, 1, &bytes_read, &error_details));
- return bytes_read;
- }
-
- // If buffer is empty, the blocks_ array must be empty, which means all
- // blocks are deallocated.
- bool CheckEmptyInvariants() {
- return !buffer_->Empty() || IsBlockArrayEmpty();
- }
-
- bool IsBlockArrayEmpty() {
- if (FLAGS_quic_reduce_sequencer_buffer_memory_life_time && // NOLINT
- buffer_->blocks_ == nullptr) {
- return true;
- }
-
- size_t count = buffer_->blocks_count_;
- for (size_t i = 0; i < count; i++) {
- if (buffer_->blocks_[i] != nullptr) {
- return false;
- }
- }
- return true;
- }
-
- bool CheckInitialState() {
- EXPECT_TRUE(buffer_->Empty() && buffer_->total_bytes_read_ == 0 &&
- buffer_->num_bytes_buffered_ == 0);
- return CheckBufferInvariants();
- }
-
- bool CheckBufferInvariants() {
- QuicStreamOffset data_span =
- buffer_->gaps_.back().begin_offset - buffer_->total_bytes_read_;
- bool capacity_sane = data_span <= buffer_->max_buffer_capacity_bytes_ &&
- data_span >= buffer_->num_bytes_buffered_;
- if (!capacity_sane) {
- LOG(ERROR) << "data span is larger than capacity.";
- LOG(ERROR) << "total read: " << buffer_->total_bytes_read_
- << " last byte: " << buffer_->gaps_.back().begin_offset;
- }
- bool total_read_sane =
- buffer_->gaps_.front().begin_offset >= buffer_->total_bytes_read_;
- if (!total_read_sane) {
- LOG(ERROR) << "read across 1st gap.";
- }
- bool read_offset_sane = buffer_->ReadOffset() < kBlockSizeBytes;
- if (!capacity_sane) {
- LOG(ERROR) << "read offset go beyond 1st block";
- }
- bool block_match_capacity =
- (buffer_->max_buffer_capacity_bytes_ <=
- buffer_->blocks_count_ * kBlockSizeBytes) &&
- (buffer_->max_buffer_capacity_bytes_ >
- (buffer_->blocks_count_ - 1) * kBlockSizeBytes);
- if (!capacity_sane) {
- LOG(ERROR) << "block number not match capcaity.";
- }
- bool block_retired_when_empty = CheckEmptyInvariants();
- if (!block_retired_when_empty) {
- LOG(ERROR) << "block is not retired after use.";
- }
- return capacity_sane && total_read_sane && read_offset_sane &&
- block_match_capacity && block_retired_when_empty;
- }
-
- size_t GetInBlockOffset(QuicStreamOffset offset) {
- return buffer_->GetInBlockOffset(offset);
- }
-
- BufferBlock* GetBlock(size_t index) { return buffer_->blocks_[index]; }
-
- int GapSize() { return buffer_->gaps_.size(); }
-
- std::list<Gap> GetGaps() { return buffer_->gaps_; }
-
- size_t max_buffer_capacity() { return buffer_->max_buffer_capacity_bytes_; }
-
- size_t ReadableBytes() { return buffer_->ReadableBytes(); }
-
- std::map<QuicStreamOffset, FrameInfo>* frame_arrival_time_map() {
- return &(buffer_->frame_arrival_time_map_);
- }
-
- void set_total_bytes_read(QuicStreamOffset total_bytes_read) {
- buffer_->total_bytes_read_ = total_bytes_read;
- }
-
- void set_gaps(const std::list<Gap>& gaps) { buffer_->gaps_ = gaps; }
-
- bool IsBufferAllocated() { return buffer_->blocks_ != nullptr; }
-
- private:
- QuicStreamSequencerBuffer* buffer_;
-};
-
namespace {
class QuicStreamSequencerBufferTest : public testing::Test {
« no previous file with comments | « net/quic/core/quic_stream_sequencer.cc ('k') | net/quic/test_tools/quic_stream_sequencer_buffer_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698