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

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

Issue 1458003004: Fix bug in ReliableQuicStream::WritevData() where if the write failed and the connection was closed… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@107427162
Patch Set: Created 5 years, 1 month 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/reliable_quic_stream.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/reliable_quic_stream.h" 5 #include "net/quic/reliable_quic_stream.h"
6 6
7 #include "net/quic/quic_connection.h" 7 #include "net/quic/quic_connection.h"
8 #include "net/quic/quic_flags.h" 8 #include "net/quic/quic_flags.h"
9 #include "net/quic/quic_utils.h" 9 #include "net/quic/quic_utils.h"
10 #include "net/quic/quic_write_blocked_list.h" 10 #include "net/quic/quic_write_blocked_list.h"
11 #include "net/quic/spdy_utils.h" 11 #include "net/quic/spdy_utils.h"
12 #include "net/quic/test_tools/quic_config_peer.h" 12 #include "net/quic/test_tools/quic_config_peer.h"
13 #include "net/quic/test_tools/quic_connection_peer.h" 13 #include "net/quic/test_tools/quic_connection_peer.h"
14 #include "net/quic/test_tools/quic_flow_controller_peer.h" 14 #include "net/quic/test_tools/quic_flow_controller_peer.h"
15 #include "net/quic/test_tools/quic_session_peer.h" 15 #include "net/quic/test_tools/quic_session_peer.h"
16 #include "net/quic/test_tools/quic_test_utils.h" 16 #include "net/quic/test_tools/quic_test_utils.h"
17 #include "net/quic/test_tools/reliable_quic_stream_peer.h" 17 #include "net/quic/test_tools/reliable_quic_stream_peer.h"
18 #include "net/test/gtest_util.h" 18 #include "net/test/gtest_util.h"
19 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gmock_mutant.h" 20 #include "testing/gmock_mutant.h"
21 21
22 using base::StringPiece; 22 using base::StringPiece;
23 using std::min; 23 using std::min;
24 using std::string; 24 using std::string;
25 using testing::AnyNumber; 25 using testing::AnyNumber;
26 using testing::AtLeast; 26 using testing::AtLeast;
27 using testing::CreateFunctor; 27 using testing::CreateFunctor;
28 using testing::InSequence; 28 using testing::InSequence;
29 using testing::Invoke; 29 using testing::Invoke;
30 using testing::DoAll;
30 using testing::Return; 31 using testing::Return;
31 using testing::StrictMock; 32 using testing::StrictMock;
32 using testing::WithArgs; 33 using testing::WithArgs;
33 using testing::_; 34 using testing::_;
34 35
35 namespace net { 36 namespace net {
36 namespace test { 37 namespace test {
37 namespace { 38 namespace {
38 39
39 const char kData1[] = "FooAndBar"; 40 const char kData1[] = "FooAndBar";
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 134
134 void set_initial_flow_control_window_bytes(uint32 val) { 135 void set_initial_flow_control_window_bytes(uint32 val) {
135 initial_flow_control_window_bytes_ = val; 136 initial_flow_control_window_bytes_ = val;
136 } 137 }
137 138
138 bool HasWriteBlockedStreams() { 139 bool HasWriteBlockedStreams() {
139 return write_blocked_list_->HasWriteBlockedCryptoOrHeadersStream() || 140 return write_blocked_list_->HasWriteBlockedCryptoOrHeadersStream() ||
140 write_blocked_list_->HasWriteBlockedDataStreams(); 141 write_blocked_list_->HasWriteBlockedDataStreams();
141 } 142 }
142 143
144 QuicConsumedData CloseStreamOnWriteError(
145 QuicStreamId id,
146 QuicIOVector /*iov*/,
147 QuicStreamOffset /*offset*/,
148 bool /*fin*/,
149 FecProtection /*fec_protection*/,
150 QuicAckListenerInterface* /*ack_notifier_delegate*/) {
151 session_->CloseStream(id);
152 return QuicConsumedData(1, false);
153
154 }
155
143 protected: 156 protected:
144 MockConnectionHelper helper_; 157 MockConnectionHelper helper_;
145 MockConnection* connection_; 158 MockConnection* connection_;
146 scoped_ptr<MockQuicSpdySession> session_; 159 scoped_ptr<MockQuicSpdySession> session_;
147 TestStream* stream_; 160 TestStream* stream_;
148 SpdyHeaderBlock headers_; 161 SpdyHeaderBlock headers_;
149 QuicWriteBlockedList* write_blocked_list_; 162 QuicWriteBlockedList* write_blocked_list_;
150 uint32 initial_flow_control_window_bytes_; 163 uint32 initial_flow_control_window_bytes_;
151 QuicTime::Delta zero_; 164 QuicTime::Delta zero_;
152 QuicVersionVector supported_versions_; 165 QuicVersionVector supported_versions_;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 Initialize(kShouldProcessData); 217 Initialize(kShouldProcessData);
205 218
206 // Write no data and a fin. If we consume nothing we should be write blocked, 219 // Write no data and a fin. If we consume nothing we should be write blocked,
207 // as the fin was not consumed. 220 // as the fin was not consumed.
208 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _)) 221 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _))
209 .WillOnce(Return(QuicConsumedData(0, false))); 222 .WillOnce(Return(QuicConsumedData(0, false)));
210 stream_->WriteOrBufferData(StringPiece(), true, nullptr); 223 stream_->WriteOrBufferData(StringPiece(), true, nullptr);
211 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); 224 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams());
212 } 225 }
213 226
227 TEST_F(ReliableQuicStreamTest, CloseOnPartialWrite) {
228 Initialize(kShouldProcessData);
229
230 // Write some data and no fin. However, while writing the data
231 // close the stream and verify that MarkConnectionLevelWriteBlocked does not
232 // crash with an unknown stream.
233 EXPECT_CALL(*session_, WritevData(kTestStreamId, _, _, _, _, _))
234 .WillOnce(Invoke(this, &ReliableQuicStreamTest::CloseStreamOnWriteError));
235 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, nullptr);
236 ASSERT_EQ(0u, write_blocked_list_->NumBlockedStreams());
237 }
238
214 TEST_F(ReliableQuicStreamTest, WriteOrBufferData) { 239 TEST_F(ReliableQuicStreamTest, WriteOrBufferData) {
215 Initialize(kShouldProcessData); 240 Initialize(kShouldProcessData);
216 241
217 EXPECT_FALSE(HasWriteBlockedStreams()); 242 EXPECT_FALSE(HasWriteBlockedStreams());
218 size_t length = 1 + QuicPacketCreator::StreamFramePacketOverhead( 243 size_t length = 1 + QuicPacketCreator::StreamFramePacketOverhead(
219 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 244 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion,
220 PACKET_6BYTE_PACKET_NUMBER, 0u, NOT_IN_FEC_GROUP); 245 PACKET_6BYTE_PACKET_NUMBER, 0u, NOT_IN_FEC_GROUP);
221 connection_->SetMaxPacketLength(length); 246 connection_->SetMaxPacketLength(length);
222 247
223 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)).WillOnce( 248 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)).WillOnce(
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); 767 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
743 } else { 768 } else {
744 EXPECT_FALSE(stream_->fin_received()); 769 EXPECT_FALSE(stream_->fin_received());
745 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset()); 770 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset());
746 } 771 }
747 } 772 }
748 773
749 } // namespace 774 } // namespace
750 } // namespace test 775 } // namespace test
751 } // namespace net 776 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/reliable_quic_stream.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698