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

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

Issue 1395423009: relnote: add test cases to catch failure on uninitialized self_address_ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Add_comment_104108540
Patch Set: Minor cleanup Created 5 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 unified diff | Download patch
« net/quic/quic_connection.cc ('K') | « net/quic/quic_connection.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_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); 232 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper);
233 }; 233 };
234 234
235 class TestPacketWriter : public QuicPacketWriter { 235 class TestPacketWriter : public QuicPacketWriter {
236 public: 236 public:
237 TestPacketWriter(QuicVersion version, MockClock* clock) 237 TestPacketWriter(QuicVersion version, MockClock* clock)
238 : version_(version), 238 : version_(version),
239 framer_(SupportedVersions(version_)), 239 framer_(SupportedVersions(version_)),
240 last_packet_size_(0), 240 last_packet_size_(0),
241 write_blocked_(false), 241 write_blocked_(false),
242 write_should_fail_(false),
242 block_on_next_write_(false), 243 block_on_next_write_(false),
243 is_write_blocked_data_buffered_(false), 244 is_write_blocked_data_buffered_(false),
244 final_bytes_of_last_packet_(0), 245 final_bytes_of_last_packet_(0),
245 final_bytes_of_previous_packet_(0), 246 final_bytes_of_previous_packet_(0),
246 use_tagging_decrypter_(false), 247 use_tagging_decrypter_(false),
247 packets_write_attempts_(0), 248 packets_write_attempts_(0),
248 clock_(clock), 249 clock_(clock),
249 write_pause_time_delta_(QuicTime::Delta::Zero()), 250 write_pause_time_delta_(QuicTime::Delta::Zero()),
250 max_packet_size_(kMaxPacketSize) {} 251 max_packet_size_(kMaxPacketSize) {}
251 252
(...skipping 15 matching lines...) Expand all
267 framer_.framer()->SetDecrypter(ENCRYPTION_NONE, new TaggingDecrypter); 268 framer_.framer()->SetDecrypter(ENCRYPTION_NONE, new TaggingDecrypter);
268 } 269 }
269 EXPECT_TRUE(framer_.ProcessPacket(packet)); 270 EXPECT_TRUE(framer_.ProcessPacket(packet));
270 if (block_on_next_write_) { 271 if (block_on_next_write_) {
271 write_blocked_ = true; 272 write_blocked_ = true;
272 block_on_next_write_ = false; 273 block_on_next_write_ = false;
273 } 274 }
274 if (IsWriteBlocked()) { 275 if (IsWriteBlocked()) {
275 return WriteResult(WRITE_STATUS_BLOCKED, -1); 276 return WriteResult(WRITE_STATUS_BLOCKED, -1);
276 } 277 }
278
279 if (ShouldWriteFail()) {
280 return WriteResult(WRITE_STATUS_ERROR, 0);
281 }
282
277 last_packet_size_ = packet.length(); 283 last_packet_size_ = packet.length();
278 284
279 if (!write_pause_time_delta_.IsZero()) { 285 if (!write_pause_time_delta_.IsZero()) {
280 clock_->AdvanceTime(write_pause_time_delta_); 286 clock_->AdvanceTime(write_pause_time_delta_);
281 } 287 }
282 return WriteResult(WRITE_STATUS_OK, last_packet_size_); 288 return WriteResult(WRITE_STATUS_OK, last_packet_size_);
283 } 289 }
284 290
285 bool IsWriteBlockedDataBuffered() const override { 291 bool IsWriteBlockedDataBuffered() const override {
286 return is_write_blocked_data_buffered_; 292 return is_write_blocked_data_buffered_;
287 } 293 }
288 294
295 bool ShouldWriteFail() { return write_should_fail_; }
296
289 bool IsWriteBlocked() const override { return write_blocked_; } 297 bool IsWriteBlocked() const override { return write_blocked_; }
290 298
291 void SetWritable() override { write_blocked_ = false; } 299 void SetWritable() override { write_blocked_ = false; }
292 300
301 void SetShouldWriteFail() { write_should_fail_ = true; }
302
293 QuicByteCount GetMaxPacketSize( 303 QuicByteCount GetMaxPacketSize(
294 const IPEndPoint& /*peer_address*/) const override { 304 const IPEndPoint& /*peer_address*/) const override {
295 return max_packet_size_; 305 return max_packet_size_;
296 } 306 }
297 307
298 void BlockOnNextWrite() { block_on_next_write_ = true; } 308 void BlockOnNextWrite() { block_on_next_write_ = true; }
299 309
300 // Sets the amount of time that the writer should before the actual write. 310 // Sets the amount of time that the writer should before the actual write.
301 void SetWritePauseTimeDelta(QuicTime::Delta delta) { 311 void SetWritePauseTimeDelta(QuicTime::Delta delta) {
302 write_pause_time_delta_ = delta; 312 write_pause_time_delta_ = delta;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 386
377 void set_max_packet_size(QuicByteCount max_packet_size) { 387 void set_max_packet_size(QuicByteCount max_packet_size) {
378 max_packet_size_ = max_packet_size; 388 max_packet_size_ = max_packet_size;
379 } 389 }
380 390
381 private: 391 private:
382 QuicVersion version_; 392 QuicVersion version_;
383 SimpleQuicFramer framer_; 393 SimpleQuicFramer framer_;
384 size_t last_packet_size_; 394 size_t last_packet_size_;
385 bool write_blocked_; 395 bool write_blocked_;
396 bool write_should_fail_;
386 bool block_on_next_write_; 397 bool block_on_next_write_;
387 bool is_write_blocked_data_buffered_; 398 bool is_write_blocked_data_buffered_;
388 uint32 final_bytes_of_last_packet_; 399 uint32 final_bytes_of_last_packet_;
389 uint32 final_bytes_of_previous_packet_; 400 uint32 final_bytes_of_previous_packet_;
390 bool use_tagging_decrypter_; 401 bool use_tagging_decrypter_;
391 uint32 packets_write_attempts_; 402 uint32 packets_write_attempts_;
392 MockClock *clock_; 403 MockClock *clock_;
393 // If non-zero, the clock will pause during WritePacket for this amount of 404 // If non-zero, the clock will pause during WritePacket for this amount of
394 // time. 405 // time.
395 QuicTime::Delta write_pause_time_delta_; 406 QuicTime::Delta write_pause_time_delta_;
(...skipping 3246 matching lines...) Expand 10 before | Expand all | Expand 10 after
3642 3653
3643 TEST_P(QuicConnectionTest, SendScheduler) { 3654 TEST_P(QuicConnectionTest, SendScheduler) {
3644 // Test that if we send a packet without delay, it is not queued. 3655 // Test that if we send a packet without delay, it is not queued.
3645 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 3656 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
3646 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 3657 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3647 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, 3658 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash,
3648 HAS_RETRANSMITTABLE_DATA, false, false); 3659 HAS_RETRANSMITTABLE_DATA, false, false);
3649 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 3660 EXPECT_EQ(0u, connection_.NumQueuedPackets());
3650 } 3661 }
3651 3662
3663 TEST_P(QuicConnectionTest, FailToSendFirstPacket) {
3664 // Test that the connection does not crash when it fails to send the first
3665 // packet at which point self_address_ might be uninitialized.
3666 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1);
3667 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
3668 writer_->SetShouldWriteFail();
3669 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash,
3670 HAS_RETRANSMITTABLE_DATA, false, false);
3671 }
3672
3652 TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) { 3673 TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) {
3653 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 3674 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
3654 BlockOnNextWrite(); 3675 BlockOnNextWrite();
3655 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0); 3676 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0);
3656 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, 3677 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash,
3657 HAS_RETRANSMITTABLE_DATA, false, false); 3678 HAS_RETRANSMITTABLE_DATA, false, false);
3658 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 3679 EXPECT_EQ(1u, connection_.NumQueuedPackets());
3659 } 3680 }
3660 3681
3661 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { 3682 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) {
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after
4805 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 4826 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
4806 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); 4827 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away.");
4807 EXPECT_TRUE(connection_.goaway_sent()); 4828 EXPECT_TRUE(connection_.goaway_sent());
4808 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 4829 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
4809 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); 4830 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away.");
4810 } 4831 }
4811 4832
4812 } // namespace 4833 } // namespace
4813 } // namespace test 4834 } // namespace test
4814 } // namespace net 4835 } // namespace net
OLDNEW
« net/quic/quic_connection.cc ('K') | « net/quic/quic_connection.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698