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

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

Issue 1413373013: Quic streams honor RST_STREAM + NO_ERROR on the write side. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@106851267
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/quic_connection.cc ('k') | net/quic/quic_spdy_stream.h » ('j') | 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 2408 matching lines...) Expand 10 before | Expand all | Expand 10 after
2419 } 2419 }
2420 2420
2421 TEST_P(QuicConnectionTest, DoNotSendQueuedPacketForResetStream) { 2421 TEST_P(QuicConnectionTest, DoNotSendQueuedPacketForResetStream) {
2422 // Block the connection to queue the packet. 2422 // Block the connection to queue the packet.
2423 BlockOnNextWrite(); 2423 BlockOnNextWrite();
2424 2424
2425 QuicStreamId stream_id = 2; 2425 QuicStreamId stream_id = 2;
2426 connection_.SendStreamDataWithString(stream_id, "foo", 0, !kFin, nullptr); 2426 connection_.SendStreamDataWithString(stream_id, "foo", 0, !kFin, nullptr);
2427 2427
2428 // Now that there is a queued packet, reset the stream. 2428 // Now that there is a queued packet, reset the stream.
2429 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); 2429 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14);
2430 2430
2431 // Unblock the connection and verify that only the RST_STREAM is sent. 2431 // Unblock the connection and verify that only the RST_STREAM is sent.
2432 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2432 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2433 writer_->SetWritable(); 2433 writer_->SetWritable();
2434 connection_.OnCanWrite(); 2434 connection_.OnCanWrite();
2435 EXPECT_EQ(1u, writer_->frame_count()); 2435 EXPECT_EQ(1u, writer_->frame_count());
2436 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); 2436 EXPECT_EQ(1u, writer_->rst_stream_frames().size());
2437 } 2437 }
2438 2438
2439 TEST_P(QuicConnectionTest, SendQueuedPacketForQuicRstStreamNoError) {
2440 // Block the connection to queue the packet.
2441 BlockOnNextWrite();
2442
2443 QuicStreamId stream_id = 2;
2444 connection_.SendStreamDataWithString(stream_id, "foo", 0, !kFin, nullptr);
2445
2446 // Now that there is a queued packet, reset the stream.
2447 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14);
2448
2449 // Unblock the connection and verify that the RST_STREAM is sent and the data
2450 // packet is sent on QUIC_VERSION_29 or later versions.
2451 if (version() > QUIC_VERSION_28) {
2452 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2453 .Times(AtLeast(2));
2454 } else {
2455 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2456 }
2457 writer_->SetWritable();
2458 connection_.OnCanWrite();
2459 EXPECT_EQ(1u, writer_->frame_count());
2460 EXPECT_EQ(1u, writer_->rst_stream_frames().size());
2461 }
2462
2439 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnNack) { 2463 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnNack) {
2440 QuicStreamId stream_id = 2; 2464 QuicStreamId stream_id = 2;
2441 QuicPacketNumber last_packet; 2465 QuicPacketNumber last_packet;
2442 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2466 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet);
2443 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); 2467 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet);
2444 SendStreamDataToPeer(stream_id, "fooos", 7, !kFin, &last_packet); 2468 SendStreamDataToPeer(stream_id, "fooos", 7, !kFin, &last_packet);
2445 2469
2446 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2470 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2447 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); 2471 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14);
2448 2472
2449 // Lose a packet and ensure it does not trigger retransmission. 2473 // Lose a packet and ensure it does not trigger retransmission.
2450 QuicAckFrame nack_two = InitAckFrame(last_packet); 2474 QuicAckFrame nack_two = InitAckFrame(last_packet);
2451 NackPacket(last_packet - 1, &nack_two); 2475 NackPacket(last_packet - 1, &nack_two);
2452 PacketNumberSet lost_packets; 2476 PacketNumberSet lost_packets;
2453 lost_packets.insert(last_packet - 1); 2477 lost_packets.insert(last_packet - 1);
2454 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2478 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2455 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 2479 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2456 .WillOnce(Return(lost_packets)); 2480 .WillOnce(Return(lost_packets));
2457 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2481 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2458 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2482 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2459 ProcessAckPacket(&nack_two); 2483 ProcessAckPacket(&nack_two);
2460 } 2484 }
2461 2485
2486 TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnNack) {
2487 QuicStreamId stream_id = 2;
2488 QuicPacketNumber last_packet;
2489 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet);
2490 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet);
2491 SendStreamDataToPeer(stream_id, "fooos", 7, !kFin, &last_packet);
2492
2493 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2494 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14);
2495
2496 // Lose a packet, ensure it triggers retransmission on QUIC_VERSION_29
2497 // or later versions.
2498 QuicAckFrame nack_two = InitAckFrame(last_packet);
2499 NackPacket(last_packet - 1, &nack_two);
2500 PacketNumberSet lost_packets;
2501 lost_packets.insert(last_packet - 1);
2502 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2503 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2504 .WillOnce(Return(lost_packets));
2505 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2506 if (version() > QUIC_VERSION_28) {
2507 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2508 .Times(AtLeast(1));
2509 } else {
2510 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2511 }
2512 ProcessAckPacket(&nack_two);
2513 }
2514
2462 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnRTO) { 2515 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnRTO) {
2463 QuicStreamId stream_id = 2; 2516 QuicStreamId stream_id = 2;
2464 QuicPacketNumber last_packet; 2517 QuicPacketNumber last_packet;
2465 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2518 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet);
2466 2519
2467 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2520 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2468 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); 2521 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14);
2469 2522
2470 // Fire the RTO and verify that the RST_STREAM is resent, not stream data. 2523 // Fire the RTO and verify that the RST_STREAM is resent, not stream data.
2471 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2524 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2472 clock_.AdvanceTime(DefaultRetransmissionTime()); 2525 clock_.AdvanceTime(DefaultRetransmissionTime());
2473 connection_.GetRetransmissionAlarm()->Fire(); 2526 connection_.GetRetransmissionAlarm()->Fire();
2474 EXPECT_EQ(1u, writer_->frame_count()); 2527 EXPECT_EQ(1u, writer_->frame_count());
2475 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); 2528 EXPECT_EQ(1u, writer_->rst_stream_frames().size());
2476 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); 2529 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id);
2477 } 2530 }
2478 2531
2532 TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnRTO) {
2533 QuicStreamId stream_id = 2;
2534 QuicPacketNumber last_packet;
2535 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet);
2536
2537 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2538 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14);
2539
2540 // Fire the RTO and verify that the RST_STREAM is resent, the stream data
2541 // is only sent on QUIC_VERSION_29 or later versions.
2542 if (version() > QUIC_VERSION_28) {
2543 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2544 .Times(AtLeast(2));
2545 } else {
2546 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2547 }
2548 clock_.AdvanceTime(DefaultRetransmissionTime());
2549 connection_.GetRetransmissionAlarm()->Fire();
2550 EXPECT_EQ(1u, writer_->frame_count());
2551 EXPECT_EQ(1u, writer_->rst_stream_frames().size());
2552 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id);
2553 }
2554
2479 TEST_P(QuicConnectionTest, DoNotSendPendingRetransmissionForResetStream) { 2555 TEST_P(QuicConnectionTest, DoNotSendPendingRetransmissionForResetStream) {
2480 QuicStreamId stream_id = 2; 2556 QuicStreamId stream_id = 2;
2481 QuicPacketNumber last_packet; 2557 QuicPacketNumber last_packet;
2482 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2558 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet);
2483 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); 2559 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet);
2484 BlockOnNextWrite(); 2560 BlockOnNextWrite();
2485 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr); 2561 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr);
2486 2562
2487 // Lose a packet which will trigger a pending retransmission. 2563 // Lose a packet which will trigger a pending retransmission.
2488 QuicAckFrame ack = InitAckFrame(last_packet); 2564 QuicAckFrame ack = InitAckFrame(last_packet);
2489 NackPacket(last_packet - 1, &ack); 2565 NackPacket(last_packet - 1, &ack);
2490 PacketNumberSet lost_packets; 2566 PacketNumberSet lost_packets;
2491 lost_packets.insert(last_packet - 1); 2567 lost_packets.insert(last_packet - 1);
2492 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2568 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2493 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 2569 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2494 .WillOnce(Return(lost_packets)); 2570 .WillOnce(Return(lost_packets));
2495 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2571 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2496 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2572 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2497 ProcessAckPacket(&ack); 2573 ProcessAckPacket(&ack);
2498 2574
2499 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); 2575 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14);
2500 2576
2501 // Unblock the connection and verify that the RST_STREAM is sent but not the 2577 // Unblock the connection and verify that the RST_STREAM is sent but not the
2502 // second data packet nor a retransmit. 2578 // second data packet nor a retransmit.
2503 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2579 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2504 writer_->SetWritable(); 2580 writer_->SetWritable();
2505 connection_.OnCanWrite(); 2581 connection_.OnCanWrite();
2506 EXPECT_EQ(1u, writer_->frame_count()); 2582 EXPECT_EQ(1u, writer_->frame_count());
2507 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); 2583 EXPECT_EQ(1u, writer_->rst_stream_frames().size());
2508 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); 2584 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id);
2509 } 2585 }
2510 2586
2587 TEST_P(QuicConnectionTest, SendPendingRetransmissionForQuicRstStreamNoError) {
2588 QuicStreamId stream_id = 2;
2589 QuicPacketNumber last_packet;
2590 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet);
2591 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet);
2592 BlockOnNextWrite();
2593 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr);
2594
2595 // Lose a packet which will trigger a pending retransmission.
2596 QuicAckFrame ack = InitAckFrame(last_packet);
2597 NackPacket(last_packet - 1, &ack);
2598 PacketNumberSet lost_packets;
2599 lost_packets.insert(last_packet - 1);
2600 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2601 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2602 .WillOnce(Return(lost_packets));
2603 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2604 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2605 ProcessAckPacket(&ack);
2606
2607 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14);
2608
2609 // Unblock the connection and verify that the RST_STREAM is sent and the
2610 // second data packet or a retransmit is only sent on QUIC_VERSION_29 or
2611 // later versions.
2612 if (version() > QUIC_VERSION_28) {
2613 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2614 .Times(AtLeast(2));
2615 } else {
2616 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2617 }
2618 writer_->SetWritable();
2619 connection_.OnCanWrite();
2620 EXPECT_EQ(1u, writer_->frame_count());
2621 if (version() > QUIC_VERSION_28) {
2622 EXPECT_EQ(0u, writer_->rst_stream_frames().size());
2623 } else {
2624 EXPECT_EQ(1u, writer_->rst_stream_frames().size());
2625 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id);
2626 }
2627 }
2628
2511 TEST_P(QuicConnectionTest, DiscardRetransmit) { 2629 TEST_P(QuicConnectionTest, DiscardRetransmit) {
2512 QuicPacketNumber last_packet; 2630 QuicPacketNumber last_packet;
2513 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 2631 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1
2514 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 2632 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2
2515 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 2633 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3
2516 2634
2517 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2635 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2518 2636
2519 // Instigate a loss with an ack. 2637 // Instigate a loss with an ack.
2520 QuicAckFrame nack_two = InitAckFrame(3); 2638 QuicAckFrame nack_two = InitAckFrame(3);
(...skipping 2623 matching lines...) Expand 10 before | Expand all | Expand 10 after
5144 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 5262 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
5145 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); 5263 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away.");
5146 EXPECT_TRUE(connection_.goaway_sent()); 5264 EXPECT_TRUE(connection_.goaway_sent());
5147 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 5265 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
5148 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); 5266 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away.");
5149 } 5267 }
5150 5268
5151 } // namespace 5269 } // namespace
5152 } // namespace test 5270 } // namespace test
5153 } // namespace net 5271 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_spdy_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698