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

Unified Diff: net/quic/core/quic_server_session_base_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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/core/quic_server_session_base.cc ('k') | net/quic/core/quic_session.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/core/quic_server_session_base_test.cc
diff --git a/net/quic/core/quic_server_session_base_test.cc b/net/quic/core/quic_server_session_base_test.cc
index 171b1cbf932f4780a49d1281782583135915f2a5..596d2678333066be7247de6b1617ef5ab86398df 100644
--- a/net/quic/core/quic_server_session_base_test.cc
+++ b/net/quic/core/quic_server_session_base_test.cc
@@ -80,6 +80,8 @@ class TestServerSession : public QuicServerSessionBase {
~TestServerSession() override { delete connection(); };
protected:
+ // TODO(ckrasic) - for two below, remove when
+ // quic_reloadable_flag_quic_refactor_stream_creation is deprecated.
QuicSpdyStream* CreateIncomingDynamicStream(QuicStreamId id) override {
if (!ShouldCreateIncomingDynamicStream(id)) {
return nullptr;
@@ -102,6 +104,10 @@ class TestServerSession : public QuicServerSessionBase {
return stream;
}
+ std::unique_ptr<QuicStream> CreateStream(QuicStreamId id) override {
+ return QuicMakeUnique<QuicSimpleServerStream>(id, this, response_cache_);
+ }
+
QuicCryptoServerStreamBase* CreateQuicCryptoServerStream(
const QuicCryptoServerConfig* crypto_config,
QuicCompressedCertsCache* compressed_certs_cache) override {
@@ -151,6 +157,14 @@ class QuicServerSessionBaseTest : public QuicTestWithParam<QuicVersion> {
visitor_ = QuicConnectionPeer::GetVisitor(connection_);
}
+ QuicStreamId GetNthClientInitiatedId(int n) {
+ return QuicSpdySessionPeer::GetNthClientInitiatedStreamId(*session_, n);
+ }
+
+ QuicStreamId GetNthServerInitiatedId(int n) {
+ return QuicSpdySessionPeer::GetNthServerInitiatedStreamId(*session_, n);
+ }
+
StrictMock<MockQuicSessionVisitor> owner_;
StrictMock<MockQuicCryptoServerStreamHelper> stream_helper_;
MockQuicConnectionHelper helper_;
@@ -198,16 +212,17 @@ TEST_P(QuicServerSessionBaseTest, ServerPushDisabledByDefault) {
TEST_P(QuicServerSessionBaseTest, CloseStreamDueToReset) {
// Open a stream, then reset it.
// Send two bytes of payload to open it.
- QuicStreamFrame data1(kClientDataStreamId1, false, 0, QuicStringPiece("HT"));
+ QuicStreamFrame data1(GetNthClientInitiatedId(0), false, 0,
+ QuicStringPiece("HT"));
session_->OnStreamFrame(data1);
EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams());
// Send a reset (and expect the peer to send a RST in response).
- QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM,
- 0);
+ QuicRstStreamFrame rst1(GetNthClientInitiatedId(0),
+ QUIC_ERROR_PROCESSING_STREAM, 0);
EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1);
- EXPECT_CALL(*connection_,
- SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0));
+ EXPECT_CALL(*connection_, SendRstStream(GetNthClientInitiatedId(0),
+ QUIC_RST_ACKNOWLEDGEMENT, 0));
visitor_->OnRstStream(rst1);
EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams());
@@ -221,16 +236,17 @@ TEST_P(QuicServerSessionBaseTest, CloseStreamDueToReset) {
TEST_P(QuicServerSessionBaseTest, NeverOpenStreamDueToReset) {
// Send a reset (and expect the peer to send a RST in response).
- QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM,
- 0);
+ QuicRstStreamFrame rst1(GetNthClientInitiatedId(0),
+ QUIC_ERROR_PROCESSING_STREAM, 0);
EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1);
- EXPECT_CALL(*connection_,
- SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0));
+ EXPECT_CALL(*connection_, SendRstStream(GetNthClientInitiatedId(0),
+ QUIC_RST_ACKNOWLEDGEMENT, 0));
visitor_->OnRstStream(rst1);
EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams());
// Send two bytes of payload.
- QuicStreamFrame data1(kClientDataStreamId1, false, 0, QuicStringPiece("HT"));
+ QuicStreamFrame data1(GetNthClientInitiatedId(0), false, 0,
+ QuicStringPiece("HT"));
visitor_->OnStreamFrame(data1);
// The stream should never be opened, now that the reset is received.
@@ -240,26 +256,29 @@ TEST_P(QuicServerSessionBaseTest, NeverOpenStreamDueToReset) {
TEST_P(QuicServerSessionBaseTest, AcceptClosedStream) {
// Send (empty) compressed headers followed by two bytes of data.
- QuicStreamFrame frame1(kClientDataStreamId1, false, 0,
+ QuicStreamFrame frame1(GetNthClientInitiatedId(0), false, 0,
QuicStringPiece("\1\0\0\0\0\0\0\0HT"));
- QuicStreamFrame frame2(kClientDataStreamId2, false, 0,
+ QuicStreamFrame frame2(GetNthClientInitiatedId(1), false, 0,
QuicStringPiece("\2\0\0\0\0\0\0\0HT"));
visitor_->OnStreamFrame(frame1);
visitor_->OnStreamFrame(frame2);
EXPECT_EQ(2u, session_->GetNumOpenIncomingStreams());
// Send a reset (and expect the peer to send a RST in response).
- QuicRstStreamFrame rst(kClientDataStreamId1, QUIC_ERROR_PROCESSING_STREAM, 0);
+ QuicRstStreamFrame rst(GetNthClientInitiatedId(0),
+ QUIC_ERROR_PROCESSING_STREAM, 0);
EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1);
- EXPECT_CALL(*connection_,
- SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0));
+ EXPECT_CALL(*connection_, SendRstStream(GetNthClientInitiatedId(0),
+ QUIC_RST_ACKNOWLEDGEMENT, 0));
visitor_->OnRstStream(rst);
// If we were tracking, we'd probably want to reject this because it's data
// past the reset point of stream 3. As it's a closed stream we just drop the
// data on the floor, but accept the packet because it has data for stream 5.
- QuicStreamFrame frame3(kClientDataStreamId1, false, 2, QuicStringPiece("TP"));
- QuicStreamFrame frame4(kClientDataStreamId2, false, 2, QuicStringPiece("TP"));
+ QuicStreamFrame frame3(GetNthClientInitiatedId(0), false, 2,
+ QuicStringPiece("TP"));
+ QuicStreamFrame frame4(GetNthClientInitiatedId(1), false, 2,
+ QuicStringPiece("TP"));
visitor_->OnStreamFrame(frame3);
visitor_->OnStreamFrame(frame4);
// The stream should never be opened, now that the reset is received.
@@ -281,23 +300,23 @@ TEST_P(QuicServerSessionBaseTest, MaxOpenStreams) {
EXPECT_EQ(kMaxStreamsForTest + kMaxStreamsMinimumIncrement,
session_->max_open_incoming_streams());
EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams());
- QuicStreamId stream_id = kClientDataStreamId1;
+ QuicStreamId stream_id = GetNthClientInitiatedId(0);
// Open the max configured number of streams, should be no problem.
for (size_t i = 0; i < kMaxStreamsForTest; ++i) {
EXPECT_TRUE(QuicServerSessionBasePeer::GetOrCreateDynamicStream(
session_.get(), stream_id));
- stream_id += 2;
+ stream_id += QuicSpdySessionPeer::NextStreamId(*session_);
}
// Open more streams: server should accept slightly more than the limit.
for (size_t i = 0; i < kMaxStreamsMinimumIncrement; ++i) {
EXPECT_TRUE(QuicServerSessionBasePeer::GetOrCreateDynamicStream(
session_.get(), stream_id));
- stream_id += 2;
+ stream_id += QuicSpdySessionPeer::NextStreamId(*session_);
}
// Now violate the server's internal stream limit.
- stream_id += 2;
+ stream_id += QuicSpdySessionPeer::NextStreamId(*session_);
EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0);
EXPECT_CALL(*connection_, SendRstStream(stream_id, QUIC_REFUSED_STREAM, 0));
// Even if the connection remains open, the stream creation should fail.
@@ -321,11 +340,12 @@ TEST_P(QuicServerSessionBaseTest, MaxAvailableStreams) {
EXPECT_EQ(0u, session_->GetNumOpenIncomingStreams());
EXPECT_TRUE(QuicServerSessionBasePeer::GetOrCreateDynamicStream(
- session_.get(), kClientDataStreamId1));
+ session_.get(), GetNthClientInitiatedId(0)));
// Establish available streams up to the server's limit.
+ QuicStreamId next_id = QuicSpdySessionPeer::NextStreamId(*session_);
const int kLimitingStreamId =
- kClientDataStreamId1 + (kAvailableStreamLimit)*2 + 2;
+ GetNthClientInitiatedId(kAvailableStreamLimit + 1);
EXPECT_TRUE(QuicServerSessionBasePeer::GetOrCreateDynamicStream(
session_.get(), kLimitingStreamId));
@@ -335,7 +355,7 @@ TEST_P(QuicServerSessionBaseTest, MaxAvailableStreams) {
// This forces stream kLimitingStreamId + 2 to become available, which
// violates the quota.
EXPECT_FALSE(QuicServerSessionBasePeer::GetOrCreateDynamicStream(
- session_.get(), kLimitingStreamId + 4));
+ session_.get(), kLimitingStreamId + 2 * next_id));
}
// TODO(ckrasic): remove this when
@@ -355,15 +375,21 @@ TEST_P(QuicServerSessionBaseTest, GetEvenIncomingError) {
// Incoming streams on the server session must be odd.
EXPECT_CALL(*connection_, CloseConnection(QUIC_INVALID_STREAM_ID, _, _));
EXPECT_EQ(nullptr, QuicServerSessionBasePeer::GetOrCreateDynamicStream(
- session_.get(), 4));
+ session_.get(), GetNthServerInitiatedId(0)));
}
TEST_P(QuicServerSessionBaseTest, GetStreamDisconnected) {
// Don't create new streams if the connection is disconnected.
QuicConnectionPeer::TearDownLocalConnectionState(connection_);
- EXPECT_QUIC_BUG(
- QuicServerSessionBasePeer::GetOrCreateDynamicStream(session_.get(), 5),
- "ShouldCreateIncomingDynamicStream called when disconnected");
+ if (FLAGS_quic_reloadable_flag_quic_refactor_stream_creation) {
+ EXPECT_EQ(nullptr, QuicServerSessionBasePeer::GetOrCreateDynamicStream(
+ session_.get(), GetNthClientInitiatedId(0)));
+ } else {
+ EXPECT_QUIC_BUG(
+ QuicServerSessionBasePeer::GetOrCreateDynamicStream(
+ session_.get(), GetNthClientInitiatedId(0)),
+ "ShouldCreateIncomingDynamicStream called when disconnected");
+ }
}
class MockQuicCryptoServerStream : public QuicCryptoServerStream {
« no previous file with comments | « net/quic/core/quic_server_session_base.cc ('k') | net/quic/core/quic_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698