OLD | NEW |
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 <stddef.h> | 5 #include <stddef.h> |
6 #include <sys/epoll.h> | 6 #include <sys/epoll.h> |
7 | 7 |
8 #include <cstdint> | 8 #include <cstdint> |
9 #include <list> | 9 #include <list> |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <utility> | 12 #include <utility> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
19 #include "base/threading/platform_thread.h" | 19 #include "base/threading/platform_thread.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "net/base/ip_address.h" | 21 #include "net/base/ip_address.h" |
22 #include "net/base/ip_endpoint.h" | 22 #include "net/base/ip_endpoint.h" |
23 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" | 23 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" |
24 #include "net/quic/core/crypto/null_encrypter.h" | 24 #include "net/quic/core/crypto/null_encrypter.h" |
25 #include "net/quic/core/quic_client_session_base.h" | 25 #include "net/quic/core/quic_client_session_base.h" |
26 #include "net/quic/core/quic_flags.h" | 26 #include "net/quic/core/quic_flags.h" |
27 #include "net/quic/core/quic_framer.h" | 27 #include "net/quic/core/quic_framer.h" |
28 #include "net/quic/core/quic_packet_creator.h" | 28 #include "net/quic/core/quic_packet_creator.h" |
29 #include "net/quic/core/quic_protocol.h" | 29 #include "net/quic/core/quic_packets.h" |
30 #include "net/quic/core/quic_server_id.h" | 30 #include "net/quic/core/quic_server_id.h" |
31 #include "net/quic/core/quic_session.h" | 31 #include "net/quic/core/quic_session.h" |
32 #include "net/quic/core/quic_utils.h" | 32 #include "net/quic/core/quic_utils.h" |
33 #include "net/quic/platform/api/quic_socket_address.h" | 33 #include "net/quic/platform/api/quic_socket_address.h" |
34 #include "net/quic/test_tools/crypto_test_utils.h" | 34 #include "net/quic/test_tools/crypto_test_utils.h" |
35 #include "net/quic/test_tools/quic_config_peer.h" | 35 #include "net/quic/test_tools/quic_config_peer.h" |
36 #include "net/quic/test_tools/quic_connection_peer.h" | 36 #include "net/quic/test_tools/quic_connection_peer.h" |
37 #include "net/quic/test_tools/quic_flow_controller_peer.h" | 37 #include "net/quic/test_tools/quic_flow_controller_peer.h" |
38 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" | 38 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" |
39 #include "net/quic/test_tools/quic_session_peer.h" | 39 #include "net/quic/test_tools/quic_session_peer.h" |
40 #include "net/quic/test_tools/quic_spdy_session_peer.h" | 40 #include "net/quic/test_tools/quic_spdy_session_peer.h" |
41 #include "net/quic/test_tools/quic_stream_peer.h" | 41 #include "net/quic/test_tools/quic_stream_peer.h" |
42 #include "net/quic/test_tools/quic_stream_sequencer_peer.h" | 42 #include "net/quic/test_tools/quic_stream_sequencer_peer.h" |
43 #include "net/quic/test_tools/quic_test_utils.h" | 43 #include "net/quic/test_tools/quic_test_utils.h" |
44 #include "net/test/gtest_util.h" | 44 #include "net/test/gtest_util.h" |
45 #include "net/tools/epoll_server/epoll_server.h" | 45 #include "net/tools/epoll_server/epoll_server.h" |
46 #include "net/tools/quic/quic_epoll_connection_helper.h" | 46 #include "net/tools/quic/quic_epoll_connection_helper.h" |
47 #include "net/tools/quic/quic_in_memory_cache.h" | 47 #include "net/tools/quic/quic_http_response_cache.h" |
48 #include "net/tools/quic/quic_packet_writer_wrapper.h" | 48 #include "net/tools/quic/quic_packet_writer_wrapper.h" |
49 #include "net/tools/quic/quic_server.h" | 49 #include "net/tools/quic/quic_server.h" |
50 #include "net/tools/quic/quic_simple_server_stream.h" | 50 #include "net/tools/quic/quic_simple_server_stream.h" |
51 #include "net/tools/quic/quic_socket_utils.h" | 51 #include "net/tools/quic/quic_socket_utils.h" |
52 #include "net/tools/quic/quic_spdy_client_stream.h" | 52 #include "net/tools/quic/quic_spdy_client_stream.h" |
53 #include "net/tools/quic/test_tools/packet_dropping_test_writer.h" | 53 #include "net/tools/quic/test_tools/packet_dropping_test_writer.h" |
54 #include "net/tools/quic/test_tools/packet_reordering_writer.h" | 54 #include "net/tools/quic/test_tools/packet_reordering_writer.h" |
55 #include "net/tools/quic/test_tools/quic_client_peer.h" | 55 #include "net/tools/quic/test_tools/quic_client_peer.h" |
56 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" | 56 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" |
57 #include "net/tools/quic/test_tools/quic_server_peer.h" | 57 #include "net/tools/quic/test_tools/quic_server_peer.h" |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 << "case. Otherwise, your test will leak memory."; | 422 << "case. Otherwise, your test will leak memory."; |
423 StopServer(); | 423 StopServer(); |
424 } | 424 } |
425 | 425 |
426 void StartServer() { | 426 void StartServer() { |
427 FLAGS_quic_use_cheap_stateless_rejects = | 427 FLAGS_quic_use_cheap_stateless_rejects = |
428 GetParam().use_cheap_stateless_reject; | 428 GetParam().use_cheap_stateless_reject; |
429 | 429 |
430 auto test_server = new QuicTestServer( | 430 auto test_server = new QuicTestServer( |
431 CryptoTestUtils::ProofSourceForTesting(), server_config_, | 431 CryptoTestUtils::ProofSourceForTesting(), server_config_, |
432 server_supported_versions_, &in_memory_cache_); | 432 server_supported_versions_, &response_cache_); |
433 server_thread_.reset(new ServerThread(test_server, server_address_)); | 433 server_thread_.reset(new ServerThread(test_server, server_address_)); |
434 if (chlo_multiplier_ != 0) { | 434 if (chlo_multiplier_ != 0) { |
435 server_thread_->server()->SetChloMultiplier(chlo_multiplier_); | 435 server_thread_->server()->SetChloMultiplier(chlo_multiplier_); |
436 } | 436 } |
437 server_thread_->Initialize(); | 437 server_thread_->Initialize(); |
438 server_address_ = | 438 server_address_ = |
439 QuicSocketAddress(server_address_.host(), server_thread_->GetPort()); | 439 QuicSocketAddress(server_address_.host(), server_thread_->GetPort()); |
440 QuicDispatcher* dispatcher = | 440 QuicDispatcher* dispatcher = |
441 QuicServerPeer::GetDispatcher(server_thread_->server()); | 441 QuicServerPeer::GetDispatcher(server_thread_->server()); |
442 QuicDispatcherPeer::UseWriter(dispatcher, server_writer_); | 442 QuicDispatcherPeer::UseWriter(dispatcher, server_writer_); |
(...skipping 16 matching lines...) Expand all Loading... |
459 void StopServer() { | 459 void StopServer() { |
460 if (!server_started_) | 460 if (!server_started_) |
461 return; | 461 return; |
462 if (server_thread_.get()) { | 462 if (server_thread_.get()) { |
463 server_thread_->Quit(); | 463 server_thread_->Quit(); |
464 server_thread_->Join(); | 464 server_thread_->Join(); |
465 } | 465 } |
466 } | 466 } |
467 | 467 |
468 void AddToCache(StringPiece path, int response_code, StringPiece body) { | 468 void AddToCache(StringPiece path, int response_code, StringPiece body) { |
469 in_memory_cache_.AddSimpleResponse(server_hostname_, path, response_code, | 469 response_cache_.AddSimpleResponse(server_hostname_, path, response_code, |
470 body); | 470 body); |
471 } | 471 } |
472 | 472 |
473 void SetPacketLossPercentage(int32_t loss) { | 473 void SetPacketLossPercentage(int32_t loss) { |
474 // TODO(rtenneti): enable when we can do random packet loss tests in | 474 // TODO(rtenneti): enable when we can do random packet loss tests in |
475 // chrome's tree. | 475 // chrome's tree. |
476 if (loss != 0 && loss != 100) | 476 if (loss != 0 && loss != 100) |
477 return; | 477 return; |
478 client_writer_->set_fake_packet_loss_percentage(loss); | 478 client_writer_->set_fake_packet_loss_percentage(loss); |
479 server_writer_->set_fake_packet_loss_percentage(loss); | 479 server_writer_->set_fake_packet_loss_percentage(loss); |
480 } | 480 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 | 550 |
551 // Must be called before Initialize to have effect. | 551 // Must be called before Initialize to have effect. |
552 void SetSpdyStreamFactory(QuicTestServer::StreamFactory* factory) { | 552 void SetSpdyStreamFactory(QuicTestServer::StreamFactory* factory) { |
553 stream_factory_ = factory; | 553 stream_factory_ = factory; |
554 } | 554 } |
555 | 555 |
556 QuicFlagSaver flags_; // Save/restore all QUIC flag values. | 556 QuicFlagSaver flags_; // Save/restore all QUIC flag values. |
557 bool initialized_; | 557 bool initialized_; |
558 QuicSocketAddress server_address_; | 558 QuicSocketAddress server_address_; |
559 string server_hostname_; | 559 string server_hostname_; |
560 QuicInMemoryCache in_memory_cache_; | 560 QuicHttpResponseCache response_cache_; |
561 std::unique_ptr<ServerThread> server_thread_; | 561 std::unique_ptr<ServerThread> server_thread_; |
562 std::unique_ptr<QuicTestClient> client_; | 562 std::unique_ptr<QuicTestClient> client_; |
563 PacketDroppingTestWriter* client_writer_; | 563 PacketDroppingTestWriter* client_writer_; |
564 PacketDroppingTestWriter* server_writer_; | 564 PacketDroppingTestWriter* server_writer_; |
565 bool server_started_; | 565 bool server_started_; |
566 QuicConfig client_config_; | 566 QuicConfig client_config_; |
567 QuicConfig server_config_; | 567 QuicConfig server_config_; |
568 QuicVersionVector client_supported_versions_; | 568 QuicVersionVector client_supported_versions_; |
569 QuicVersionVector server_supported_versions_; | 569 QuicVersionVector server_supported_versions_; |
570 QuicVersion negotiated_version_; | 570 QuicVersion negotiated_version_; |
571 size_t chlo_multiplier_; | 571 size_t chlo_multiplier_; |
572 QuicTestServer::StreamFactory* stream_factory_; | 572 QuicTestServer::StreamFactory* stream_factory_; |
573 bool support_server_push_; | 573 bool support_server_push_; |
574 bool force_hol_blocking_; | 574 bool force_hol_blocking_; |
575 }; | 575 }; |
576 | 576 |
577 // Run all end to end tests with all supported versions. | 577 // Run all end to end tests with all supported versions. |
578 INSTANTIATE_TEST_CASE_P(EndToEndTests, | 578 INSTANTIATE_TEST_CASE_P(EndToEndTests, |
579 EndToEndTest, | 579 EndToEndTest, |
580 ::testing::ValuesIn(GetTestParams())); | 580 ::testing::ValuesIn(GetTestParams())); |
581 | 581 |
582 TEST_P(EndToEndTest, HandshakeSuccessful) { | 582 TEST_P(EndToEndTest, HandshakeSuccessful) { |
583 ASSERT_TRUE(Initialize()); | 583 ASSERT_TRUE(Initialize()); |
584 client_->client()->WaitForCryptoHandshakeConfirmed(); | 584 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
585 QuicCryptoStream* crypto_stream = | 585 QuicCryptoStream* crypto_stream = |
586 QuicSessionPeer::GetCryptoStream(client_->client()->session()); | 586 QuicSessionPeer::GetCryptoStream(client_->client()->session()); |
587 QuicStreamSequencer* sequencer = QuicStreamPeer::sequencer(crypto_stream); | 587 QuicStreamSequencer* sequencer = QuicStreamPeer::sequencer(crypto_stream); |
588 EXPECT_NE(FLAGS_quic_release_crypto_stream_buffer, | 588 EXPECT_NE(FLAGS_quic_release_crypto_stream_buffer, |
589 QuicStreamSequencerPeer::IsUnderlyingBufferAllocated(sequencer)); | 589 QuicStreamSequencerPeer::IsUnderlyingBufferAllocated(sequencer)); |
590 server_thread_->Pause(); | 590 server_thread_->Pause(); |
591 QuicDispatcher* dispatcher = | 591 QuicDispatcher* dispatcher = |
592 QuicServerPeer::GetDispatcher(server_thread_->server()); | 592 QuicServerPeer::GetDispatcher(server_thread_->server()); |
593 QuicSession* server_session = dispatcher->session_map().begin()->second.get(); | 593 QuicSession* server_session = dispatcher->session_map().begin()->second.get(); |
594 crypto_stream = QuicSessionPeer::GetCryptoStream(server_session); | 594 crypto_stream = QuicSessionPeer::GetCryptoStream(server_session); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 // triggering an error response. | 722 // triggering an error response. |
723 client_->SendCustomSynchronousRequest(headers, ""); | 723 client_->SendCustomSynchronousRequest(headers, ""); |
724 EXPECT_EQ(QuicSimpleServerStream::kErrorResponseBody, | 724 EXPECT_EQ(QuicSimpleServerStream::kErrorResponseBody, |
725 client_->response_body()); | 725 client_->response_body()); |
726 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); | 726 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); |
727 } | 727 } |
728 | 728 |
729 TEST_P(EndToEndTest, LargePostNoPacketLoss) { | 729 TEST_P(EndToEndTest, LargePostNoPacketLoss) { |
730 ASSERT_TRUE(Initialize()); | 730 ASSERT_TRUE(Initialize()); |
731 | 731 |
732 client_->client()->WaitForCryptoHandshakeConfirmed(); | 732 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
733 | 733 |
734 // 1 MB body. | 734 // 1 MB body. |
735 string body; | 735 string body(1024 * 1024, 'a'); |
736 GenerateBody(&body, 1024 * 1024); | |
737 SpdyHeaderBlock headers; | 736 SpdyHeaderBlock headers; |
738 headers[":method"] = "POST"; | 737 headers[":method"] = "POST"; |
739 headers[":path"] = "/foo"; | 738 headers[":path"] = "/foo"; |
740 headers[":scheme"] = "https"; | 739 headers[":scheme"] = "https"; |
741 headers[":authority"] = server_hostname_; | 740 headers[":authority"] = server_hostname_; |
742 | 741 |
743 EXPECT_EQ(kFooResponseBody, | 742 EXPECT_EQ(kFooResponseBody, |
744 client_->SendCustomSynchronousRequest(headers, body)); | 743 client_->SendCustomSynchronousRequest(headers, body)); |
745 // TODO(ianswett): There should not be packet loss in this test, but on some | 744 // TODO(ianswett): There should not be packet loss in this test, but on some |
746 // platforms the receive buffer overflows. | 745 // platforms the receive buffer overflows. |
747 VerifyCleanConnection(true); | 746 VerifyCleanConnection(true); |
748 } | 747 } |
749 | 748 |
750 TEST_P(EndToEndTest, LargePostNoPacketLoss1sRTT) { | 749 TEST_P(EndToEndTest, LargePostNoPacketLoss1sRTT) { |
751 ASSERT_TRUE(Initialize()); | 750 ASSERT_TRUE(Initialize()); |
752 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(1000)); | 751 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(1000)); |
753 | 752 |
754 client_->client()->WaitForCryptoHandshakeConfirmed(); | 753 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
755 | 754 |
756 // 100 KB body. | 755 // 100 KB body. |
757 string body; | 756 string body(100 * 1024, 'a'); |
758 GenerateBody(&body, 100 * 1024); | |
759 SpdyHeaderBlock headers; | 757 SpdyHeaderBlock headers; |
760 headers[":method"] = "POST"; | 758 headers[":method"] = "POST"; |
761 headers[":path"] = "/foo"; | 759 headers[":path"] = "/foo"; |
762 headers[":scheme"] = "https"; | 760 headers[":scheme"] = "https"; |
763 headers[":authority"] = server_hostname_; | 761 headers[":authority"] = server_hostname_; |
764 | 762 |
765 EXPECT_EQ(kFooResponseBody, | 763 EXPECT_EQ(kFooResponseBody, |
766 client_->SendCustomSynchronousRequest(headers, body)); | 764 client_->SendCustomSynchronousRequest(headers, body)); |
767 VerifyCleanConnection(false); | 765 VerifyCleanConnection(false); |
768 } | 766 } |
769 | 767 |
770 TEST_P(EndToEndTest, LargePostWithPacketLoss) { | 768 TEST_P(EndToEndTest, LargePostWithPacketLoss) { |
771 if (!BothSidesSupportStatelessRejects()) { | 769 if (!BothSidesSupportStatelessRejects()) { |
772 // Connect with lower fake packet loss than we'd like to test. | 770 // Connect with lower fake packet loss than we'd like to test. |
773 // Until b/10126687 is fixed, losing handshake packets is pretty | 771 // Until b/10126687 is fixed, losing handshake packets is pretty |
774 // brutal. | 772 // brutal. |
775 // TODO(jokulik): Until we support redundant SREJ packets, don't | 773 // TODO(jokulik): Until we support redundant SREJ packets, don't |
776 // drop handshake packets for stateless rejects. | 774 // drop handshake packets for stateless rejects. |
777 SetPacketLossPercentage(5); | 775 SetPacketLossPercentage(5); |
778 } | 776 } |
779 ASSERT_TRUE(Initialize()); | 777 ASSERT_TRUE(Initialize()); |
780 | 778 |
781 // Wait for the server SHLO before upping the packet loss. | 779 // Wait for the server SHLO before upping the packet loss. |
782 client_->client()->WaitForCryptoHandshakeConfirmed(); | 780 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
783 SetPacketLossPercentage(30); | 781 SetPacketLossPercentage(30); |
784 | 782 |
785 // 10 KB body. | 783 // 10 KB body. |
786 string body; | 784 string body(1024 * 10, 'a'); |
787 GenerateBody(&body, 1024 * 10); | |
788 SpdyHeaderBlock headers; | 785 SpdyHeaderBlock headers; |
789 headers[":method"] = "POST"; | 786 headers[":method"] = "POST"; |
790 headers[":path"] = "/foo"; | 787 headers[":path"] = "/foo"; |
791 headers[":scheme"] = "https"; | 788 headers[":scheme"] = "https"; |
792 headers[":authority"] = server_hostname_; | 789 headers[":authority"] = server_hostname_; |
793 | 790 |
794 EXPECT_EQ(kFooResponseBody, | 791 EXPECT_EQ(kFooResponseBody, |
795 client_->SendCustomSynchronousRequest(headers, body)); | 792 client_->SendCustomSynchronousRequest(headers, body)); |
796 VerifyCleanConnection(true); | 793 VerifyCleanConnection(true); |
797 } | 794 } |
798 | 795 |
799 TEST_P(EndToEndTest, LargePostWithPacketLossAndBlockedSocket) { | 796 TEST_P(EndToEndTest, LargePostWithPacketLossAndBlockedSocket) { |
800 if (!BothSidesSupportStatelessRejects()) { | 797 if (!BothSidesSupportStatelessRejects()) { |
801 // Connect with lower fake packet loss than we'd like to test. Until | 798 // Connect with lower fake packet loss than we'd like to test. Until |
802 // b/10126687 is fixed, losing handshake packets is pretty brutal. | 799 // b/10126687 is fixed, losing handshake packets is pretty brutal. |
803 // TODO(jokulik): Until we support redundant SREJ packets, don't | 800 // TODO(jokulik): Until we support redundant SREJ packets, don't |
804 // drop handshake packets for stateless rejects. | 801 // drop handshake packets for stateless rejects. |
805 SetPacketLossPercentage(5); | 802 SetPacketLossPercentage(5); |
806 } | 803 } |
807 ASSERT_TRUE(Initialize()); | 804 ASSERT_TRUE(Initialize()); |
808 | 805 |
809 // Wait for the server SHLO before upping the packet loss. | 806 // Wait for the server SHLO before upping the packet loss. |
810 client_->client()->WaitForCryptoHandshakeConfirmed(); | 807 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
811 SetPacketLossPercentage(10); | 808 SetPacketLossPercentage(10); |
812 client_writer_->set_fake_blocked_socket_percentage(10); | 809 client_writer_->set_fake_blocked_socket_percentage(10); |
813 | 810 |
814 // 10 KB body. | 811 // 10 KB body. |
815 string body; | 812 string body(1024 * 10, 'a'); |
816 GenerateBody(&body, 1024 * 10); | |
817 SpdyHeaderBlock headers; | 813 SpdyHeaderBlock headers; |
818 headers[":method"] = "POST"; | 814 headers[":method"] = "POST"; |
819 headers[":path"] = "/foo"; | 815 headers[":path"] = "/foo"; |
820 headers[":scheme"] = "https"; | 816 headers[":scheme"] = "https"; |
821 headers[":authority"] = server_hostname_; | 817 headers[":authority"] = server_hostname_; |
822 | 818 |
823 EXPECT_EQ(kFooResponseBody, | 819 EXPECT_EQ(kFooResponseBody, |
824 client_->SendCustomSynchronousRequest(headers, body)); | 820 client_->SendCustomSynchronousRequest(headers, body)); |
825 } | 821 } |
826 | 822 |
827 TEST_P(EndToEndTest, LargePostNoPacketLossWithDelayAndReordering) { | 823 TEST_P(EndToEndTest, LargePostNoPacketLossWithDelayAndReordering) { |
828 ASSERT_TRUE(Initialize()); | 824 ASSERT_TRUE(Initialize()); |
829 | 825 |
830 client_->client()->WaitForCryptoHandshakeConfirmed(); | 826 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
831 // Both of these must be called when the writer is not actively used. | 827 // Both of these must be called when the writer is not actively used. |
832 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); | 828 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); |
833 SetReorderPercentage(30); | 829 SetReorderPercentage(30); |
834 | 830 |
835 // 1 MB body. | 831 // 1 MB body. |
836 string body; | 832 string body(1024 * 1024, 'a'); |
837 GenerateBody(&body, 1024 * 1024); | |
838 SpdyHeaderBlock headers; | 833 SpdyHeaderBlock headers; |
839 headers[":method"] = "POST"; | 834 headers[":method"] = "POST"; |
840 headers[":path"] = "/foo"; | 835 headers[":path"] = "/foo"; |
841 headers[":scheme"] = "https"; | 836 headers[":scheme"] = "https"; |
842 headers[":authority"] = server_hostname_; | 837 headers[":authority"] = server_hostname_; |
843 | 838 |
844 EXPECT_EQ(kFooResponseBody, | 839 EXPECT_EQ(kFooResponseBody, |
845 client_->SendCustomSynchronousRequest(headers, body)); | 840 client_->SendCustomSynchronousRequest(headers, body)); |
846 } | 841 } |
847 | 842 |
848 TEST_P(EndToEndTest, LargePostZeroRTTFailure) { | 843 TEST_P(EndToEndTest, LargePostZeroRTTFailure) { |
849 // Send a request and then disconnect. This prepares the client to attempt | 844 // Send a request and then disconnect. This prepares the client to attempt |
850 // a 0-RTT handshake for the next request. | 845 // a 0-RTT handshake for the next request. |
851 ASSERT_TRUE(Initialize()); | 846 ASSERT_TRUE(Initialize()); |
852 | 847 |
853 string body; | 848 string body(20480, 'a'); |
854 GenerateBody(&body, 20480); | |
855 SpdyHeaderBlock headers; | 849 SpdyHeaderBlock headers; |
856 headers[":method"] = "POST"; | 850 headers[":method"] = "POST"; |
857 headers[":path"] = "/foo"; | 851 headers[":path"] = "/foo"; |
858 headers[":scheme"] = "https"; | 852 headers[":scheme"] = "https"; |
859 headers[":authority"] = server_hostname_; | 853 headers[":authority"] = server_hostname_; |
860 | 854 |
861 EXPECT_EQ(kFooResponseBody, | 855 EXPECT_EQ(kFooResponseBody, |
862 client_->SendCustomSynchronousRequest(headers, body)); | 856 client_->SendCustomSynchronousRequest(headers, body)); |
863 // In the non-stateless case, the same session is used for both | 857 // In the non-stateless case, the same session is used for both |
864 // hellos, so the number of hellos sent on that session is 2. In | 858 // hellos, so the number of hellos sent on that session is 2. In |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 EXPECT_EQ(2, client_->client()->GetNumSentClientHellos()); | 948 EXPECT_EQ(2, client_->client()->GetNumSentClientHellos()); |
955 | 949 |
956 VerifyCleanConnection(false); | 950 VerifyCleanConnection(false); |
957 } | 951 } |
958 | 952 |
959 TEST_P(EndToEndTest, LargePostSynchronousRequest) { | 953 TEST_P(EndToEndTest, LargePostSynchronousRequest) { |
960 // Send a request and then disconnect. This prepares the client to attempt | 954 // Send a request and then disconnect. This prepares the client to attempt |
961 // a 0-RTT handshake for the next request. | 955 // a 0-RTT handshake for the next request. |
962 ASSERT_TRUE(Initialize()); | 956 ASSERT_TRUE(Initialize()); |
963 | 957 |
964 string body; | 958 string body(20480, 'a'); |
965 GenerateBody(&body, 20480); | |
966 SpdyHeaderBlock headers; | 959 SpdyHeaderBlock headers; |
967 headers[":method"] = "POST"; | 960 headers[":method"] = "POST"; |
968 headers[":path"] = "/foo"; | 961 headers[":path"] = "/foo"; |
969 headers[":scheme"] = "https"; | 962 headers[":scheme"] = "https"; |
970 headers[":authority"] = server_hostname_; | 963 headers[":authority"] = server_hostname_; |
971 | 964 |
972 EXPECT_EQ(kFooResponseBody, | 965 EXPECT_EQ(kFooResponseBody, |
973 client_->SendCustomSynchronousRequest(headers, body)); | 966 client_->SendCustomSynchronousRequest(headers, body)); |
974 // In the non-stateless case, the same session is used for both | 967 // In the non-stateless case, the same session is used for both |
975 // hellos, so the number of hellos sent on that session is 2. In | 968 // hellos, so the number of hellos sent on that session is 2. In |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 | 1020 |
1028 TEST_P(EndToEndTest, SetInitialReceivedConnectionOptions) { | 1021 TEST_P(EndToEndTest, SetInitialReceivedConnectionOptions) { |
1029 QuicTagVector initial_received_options; | 1022 QuicTagVector initial_received_options; |
1030 initial_received_options.push_back(kTBBR); | 1023 initial_received_options.push_back(kTBBR); |
1031 initial_received_options.push_back(kIW10); | 1024 initial_received_options.push_back(kIW10); |
1032 initial_received_options.push_back(kPRST); | 1025 initial_received_options.push_back(kPRST); |
1033 EXPECT_TRUE(server_config_.SetInitialReceivedConnectionOptions( | 1026 EXPECT_TRUE(server_config_.SetInitialReceivedConnectionOptions( |
1034 initial_received_options)); | 1027 initial_received_options)); |
1035 | 1028 |
1036 ASSERT_TRUE(Initialize()); | 1029 ASSERT_TRUE(Initialize()); |
1037 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1030 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1038 server_thread_->WaitForCryptoHandshakeConfirmed(); | 1031 server_thread_->WaitForCryptoHandshakeConfirmed(); |
1039 | 1032 |
1040 EXPECT_FALSE(server_config_.SetInitialReceivedConnectionOptions( | 1033 EXPECT_FALSE(server_config_.SetInitialReceivedConnectionOptions( |
1041 initial_received_options)); | 1034 initial_received_options)); |
1042 | 1035 |
1043 // Verify that server's configuration is correct. | 1036 // Verify that server's configuration is correct. |
1044 server_thread_->Pause(); | 1037 server_thread_->Pause(); |
1045 EXPECT_TRUE(server_config_.HasReceivedConnectionOptions()); | 1038 EXPECT_TRUE(server_config_.HasReceivedConnectionOptions()); |
1046 EXPECT_TRUE( | 1039 EXPECT_TRUE( |
1047 ContainsQuicTag(server_config_.ReceivedConnectionOptions(), kTBBR)); | 1040 ContainsQuicTag(server_config_.ReceivedConnectionOptions(), kTBBR)); |
1048 EXPECT_TRUE( | 1041 EXPECT_TRUE( |
1049 ContainsQuicTag(server_config_.ReceivedConnectionOptions(), kIW10)); | 1042 ContainsQuicTag(server_config_.ReceivedConnectionOptions(), kIW10)); |
1050 EXPECT_TRUE( | 1043 EXPECT_TRUE( |
1051 ContainsQuicTag(server_config_.ReceivedConnectionOptions(), kPRST)); | 1044 ContainsQuicTag(server_config_.ReceivedConnectionOptions(), kPRST)); |
1052 } | 1045 } |
1053 | 1046 |
1054 TEST_P(EndToEndTest, LargePostSmallBandwidthLargeBuffer) { | 1047 TEST_P(EndToEndTest, LargePostSmallBandwidthLargeBuffer) { |
1055 ASSERT_TRUE(Initialize()); | 1048 ASSERT_TRUE(Initialize()); |
1056 SetPacketSendDelay(QuicTime::Delta::FromMicroseconds(1)); | 1049 SetPacketSendDelay(QuicTime::Delta::FromMicroseconds(1)); |
1057 // 256KB per second with a 256KB buffer from server to client. Wireless | 1050 // 256KB per second with a 256KB buffer from server to client. Wireless |
1058 // clients commonly have larger buffers, but our max CWND is 200. | 1051 // clients commonly have larger buffers, but our max CWND is 200. |
1059 server_writer_->set_max_bandwidth_and_buffer_size( | 1052 server_writer_->set_max_bandwidth_and_buffer_size( |
1060 QuicBandwidth::FromBytesPerSecond(256 * 1024), 256 * 1024); | 1053 QuicBandwidth::FromBytesPerSecond(256 * 1024), 256 * 1024); |
1061 | 1054 |
1062 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1055 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1063 | 1056 |
1064 // 1 MB body. | 1057 // 1 MB body. |
1065 string body; | 1058 string body(1024 * 1024, 'a'); |
1066 GenerateBody(&body, 1024 * 1024); | |
1067 SpdyHeaderBlock headers; | 1059 SpdyHeaderBlock headers; |
1068 headers[":method"] = "POST"; | 1060 headers[":method"] = "POST"; |
1069 headers[":path"] = "/foo"; | 1061 headers[":path"] = "/foo"; |
1070 headers[":scheme"] = "https"; | 1062 headers[":scheme"] = "https"; |
1071 headers[":authority"] = server_hostname_; | 1063 headers[":authority"] = server_hostname_; |
1072 | 1064 |
1073 EXPECT_EQ(kFooResponseBody, | 1065 EXPECT_EQ(kFooResponseBody, |
1074 client_->SendCustomSynchronousRequest(headers, body)); | 1066 client_->SendCustomSynchronousRequest(headers, body)); |
1075 // This connection may drop packets, because the buffer is smaller than the | 1067 // This connection may drop packets, because the buffer is smaller than the |
1076 // max CWND. | 1068 // max CWND. |
1077 VerifyCleanConnection(true); | 1069 VerifyCleanConnection(true); |
1078 } | 1070 } |
1079 | 1071 |
1080 TEST_P(EndToEndTest, DoNotSetResumeWriteAlarmIfConnectionFlowControlBlocked) { | 1072 TEST_P(EndToEndTest, DoNotSetResumeWriteAlarmIfConnectionFlowControlBlocked) { |
1081 // Regression test for b/14677858. | 1073 // Regression test for b/14677858. |
1082 // Test that the resume write alarm is not set in QuicConnection::OnCanWrite | 1074 // Test that the resume write alarm is not set in QuicConnection::OnCanWrite |
1083 // if currently connection level flow control blocked. If set, this results in | 1075 // if currently connection level flow control blocked. If set, this results in |
1084 // an infinite loop in the EpollServer, as the alarm fires and is immediately | 1076 // an infinite loop in the EpollServer, as the alarm fires and is immediately |
1085 // rescheduled. | 1077 // rescheduled. |
1086 ASSERT_TRUE(Initialize()); | 1078 ASSERT_TRUE(Initialize()); |
1087 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1079 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1088 | 1080 |
1089 // Ensure both stream and connection level are flow control blocked by setting | 1081 // Ensure both stream and connection level are flow control blocked by setting |
1090 // the send window offset to 0. | 1082 // the send window offset to 0. |
1091 const uint64_t flow_control_window = | 1083 const uint64_t flow_control_window = |
1092 server_config_.GetInitialStreamFlowControlWindowToSend(); | 1084 server_config_.GetInitialStreamFlowControlWindowToSend(); |
1093 QuicSpdyClientStream* stream = client_->GetOrCreateStream(); | 1085 QuicSpdyClientStream* stream = client_->GetOrCreateStream(); |
1094 QuicSession* session = client_->client()->session(); | 1086 QuicSession* session = client_->client()->session(); |
1095 QuicFlowControllerPeer::SetSendWindowOffset(stream->flow_controller(), 0); | 1087 QuicFlowControllerPeer::SetSendWindowOffset(stream->flow_controller(), 0); |
1096 QuicFlowControllerPeer::SetSendWindowOffset(session->flow_controller(), 0); | 1088 QuicFlowControllerPeer::SetSendWindowOffset(session->flow_controller(), 0); |
1097 EXPECT_TRUE(stream->flow_controller()->IsBlocked()); | 1089 EXPECT_TRUE(stream->flow_controller()->IsBlocked()); |
(...skipping 14 matching lines...) Expand all Loading... |
1112 // connection is still flow control blocked. | 1104 // connection is still flow control blocked. |
1113 session->connection()->OnCanWrite(); | 1105 session->connection()->OnCanWrite(); |
1114 | 1106 |
1115 QuicAlarm* resume_writes_alarm = | 1107 QuicAlarm* resume_writes_alarm = |
1116 QuicConnectionPeer::GetResumeWritesAlarm(session->connection()); | 1108 QuicConnectionPeer::GetResumeWritesAlarm(session->connection()); |
1117 EXPECT_FALSE(resume_writes_alarm->IsSet()); | 1109 EXPECT_FALSE(resume_writes_alarm->IsSet()); |
1118 } | 1110 } |
1119 | 1111 |
1120 TEST_P(EndToEndTest, InvalidStream) { | 1112 TEST_P(EndToEndTest, InvalidStream) { |
1121 ASSERT_TRUE(Initialize()); | 1113 ASSERT_TRUE(Initialize()); |
1122 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1114 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1123 | 1115 |
1124 string body; | 1116 string body(kMaxPacketSize, 'a'); |
1125 GenerateBody(&body, kMaxPacketSize); | |
1126 SpdyHeaderBlock headers; | 1117 SpdyHeaderBlock headers; |
1127 headers[":method"] = "POST"; | 1118 headers[":method"] = "POST"; |
1128 headers[":path"] = "/foo"; | 1119 headers[":path"] = "/foo"; |
1129 headers[":scheme"] = "https"; | 1120 headers[":scheme"] = "https"; |
1130 headers[":authority"] = server_hostname_; | 1121 headers[":authority"] = server_hostname_; |
1131 | 1122 |
1132 // Force the client to write with a stream ID belonging to a nonexistent | 1123 // Force the client to write with a stream ID belonging to a nonexistent |
1133 // server-side stream. | 1124 // server-side stream. |
1134 QuicSessionPeer::SetNextOutgoingStreamId(client_->client()->session(), 2); | 1125 QuicSessionPeer::SetNextOutgoingStreamId(client_->client()->session(), 2); |
1135 | 1126 |
1136 client_->SendCustomSynchronousRequest(headers, body); | 1127 client_->SendCustomSynchronousRequest(headers, body); |
1137 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); | 1128 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); |
1138 EXPECT_EQ(QUIC_INVALID_STREAM_ID, client_->connection_error()); | 1129 EXPECT_EQ(QUIC_INVALID_STREAM_ID, client_->connection_error()); |
1139 } | 1130 } |
1140 | 1131 |
1141 // Test that if the the server will close the connection if the client attempts | 1132 // Test that if the the server will close the connection if the client attempts |
1142 // to send a request with overly large headers. | 1133 // to send a request with overly large headers. |
1143 TEST_P(EndToEndTest, LargeHeaders) { | 1134 TEST_P(EndToEndTest, LargeHeaders) { |
1144 ASSERT_TRUE(Initialize()); | 1135 ASSERT_TRUE(Initialize()); |
1145 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1136 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1146 | 1137 |
1147 string body; | 1138 string body(kMaxPacketSize, 'a'); |
1148 GenerateBody(&body, kMaxPacketSize); | |
1149 SpdyHeaderBlock headers; | 1139 SpdyHeaderBlock headers; |
1150 headers[":method"] = "POST"; | 1140 headers[":method"] = "POST"; |
1151 headers[":path"] = "/foo"; | 1141 headers[":path"] = "/foo"; |
1152 headers[":scheme"] = "https"; | 1142 headers[":scheme"] = "https"; |
1153 headers[":authority"] = server_hostname_; | 1143 headers[":authority"] = server_hostname_; |
1154 headers["key1"] = string(15 * 1024, 'a'); | 1144 headers["key1"] = string(15 * 1024, 'a'); |
1155 headers["key2"] = string(15 * 1024, 'a'); | 1145 headers["key2"] = string(15 * 1024, 'a'); |
1156 headers["key3"] = string(15 * 1024, 'a'); | 1146 headers["key3"] = string(15 * 1024, 'a'); |
1157 | 1147 |
1158 client_->SendCustomSynchronousRequest(headers, body); | 1148 client_->SendCustomSynchronousRequest(headers, body); |
1159 if (FLAGS_quic_limit_uncompressed_headers) { | 1149 if (FLAGS_quic_limit_uncompressed_headers) { |
1160 EXPECT_EQ(QUIC_HEADERS_TOO_LARGE, client_->stream_error()); | 1150 EXPECT_EQ(QUIC_HEADERS_TOO_LARGE, client_->stream_error()); |
1161 } else { | 1151 } else { |
1162 EXPECT_EQ(QUIC_STREAM_NO_ERROR, client_->stream_error()); | 1152 EXPECT_EQ(QUIC_STREAM_NO_ERROR, client_->stream_error()); |
1163 EXPECT_EQ(kFooResponseBody, client_->response_body()); | 1153 EXPECT_EQ(kFooResponseBody, client_->response_body()); |
1164 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); | 1154 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
1165 } | 1155 } |
1166 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); | 1156 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); |
1167 } | 1157 } |
1168 | 1158 |
1169 TEST_P(EndToEndTest, EarlyResponseWithQuicStreamNoError) { | 1159 TEST_P(EndToEndTest, EarlyResponseWithQuicStreamNoError) { |
1170 ASSERT_TRUE(Initialize()); | 1160 ASSERT_TRUE(Initialize()); |
1171 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1161 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1172 | 1162 |
1173 string large_body; | 1163 string large_body(1024 * 1024, 'a'); |
1174 GenerateBody(&large_body, 1024 * 1024); | |
1175 SpdyHeaderBlock headers; | 1164 SpdyHeaderBlock headers; |
1176 headers[":method"] = "POST"; | 1165 headers[":method"] = "POST"; |
1177 headers[":path"] = "/foo"; | 1166 headers[":path"] = "/foo"; |
1178 headers[":scheme"] = "https"; | 1167 headers[":scheme"] = "https"; |
1179 headers[":authority"] = server_hostname_; | 1168 headers[":authority"] = server_hostname_; |
1180 // Insert an invalid content_length field in request to trigger an early | 1169 // Insert an invalid content_length field in request to trigger an early |
1181 // response from server. | 1170 // response from server. |
1182 headers["content-length"] = "-3"; | 1171 headers["content-length"] = "-3"; |
1183 | 1172 |
1184 client_->SendCustomSynchronousRequest(headers, large_body); | 1173 client_->SendCustomSynchronousRequest(headers, large_body); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 Initialize(); | 1206 Initialize(); |
1218 while (client_->client()->connected()) { | 1207 while (client_->client()->connected()) { |
1219 client_->client()->WaitForEvents(); | 1208 client_->client()->WaitForEvents(); |
1220 } | 1209 } |
1221 } | 1210 } |
1222 | 1211 |
1223 TEST_P(EndToEndTest, NegotiateMaxOpenStreams) { | 1212 TEST_P(EndToEndTest, NegotiateMaxOpenStreams) { |
1224 // Negotiate 1 max open stream. | 1213 // Negotiate 1 max open stream. |
1225 client_config_.SetMaxStreamsPerConnection(1, 1); | 1214 client_config_.SetMaxStreamsPerConnection(1, 1); |
1226 ASSERT_TRUE(Initialize()); | 1215 ASSERT_TRUE(Initialize()); |
1227 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1216 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1228 | 1217 |
1229 if (negotiated_version_ > QUIC_VERSION_34) { | 1218 if (negotiated_version_ > QUIC_VERSION_34) { |
1230 // Newer versions use max incoming dynamic streams. | 1219 // Newer versions use max incoming dynamic streams. |
1231 return; | 1220 return; |
1232 } | 1221 } |
1233 | 1222 |
1234 // Make the client misbehave after negotiation. | 1223 // Make the client misbehave after negotiation. |
1235 const int kServerMaxStreams = kMaxStreamsMinimumIncrement + 1; | 1224 const int kServerMaxStreams = kMaxStreamsMinimumIncrement + 1; |
1236 QuicSessionPeer::SetMaxOpenOutgoingStreams(client_->client()->session(), | 1225 QuicSessionPeer::SetMaxOpenOutgoingStreams(client_->client()->session(), |
1237 kServerMaxStreams + 1); | 1226 kServerMaxStreams + 1); |
(...skipping 17 matching lines...) Expand all Loading... |
1255 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); | 1244 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); |
1256 } | 1245 } |
1257 | 1246 |
1258 TEST_P(EndToEndTest, MaxIncomingDynamicStreamsLimitRespected) { | 1247 TEST_P(EndToEndTest, MaxIncomingDynamicStreamsLimitRespected) { |
1259 // Set a limit on maximum number of incoming dynamic streams. | 1248 // Set a limit on maximum number of incoming dynamic streams. |
1260 // Make sure the limit is respected. | 1249 // Make sure the limit is respected. |
1261 const uint32_t kServerMaxIncomingDynamicStreams = 1; | 1250 const uint32_t kServerMaxIncomingDynamicStreams = 1; |
1262 server_config_.SetMaxIncomingDynamicStreamsToSend( | 1251 server_config_.SetMaxIncomingDynamicStreamsToSend( |
1263 kServerMaxIncomingDynamicStreams); | 1252 kServerMaxIncomingDynamicStreams); |
1264 ASSERT_TRUE(Initialize()); | 1253 ASSERT_TRUE(Initialize()); |
1265 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1254 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1266 | 1255 |
1267 if (negotiated_version_ <= QUIC_VERSION_34) { | 1256 if (negotiated_version_ <= QUIC_VERSION_34) { |
1268 // Earlier versions negotiated max open streams. | 1257 // Earlier versions negotiated max open streams. |
1269 return; | 1258 return; |
1270 } | 1259 } |
1271 | 1260 |
1272 // Make the client misbehave after negotiation. | 1261 // Make the client misbehave after negotiation. |
1273 const int kServerMaxStreams = | 1262 const int kServerMaxStreams = |
1274 kMaxStreamsMinimumIncrement + kServerMaxIncomingDynamicStreams; | 1263 kMaxStreamsMinimumIncrement + kServerMaxIncomingDynamicStreams; |
1275 QuicSessionPeer::SetMaxOpenOutgoingStreams(client_->client()->session(), | 1264 QuicSessionPeer::SetMaxOpenOutgoingStreams(client_->client()->session(), |
(...skipping 20 matching lines...) Expand all Loading... |
1296 | 1285 |
1297 TEST_P(EndToEndTest, SetIndependentMaxIncomingDynamicStreamsLimits) { | 1286 TEST_P(EndToEndTest, SetIndependentMaxIncomingDynamicStreamsLimits) { |
1298 // Each endpoint can set max incoming dynamic streams independently. | 1287 // Each endpoint can set max incoming dynamic streams independently. |
1299 const uint32_t kClientMaxIncomingDynamicStreams = 2; | 1288 const uint32_t kClientMaxIncomingDynamicStreams = 2; |
1300 const uint32_t kServerMaxIncomingDynamicStreams = 1; | 1289 const uint32_t kServerMaxIncomingDynamicStreams = 1; |
1301 client_config_.SetMaxIncomingDynamicStreamsToSend( | 1290 client_config_.SetMaxIncomingDynamicStreamsToSend( |
1302 kClientMaxIncomingDynamicStreams); | 1291 kClientMaxIncomingDynamicStreams); |
1303 server_config_.SetMaxIncomingDynamicStreamsToSend( | 1292 server_config_.SetMaxIncomingDynamicStreamsToSend( |
1304 kServerMaxIncomingDynamicStreams); | 1293 kServerMaxIncomingDynamicStreams); |
1305 ASSERT_TRUE(Initialize()); | 1294 ASSERT_TRUE(Initialize()); |
1306 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1295 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1307 | 1296 |
1308 if (negotiated_version_ <= QUIC_VERSION_34) { | 1297 if (negotiated_version_ <= QUIC_VERSION_34) { |
1309 // Earlier versions negotiated max open streams. | 1298 // Earlier versions negotiated max open streams. |
1310 return; | 1299 return; |
1311 } | 1300 } |
1312 | 1301 |
1313 // The client has received the server's limit and vice versa. | 1302 // The client has received the server's limit and vice versa. |
1314 EXPECT_EQ(kServerMaxIncomingDynamicStreams, | 1303 EXPECT_EQ(kServerMaxIncomingDynamicStreams, |
1315 client_->client()->session()->max_open_outgoing_streams()); | 1304 client_->client()->session()->max_open_outgoing_streams()); |
1316 server_thread_->Pause(); | 1305 server_thread_->Pause(); |
1317 QuicDispatcher* dispatcher = | 1306 QuicDispatcher* dispatcher = |
1318 QuicServerPeer::GetDispatcher(server_thread_->server()); | 1307 QuicServerPeer::GetDispatcher(server_thread_->server()); |
1319 QuicSession* server_session = dispatcher->session_map().begin()->second.get(); | 1308 QuicSession* server_session = dispatcher->session_map().begin()->second.get(); |
1320 EXPECT_EQ(kClientMaxIncomingDynamicStreams, | 1309 EXPECT_EQ(kClientMaxIncomingDynamicStreams, |
1321 server_session->max_open_outgoing_streams()); | 1310 server_session->max_open_outgoing_streams()); |
1322 server_thread_->Resume(); | 1311 server_thread_->Resume(); |
1323 } | 1312 } |
1324 | 1313 |
1325 TEST_P(EndToEndTest, NegotiateCongestionControl) { | 1314 TEST_P(EndToEndTest, NegotiateCongestionControl) { |
1326 FLAGS_quic_allow_new_bbr = true; | 1315 FLAGS_quic_allow_new_bbr = true; |
1327 // Disable this flag because if connection uses multipath sent packet manager, | 1316 // Disable this flag because if connection uses multipath sent packet manager, |
1328 // static_cast here does not work. | 1317 // static_cast here does not work. |
1329 FLAGS_quic_enable_multipath = false; | 1318 FLAGS_quic_enable_multipath = false; |
1330 ASSERT_TRUE(Initialize()); | 1319 ASSERT_TRUE(Initialize()); |
1331 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1320 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1332 | 1321 |
1333 CongestionControlType expected_congestion_control_type = kReno; | 1322 CongestionControlType expected_congestion_control_type = kReno; |
1334 switch (GetParam().congestion_control_tag) { | 1323 switch (GetParam().congestion_control_tag) { |
1335 case kRENO: | 1324 case kRENO: |
1336 expected_congestion_control_type = kReno; | 1325 expected_congestion_control_type = kReno; |
1337 break; | 1326 break; |
1338 case kTBBR: | 1327 case kTBBR: |
1339 expected_congestion_control_type = kBBR; | 1328 expected_congestion_control_type = kBBR; |
1340 break; | 1329 break; |
1341 case kQBIC: | 1330 case kQBIC: |
(...skipping 13 matching lines...) Expand all Loading... |
1355 server_thread_->Resume(); | 1344 server_thread_->Resume(); |
1356 } | 1345 } |
1357 | 1346 |
1358 TEST_P(EndToEndTest, LimitMaxOpenStreams) { | 1347 TEST_P(EndToEndTest, LimitMaxOpenStreams) { |
1359 // Server limits the number of max streams to 2. | 1348 // Server limits the number of max streams to 2. |
1360 server_config_.SetMaxStreamsPerConnection(2, 2); | 1349 server_config_.SetMaxStreamsPerConnection(2, 2); |
1361 // Client tries to negotiate for 10. | 1350 // Client tries to negotiate for 10. |
1362 client_config_.SetMaxStreamsPerConnection(10, 5); | 1351 client_config_.SetMaxStreamsPerConnection(10, 5); |
1363 | 1352 |
1364 ASSERT_TRUE(Initialize()); | 1353 ASSERT_TRUE(Initialize()); |
1365 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1354 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1366 if (negotiated_version_ > QUIC_VERSION_34) { | 1355 if (negotiated_version_ > QUIC_VERSION_34) { |
1367 // No negotiated max streams beyond version 34. | 1356 // No negotiated max streams beyond version 34. |
1368 return; | 1357 return; |
1369 } | 1358 } |
1370 QuicConfig* client_negotiated_config = client_->client()->session()->config(); | 1359 QuicConfig* client_negotiated_config = client_->client()->session()->config(); |
1371 EXPECT_EQ(2u, client_negotiated_config->MaxStreamsPerConnection()); | 1360 EXPECT_EQ(2u, client_negotiated_config->MaxStreamsPerConnection()); |
1372 } | 1361 } |
1373 | 1362 |
1374 TEST_P(EndToEndTest, ClientSuggestsRTT) { | 1363 TEST_P(EndToEndTest, ClientSuggestsRTT) { |
1375 // Client suggests initial RTT, verify it is used. | 1364 // Client suggests initial RTT, verify it is used. |
1376 const uint32_t kInitialRTT = 20000; | 1365 const uint32_t kInitialRTT = 20000; |
1377 client_config_.SetInitialRoundTripTimeUsToSend(kInitialRTT); | 1366 client_config_.SetInitialRoundTripTimeUsToSend(kInitialRTT); |
1378 | 1367 |
1379 ASSERT_TRUE(Initialize()); | 1368 ASSERT_TRUE(Initialize()); |
1380 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1369 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1381 server_thread_->WaitForCryptoHandshakeConfirmed(); | 1370 server_thread_->WaitForCryptoHandshakeConfirmed(); |
1382 | 1371 |
1383 // Pause the server so we can access the server's internals without races. | 1372 // Pause the server so we can access the server's internals without races. |
1384 server_thread_->Pause(); | 1373 server_thread_->Pause(); |
1385 QuicDispatcher* dispatcher = | 1374 QuicDispatcher* dispatcher = |
1386 QuicServerPeer::GetDispatcher(server_thread_->server()); | 1375 QuicServerPeer::GetDispatcher(server_thread_->server()); |
1387 ASSERT_EQ(1u, dispatcher->session_map().size()); | 1376 ASSERT_EQ(1u, dispatcher->session_map().size()); |
1388 const QuicSentPacketManagerInterface& client_sent_packet_manager = | 1377 const QuicSentPacketManagerInterface& client_sent_packet_manager = |
1389 client_->client()->session()->connection()->sent_packet_manager(); | 1378 client_->client()->session()->connection()->sent_packet_manager(); |
1390 const QuicSentPacketManagerInterface* server_sent_packet_manager = | 1379 const QuicSentPacketManagerInterface* server_sent_packet_manager = |
1391 GetSentPacketManagerFromFirstServerSession(); | 1380 GetSentPacketManagerFromFirstServerSession(); |
1392 | 1381 |
1393 EXPECT_EQ(kInitialRTT, | 1382 EXPECT_EQ(kInitialRTT, |
1394 client_sent_packet_manager.GetRttStats()->initial_rtt_us()); | 1383 client_sent_packet_manager.GetRttStats()->initial_rtt_us()); |
1395 EXPECT_EQ(kInitialRTT, | 1384 EXPECT_EQ(kInitialRTT, |
1396 server_sent_packet_manager->GetRttStats()->initial_rtt_us()); | 1385 server_sent_packet_manager->GetRttStats()->initial_rtt_us()); |
1397 server_thread_->Resume(); | 1386 server_thread_->Resume(); |
1398 } | 1387 } |
1399 | 1388 |
1400 TEST_P(EndToEndTest, MaxInitialRTT) { | 1389 TEST_P(EndToEndTest, MaxInitialRTT) { |
1401 // Client tries to suggest twice the server's max initial rtt and the server | 1390 // Client tries to suggest twice the server's max initial rtt and the server |
1402 // uses the max. | 1391 // uses the max. |
1403 client_config_.SetInitialRoundTripTimeUsToSend(2 * | 1392 client_config_.SetInitialRoundTripTimeUsToSend(2 * |
1404 kMaxInitialRoundTripTimeUs); | 1393 kMaxInitialRoundTripTimeUs); |
1405 | 1394 |
1406 ASSERT_TRUE(Initialize()); | 1395 ASSERT_TRUE(Initialize()); |
1407 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1396 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1408 server_thread_->WaitForCryptoHandshakeConfirmed(); | 1397 server_thread_->WaitForCryptoHandshakeConfirmed(); |
1409 | 1398 |
1410 // Pause the server so we can access the server's internals without races. | 1399 // Pause the server so we can access the server's internals without races. |
1411 server_thread_->Pause(); | 1400 server_thread_->Pause(); |
1412 QuicDispatcher* dispatcher = | 1401 QuicDispatcher* dispatcher = |
1413 QuicServerPeer::GetDispatcher(server_thread_->server()); | 1402 QuicServerPeer::GetDispatcher(server_thread_->server()); |
1414 ASSERT_EQ(1u, dispatcher->session_map().size()); | 1403 ASSERT_EQ(1u, dispatcher->session_map().size()); |
1415 QuicSession* session = dispatcher->session_map().begin()->second.get(); | 1404 QuicSession* session = dispatcher->session_map().begin()->second.get(); |
1416 const QuicSentPacketManagerInterface& client_sent_packet_manager = | 1405 const QuicSentPacketManagerInterface& client_sent_packet_manager = |
1417 client_->client()->session()->connection()->sent_packet_manager(); | 1406 client_->client()->session()->connection()->sent_packet_manager(); |
1418 | 1407 |
1419 // Now that acks have been exchanged, the RTT estimate has decreased on the | 1408 // Now that acks have been exchanged, the RTT estimate has decreased on the |
1420 // server and is not infinite on the client. | 1409 // server and is not infinite on the client. |
1421 EXPECT_FALSE( | 1410 EXPECT_FALSE( |
1422 client_sent_packet_manager.GetRttStats()->smoothed_rtt().IsInfinite()); | 1411 client_sent_packet_manager.GetRttStats()->smoothed_rtt().IsInfinite()); |
1423 const RttStats& server_rtt_stats = | 1412 const RttStats& server_rtt_stats = |
1424 *session->connection()->sent_packet_manager().GetRttStats(); | 1413 *session->connection()->sent_packet_manager().GetRttStats(); |
1425 EXPECT_EQ(static_cast<int64_t>(kMaxInitialRoundTripTimeUs), | 1414 EXPECT_EQ(static_cast<int64_t>(kMaxInitialRoundTripTimeUs), |
1426 server_rtt_stats.initial_rtt_us()); | 1415 server_rtt_stats.initial_rtt_us()); |
1427 EXPECT_GE(static_cast<int64_t>(kMaxInitialRoundTripTimeUs), | 1416 EXPECT_GE(static_cast<int64_t>(kMaxInitialRoundTripTimeUs), |
1428 server_rtt_stats.smoothed_rtt().ToMicroseconds()); | 1417 server_rtt_stats.smoothed_rtt().ToMicroseconds()); |
1429 server_thread_->Resume(); | 1418 server_thread_->Resume(); |
1430 } | 1419 } |
1431 | 1420 |
1432 TEST_P(EndToEndTest, MinInitialRTT) { | 1421 TEST_P(EndToEndTest, MinInitialRTT) { |
1433 // Client tries to suggest 0 and the server uses the default. | 1422 // Client tries to suggest 0 and the server uses the default. |
1434 client_config_.SetInitialRoundTripTimeUsToSend(0); | 1423 client_config_.SetInitialRoundTripTimeUsToSend(0); |
1435 | 1424 |
1436 ASSERT_TRUE(Initialize()); | 1425 ASSERT_TRUE(Initialize()); |
1437 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1426 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1438 server_thread_->WaitForCryptoHandshakeConfirmed(); | 1427 server_thread_->WaitForCryptoHandshakeConfirmed(); |
1439 | 1428 |
1440 // Pause the server so we can access the server's internals without races. | 1429 // Pause the server so we can access the server's internals without races. |
1441 server_thread_->Pause(); | 1430 server_thread_->Pause(); |
1442 QuicDispatcher* dispatcher = | 1431 QuicDispatcher* dispatcher = |
1443 QuicServerPeer::GetDispatcher(server_thread_->server()); | 1432 QuicServerPeer::GetDispatcher(server_thread_->server()); |
1444 ASSERT_EQ(1u, dispatcher->session_map().size()); | 1433 ASSERT_EQ(1u, dispatcher->session_map().size()); |
1445 QuicSession* session = dispatcher->session_map().begin()->second.get(); | 1434 QuicSession* session = dispatcher->session_map().begin()->second.get(); |
1446 const QuicSentPacketManagerInterface& client_sent_packet_manager = | 1435 const QuicSentPacketManagerInterface& client_sent_packet_manager = |
1447 client_->client()->session()->connection()->sent_packet_manager(); | 1436 client_->client()->session()->connection()->sent_packet_manager(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1511 | 1500 |
1512 TEST_P(EndToEndTest, MaxStreamsUberTest) { | 1501 TEST_P(EndToEndTest, MaxStreamsUberTest) { |
1513 if (!BothSidesSupportStatelessRejects()) { | 1502 if (!BothSidesSupportStatelessRejects()) { |
1514 // Connect with lower fake packet loss than we'd like to test. Until | 1503 // Connect with lower fake packet loss than we'd like to test. Until |
1515 // b/10126687 is fixed, losing handshake packets is pretty brutal. | 1504 // b/10126687 is fixed, losing handshake packets is pretty brutal. |
1516 // TODO(jokulik): Until we support redundant SREJ packets, don't | 1505 // TODO(jokulik): Until we support redundant SREJ packets, don't |
1517 // drop handshake packets for stateless rejects. | 1506 // drop handshake packets for stateless rejects. |
1518 SetPacketLossPercentage(1); | 1507 SetPacketLossPercentage(1); |
1519 } | 1508 } |
1520 ASSERT_TRUE(Initialize()); | 1509 ASSERT_TRUE(Initialize()); |
1521 string large_body; | 1510 string large_body(10240, 'a'); |
1522 GenerateBody(&large_body, 10240); | |
1523 int max_streams = 100; | 1511 int max_streams = 100; |
1524 | 1512 |
1525 AddToCache("/large_response", 200, large_body); | 1513 AddToCache("/large_response", 200, large_body); |
1526 | 1514 |
1527 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1515 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1528 SetPacketLossPercentage(10); | 1516 SetPacketLossPercentage(10); |
1529 | 1517 |
1530 for (int i = 0; i < max_streams; ++i) { | 1518 for (int i = 0; i < max_streams; ++i) { |
1531 EXPECT_LT(0, client_->SendRequest("/large_response")); | 1519 EXPECT_LT(0, client_->SendRequest("/large_response")); |
1532 } | 1520 } |
1533 | 1521 |
1534 // WaitForEvents waits 50ms and returns true if there are outstanding | 1522 // WaitForEvents waits 50ms and returns true if there are outstanding |
1535 // requests. | 1523 // requests. |
1536 while (client_->client()->WaitForEvents() == true) { | 1524 while (client_->client()->WaitForEvents() == true) { |
1537 } | 1525 } |
1538 } | 1526 } |
1539 | 1527 |
1540 TEST_P(EndToEndTest, StreamCancelErrorTest) { | 1528 TEST_P(EndToEndTest, StreamCancelErrorTest) { |
1541 ASSERT_TRUE(Initialize()); | 1529 ASSERT_TRUE(Initialize()); |
1542 string small_body; | 1530 string small_body(256, 'a'); |
1543 GenerateBody(&small_body, 256); | |
1544 | 1531 |
1545 AddToCache("/small_response", 200, small_body); | 1532 AddToCache("/small_response", 200, small_body); |
1546 | 1533 |
1547 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1534 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1548 | 1535 |
1549 QuicSession* session = client_->client()->session(); | 1536 QuicSession* session = client_->client()->session(); |
1550 // Lose the request. | 1537 // Lose the request. |
1551 SetPacketLossPercentage(100); | 1538 SetPacketLossPercentage(100); |
1552 EXPECT_LT(0, client_->SendRequest("/small_response")); | 1539 EXPECT_LT(0, client_->SendRequest("/small_response")); |
1553 client_->client()->WaitForEvents(); | 1540 client_->client()->WaitForEvents(); |
1554 // Transmit the cancel, and ensure the connection is torn down properly. | 1541 // Transmit the cancel, and ensure the connection is torn down properly. |
1555 SetPacketLossPercentage(0); | 1542 SetPacketLossPercentage(0); |
1556 QuicStreamId stream_id = kClientDataStreamId1; | 1543 QuicStreamId stream_id = kClientDataStreamId1; |
1557 session->SendRstStream(stream_id, QUIC_STREAM_CANCELLED, 0); | 1544 session->SendRstStream(stream_id, QUIC_STREAM_CANCELLED, 0); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1665 set_client_initial_session_flow_control_receive_window(kClientSessionIFCW); | 1652 set_client_initial_session_flow_control_receive_window(kClientSessionIFCW); |
1666 | 1653 |
1667 uint32_t kServerStreamIFCW = 32 * 1024; | 1654 uint32_t kServerStreamIFCW = 32 * 1024; |
1668 uint32_t kServerSessionIFCW = 48 * 1024; | 1655 uint32_t kServerSessionIFCW = 48 * 1024; |
1669 set_server_initial_stream_flow_control_receive_window(kServerStreamIFCW); | 1656 set_server_initial_stream_flow_control_receive_window(kServerStreamIFCW); |
1670 set_server_initial_session_flow_control_receive_window(kServerSessionIFCW); | 1657 set_server_initial_session_flow_control_receive_window(kServerSessionIFCW); |
1671 | 1658 |
1672 ASSERT_TRUE(Initialize()); | 1659 ASSERT_TRUE(Initialize()); |
1673 | 1660 |
1674 // Values are exchanged during crypto handshake, so wait for that to finish. | 1661 // Values are exchanged during crypto handshake, so wait for that to finish. |
1675 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1662 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1676 server_thread_->WaitForCryptoHandshakeConfirmed(); | 1663 server_thread_->WaitForCryptoHandshakeConfirmed(); |
1677 | 1664 |
1678 // Open a data stream to make sure the stream level flow control is updated. | 1665 // Open a data stream to make sure the stream level flow control is updated. |
1679 QuicSpdyClientStream* stream = client_->GetOrCreateStream(); | 1666 QuicSpdyClientStream* stream = client_->GetOrCreateStream(); |
1680 stream->WriteOrBufferBody("hello", false, nullptr); | 1667 stream->WriteOrBufferBody("hello", false, nullptr); |
1681 | 1668 |
1682 // Client should have the right values for server's receive window. | 1669 // Client should have the right values for server's receive window. |
1683 EXPECT_EQ(kServerStreamIFCW, | 1670 EXPECT_EQ(kServerStreamIFCW, |
1684 client_->client() | 1671 client_->client() |
1685 ->session() | 1672 ->session() |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1718 set_client_initial_stream_flow_control_receive_window(kStreamIFCW); | 1705 set_client_initial_stream_flow_control_receive_window(kStreamIFCW); |
1719 set_client_initial_session_flow_control_receive_window(kSessionIFCW); | 1706 set_client_initial_session_flow_control_receive_window(kSessionIFCW); |
1720 set_server_initial_stream_flow_control_receive_window(kStreamIFCW); | 1707 set_server_initial_stream_flow_control_receive_window(kStreamIFCW); |
1721 set_server_initial_session_flow_control_receive_window(kSessionIFCW); | 1708 set_server_initial_session_flow_control_receive_window(kSessionIFCW); |
1722 | 1709 |
1723 ASSERT_TRUE(Initialize()); | 1710 ASSERT_TRUE(Initialize()); |
1724 | 1711 |
1725 // Wait for crypto handshake to finish. This should have contributed to the | 1712 // Wait for crypto handshake to finish. This should have contributed to the |
1726 // crypto stream flow control window, but not affected the session flow | 1713 // crypto stream flow control window, but not affected the session flow |
1727 // control window. | 1714 // control window. |
1728 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1715 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1729 server_thread_->WaitForCryptoHandshakeConfirmed(); | 1716 server_thread_->WaitForCryptoHandshakeConfirmed(); |
1730 | 1717 |
1731 QuicCryptoStream* crypto_stream = | 1718 QuicCryptoStream* crypto_stream = |
1732 QuicSessionPeer::GetCryptoStream(client_->client()->session()); | 1719 QuicSessionPeer::GetCryptoStream(client_->client()->session()); |
1733 EXPECT_LT( | 1720 EXPECT_LT( |
1734 QuicFlowControllerPeer::SendWindowSize(crypto_stream->flow_controller()), | 1721 QuicFlowControllerPeer::SendWindowSize(crypto_stream->flow_controller()), |
1735 kStreamIFCW); | 1722 kStreamIFCW); |
1736 EXPECT_EQ(kSessionIFCW, QuicFlowControllerPeer::SendWindowSize( | 1723 EXPECT_EQ(kSessionIFCW, QuicFlowControllerPeer::SendWindowSize( |
1737 client_->client()->session()->flow_controller())); | 1724 client_->client()->session()->flow_controller())); |
1738 | 1725 |
(...skipping 22 matching lines...) Expand all Loading... |
1761 EXPECT_EQ(kSessionIFCW, QuicFlowControllerPeer::ReceiveWindowSize( | 1748 EXPECT_EQ(kSessionIFCW, QuicFlowControllerPeer::ReceiveWindowSize( |
1762 server_connection_flow_controller)); | 1749 server_connection_flow_controller)); |
1763 server_thread_->Resume(); | 1750 server_thread_->Resume(); |
1764 } | 1751 } |
1765 | 1752 |
1766 TEST_P(EndToEndTest, FlowControlsSynced) { | 1753 TEST_P(EndToEndTest, FlowControlsSynced) { |
1767 set_smaller_flow_control_receive_window(); | 1754 set_smaller_flow_control_receive_window(); |
1768 | 1755 |
1769 ASSERT_TRUE(Initialize()); | 1756 ASSERT_TRUE(Initialize()); |
1770 | 1757 |
1771 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1758 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1772 server_thread_->WaitForCryptoHandshakeConfirmed(); | 1759 server_thread_->WaitForCryptoHandshakeConfirmed(); |
1773 | 1760 |
1774 server_thread_->Pause(); | 1761 server_thread_->Pause(); |
1775 QuicSpdySession* const client_session = client_->client()->session(); | 1762 QuicSpdySession* const client_session = client_->client()->session(); |
1776 QuicDispatcher* dispatcher = | 1763 QuicDispatcher* dispatcher = |
1777 QuicServerPeer::GetDispatcher(server_thread_->server()); | 1764 QuicServerPeer::GetDispatcher(server_thread_->server()); |
1778 auto server_session = static_cast<QuicSpdySession*>( | 1765 auto server_session = static_cast<QuicSpdySession*>( |
1779 dispatcher->session_map().begin()->second.get()); | 1766 dispatcher->session_map().begin()->second.get()); |
1780 | 1767 |
1781 ExpectFlowControlsSynced(client_session->flow_controller(), | 1768 ExpectFlowControlsSynced(client_session->flow_controller(), |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1861 // interested in has been ACKed. This tests end-to-end ACK notification, and | 1848 // interested in has been ACKed. This tests end-to-end ACK notification, and |
1862 // demonstrates that retransmissions do not break this functionality. | 1849 // demonstrates that retransmissions do not break this functionality. |
1863 if (!BothSidesSupportStatelessRejects()) { | 1850 if (!BothSidesSupportStatelessRejects()) { |
1864 // TODO(jokulik): Until we support redundant SREJ packets, don't | 1851 // TODO(jokulik): Until we support redundant SREJ packets, don't |
1865 // drop handshake packets for stateless rejects. | 1852 // drop handshake packets for stateless rejects. |
1866 SetPacketLossPercentage(5); | 1853 SetPacketLossPercentage(5); |
1867 } | 1854 } |
1868 ASSERT_TRUE(Initialize()); | 1855 ASSERT_TRUE(Initialize()); |
1869 | 1856 |
1870 // Wait for the server SHLO before upping the packet loss. | 1857 // Wait for the server SHLO before upping the packet loss. |
1871 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1858 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1872 SetPacketLossPercentage(30); | 1859 SetPacketLossPercentage(30); |
1873 client_writer_->set_fake_blocked_socket_percentage(10); | 1860 client_writer_->set_fake_blocked_socket_percentage(10); |
1874 | 1861 |
1875 // Create a POST request and send the headers only. | 1862 // Create a POST request and send the headers only. |
1876 SpdyHeaderBlock headers; | 1863 SpdyHeaderBlock headers; |
1877 headers[":method"] = "POST"; | 1864 headers[":method"] = "POST"; |
1878 headers[":path"] = "/foo"; | 1865 headers[":path"] = "/foo"; |
1879 headers[":scheme"] = "https"; | 1866 headers[":scheme"] = "https"; |
1880 headers[":authority"] = server_hostname_; | 1867 headers[":authority"] = server_hostname_; |
1881 | 1868 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1933 EXPECT_EQ("", client_->SendSynchronousRequest("/foo")); | 1920 EXPECT_EQ("", client_->SendSynchronousRequest("/foo")); |
1934 EXPECT_TRUE(client_->response_headers()->empty()); | 1921 EXPECT_TRUE(client_->response_headers()->empty()); |
1935 EXPECT_EQ(QUIC_PUBLIC_RESET, client_->connection_error()); | 1922 EXPECT_EQ(QUIC_PUBLIC_RESET, client_->connection_error()); |
1936 } | 1923 } |
1937 | 1924 |
1938 // Send a public reset from the server for a different connection ID. | 1925 // Send a public reset from the server for a different connection ID. |
1939 // It should be ignored. | 1926 // It should be ignored. |
1940 TEST_P(EndToEndTest, ServerSendPublicResetWithDifferentConnectionId) { | 1927 TEST_P(EndToEndTest, ServerSendPublicResetWithDifferentConnectionId) { |
1941 ASSERT_TRUE(Initialize()); | 1928 ASSERT_TRUE(Initialize()); |
1942 | 1929 |
1943 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1930 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
1944 | 1931 |
1945 // Send the public reset. | 1932 // Send the public reset. |
1946 QuicConnectionId incorrect_connection_id = | 1933 QuicConnectionId incorrect_connection_id = |
1947 client_->client()->session()->connection()->connection_id() + 1; | 1934 client_->client()->session()->connection()->connection_id() + 1; |
1948 QuicPublicResetPacket header; | 1935 QuicPublicResetPacket header; |
1949 header.public_header.connection_id = incorrect_connection_id; | 1936 header.public_header.connection_id = incorrect_connection_id; |
1950 header.public_header.reset_flag = true; | 1937 header.public_header.reset_flag = true; |
1951 header.public_header.version_flag = false; | 1938 header.public_header.version_flag = false; |
1952 header.rejected_packet_number = 10101; | 1939 header.rejected_packet_number = 10101; |
1953 QuicFramer framer(server_supported_versions_, QuicTime::Zero(), | 1940 QuicFramer framer(server_supported_versions_, QuicTime::Zero(), |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1998 // The connection should be unaffected. | 1985 // The connection should be unaffected. |
1999 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1986 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
2000 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); | 1987 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
2001 } | 1988 } |
2002 | 1989 |
2003 // Send a version negotiation packet from the server for a different | 1990 // Send a version negotiation packet from the server for a different |
2004 // connection ID. It should be ignored. | 1991 // connection ID. It should be ignored. |
2005 TEST_P(EndToEndTest, ServerSendVersionNegotiationWithDifferentConnectionId) { | 1992 TEST_P(EndToEndTest, ServerSendVersionNegotiationWithDifferentConnectionId) { |
2006 ASSERT_TRUE(Initialize()); | 1993 ASSERT_TRUE(Initialize()); |
2007 | 1994 |
2008 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1995 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
2009 | 1996 |
2010 // Send the version negotiation packet. | 1997 // Send the version negotiation packet. |
2011 QuicConnectionId incorrect_connection_id = | 1998 QuicConnectionId incorrect_connection_id = |
2012 client_->client()->session()->connection()->connection_id() + 1; | 1999 client_->client()->session()->connection()->connection_id() + 1; |
2013 std::unique_ptr<QuicEncryptedPacket> packet( | 2000 std::unique_ptr<QuicEncryptedPacket> packet( |
2014 QuicFramer::BuildVersionNegotiationPacket(incorrect_connection_id, | 2001 QuicFramer::BuildVersionNegotiationPacket(incorrect_connection_id, |
2015 server_supported_versions_)); | 2002 server_supported_versions_)); |
2016 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor; | 2003 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor; |
2017 client_->client()->session()->connection()->set_debug_visitor(&visitor); | 2004 client_->client()->session()->connection()->set_debug_visitor(&visitor); |
2018 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id)) | 2005 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id)) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2140 // The connection should not be terminated. | 2127 // The connection should not be terminated. |
2141 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 2128 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
2142 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); | 2129 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
2143 } | 2130 } |
2144 | 2131 |
2145 // A test stream that gives |response_body_| as an error response body. | 2132 // A test stream that gives |response_body_| as an error response body. |
2146 class ServerStreamWithErrorResponseBody : public QuicSimpleServerStream { | 2133 class ServerStreamWithErrorResponseBody : public QuicSimpleServerStream { |
2147 public: | 2134 public: |
2148 ServerStreamWithErrorResponseBody(QuicStreamId id, | 2135 ServerStreamWithErrorResponseBody(QuicStreamId id, |
2149 QuicSpdySession* session, | 2136 QuicSpdySession* session, |
2150 QuicInMemoryCache* in_memory_cache, | 2137 QuicHttpResponseCache* response_cache, |
2151 string response_body) | 2138 string response_body) |
2152 : QuicSimpleServerStream(id, session, in_memory_cache), | 2139 : QuicSimpleServerStream(id, session, response_cache), |
2153 response_body_(std::move(response_body)) {} | 2140 response_body_(std::move(response_body)) {} |
2154 | 2141 |
2155 ~ServerStreamWithErrorResponseBody() override {} | 2142 ~ServerStreamWithErrorResponseBody() override {} |
2156 | 2143 |
2157 protected: | 2144 protected: |
2158 void SendErrorResponse() override { | 2145 void SendErrorResponse() override { |
2159 DVLOG(1) << "Sending error response for stream " << id(); | 2146 DVLOG(1) << "Sending error response for stream " << id(); |
2160 SpdyHeaderBlock headers; | 2147 SpdyHeaderBlock headers; |
2161 headers[":status"] = "500"; | 2148 headers[":status"] = "500"; |
2162 headers["content-length"] = base::UintToString(response_body_.size()); | 2149 headers["content-length"] = base::UintToString(response_body_.size()); |
2163 // This method must call CloseReadSide to cause the test case, StopReading | 2150 // This method must call CloseReadSide to cause the test case, StopReading |
2164 // is not sufficient. | 2151 // is not sufficient. |
2165 QuicStreamPeer::CloseReadSide(this); | 2152 QuicStreamPeer::CloseReadSide(this); |
2166 SendHeadersAndBody(std::move(headers), response_body_); | 2153 SendHeadersAndBody(std::move(headers), response_body_); |
2167 } | 2154 } |
2168 | 2155 |
2169 string response_body_; | 2156 string response_body_; |
2170 }; | 2157 }; |
2171 | 2158 |
2172 class StreamWithErrorFactory : public QuicTestServer::StreamFactory { | 2159 class StreamWithErrorFactory : public QuicTestServer::StreamFactory { |
2173 public: | 2160 public: |
2174 explicit StreamWithErrorFactory(string response_body) | 2161 explicit StreamWithErrorFactory(string response_body) |
2175 : response_body_(std::move(response_body)) {} | 2162 : response_body_(std::move(response_body)) {} |
2176 | 2163 |
2177 ~StreamWithErrorFactory() override {} | 2164 ~StreamWithErrorFactory() override {} |
2178 | 2165 |
2179 QuicSimpleServerStream* CreateStream( | 2166 QuicSimpleServerStream* CreateStream( |
2180 QuicStreamId id, | 2167 QuicStreamId id, |
2181 QuicSpdySession* session, | 2168 QuicSpdySession* session, |
2182 QuicInMemoryCache* in_memory_cache) override { | 2169 QuicHttpResponseCache* response_cache) override { |
2183 return new ServerStreamWithErrorResponseBody(id, session, in_memory_cache, | 2170 return new ServerStreamWithErrorResponseBody(id, session, response_cache, |
2184 response_body_); | 2171 response_body_); |
2185 } | 2172 } |
2186 | 2173 |
2187 private: | 2174 private: |
2188 string response_body_; | 2175 string response_body_; |
2189 }; | 2176 }; |
2190 | 2177 |
2191 // A test server stream that drops all received body. | 2178 // A test server stream that drops all received body. |
2192 class ServerStreamThatDropsBody : public QuicSimpleServerStream { | 2179 class ServerStreamThatDropsBody : public QuicSimpleServerStream { |
2193 public: | 2180 public: |
2194 ServerStreamThatDropsBody(QuicStreamId id, | 2181 ServerStreamThatDropsBody(QuicStreamId id, |
2195 QuicSpdySession* session, | 2182 QuicSpdySession* session, |
2196 QuicInMemoryCache* in_memory_cache) | 2183 QuicHttpResponseCache* response_cache) |
2197 : QuicSimpleServerStream(id, session, in_memory_cache) {} | 2184 : QuicSimpleServerStream(id, session, response_cache) {} |
2198 | 2185 |
2199 ~ServerStreamThatDropsBody() override {} | 2186 ~ServerStreamThatDropsBody() override {} |
2200 | 2187 |
2201 protected: | 2188 protected: |
2202 void OnDataAvailable() override { | 2189 void OnDataAvailable() override { |
2203 while (HasBytesToRead()) { | 2190 while (HasBytesToRead()) { |
2204 struct iovec iov; | 2191 struct iovec iov; |
2205 if (GetReadableRegions(&iov, 1) == 0) { | 2192 if (GetReadableRegions(&iov, 1) == 0) { |
2206 // No more data to read. | 2193 // No more data to read. |
2207 break; | 2194 break; |
(...skipping 21 matching lines...) Expand all Loading... |
2229 | 2216 |
2230 class ServerStreamThatDropsBodyFactory : public QuicTestServer::StreamFactory { | 2217 class ServerStreamThatDropsBodyFactory : public QuicTestServer::StreamFactory { |
2231 public: | 2218 public: |
2232 ServerStreamThatDropsBodyFactory() {} | 2219 ServerStreamThatDropsBodyFactory() {} |
2233 | 2220 |
2234 ~ServerStreamThatDropsBodyFactory() override{}; | 2221 ~ServerStreamThatDropsBodyFactory() override{}; |
2235 | 2222 |
2236 QuicSimpleServerStream* CreateStream( | 2223 QuicSimpleServerStream* CreateStream( |
2237 QuicStreamId id, | 2224 QuicStreamId id, |
2238 QuicSpdySession* session, | 2225 QuicSpdySession* session, |
2239 QuicInMemoryCache* in_memory_cache) override { | 2226 QuicHttpResponseCache* response_cache) override { |
2240 return new ServerStreamThatDropsBody(id, session, in_memory_cache); | 2227 return new ServerStreamThatDropsBody(id, session, response_cache); |
2241 } | 2228 } |
2242 }; | 2229 }; |
2243 | 2230 |
2244 // A test server stream that sends response with body size greater than 4GB. | 2231 // A test server stream that sends response with body size greater than 4GB. |
2245 class ServerStreamThatSendsHugeResponse : public QuicSimpleServerStream { | 2232 class ServerStreamThatSendsHugeResponse : public QuicSimpleServerStream { |
2246 public: | 2233 public: |
2247 ServerStreamThatSendsHugeResponse(QuicStreamId id, | 2234 ServerStreamThatSendsHugeResponse(QuicStreamId id, |
2248 QuicSpdySession* session, | 2235 QuicSpdySession* session, |
2249 QuicInMemoryCache* in_memory_cache, | 2236 QuicHttpResponseCache* response_cache, |
2250 int64_t body_bytes) | 2237 int64_t body_bytes) |
2251 : QuicSimpleServerStream(id, session, in_memory_cache), | 2238 : QuicSimpleServerStream(id, session, response_cache), |
2252 body_bytes_(body_bytes) {} | 2239 body_bytes_(body_bytes) {} |
2253 | 2240 |
2254 ~ServerStreamThatSendsHugeResponse() override {} | 2241 ~ServerStreamThatSendsHugeResponse() override {} |
2255 | 2242 |
2256 protected: | 2243 protected: |
2257 void SendResponse() override { | 2244 void SendResponse() override { |
2258 QuicInMemoryCache::Response response; | 2245 QuicHttpResponseCache::Response response; |
2259 string body; | 2246 string body(body_bytes_, 'a'); |
2260 GenerateBody(&body, body_bytes_); | |
2261 response.set_body(body); | 2247 response.set_body(body); |
2262 SendHeadersAndBodyAndTrailers(response.headers().Clone(), response.body(), | 2248 SendHeadersAndBodyAndTrailers(response.headers().Clone(), response.body(), |
2263 response.trailers().Clone()); | 2249 response.trailers().Clone()); |
2264 } | 2250 } |
2265 | 2251 |
2266 private: | 2252 private: |
2267 // Use a explicit int64_t rather than size_t to simulate a 64-bit server | 2253 // Use a explicit int64_t rather than size_t to simulate a 64-bit server |
2268 // talking to a 32-bit client. | 2254 // talking to a 32-bit client. |
2269 int64_t body_bytes_; | 2255 int64_t body_bytes_; |
2270 }; | 2256 }; |
2271 | 2257 |
2272 class ServerStreamThatSendsHugeResponseFactory | 2258 class ServerStreamThatSendsHugeResponseFactory |
2273 : public QuicTestServer::StreamFactory { | 2259 : public QuicTestServer::StreamFactory { |
2274 public: | 2260 public: |
2275 explicit ServerStreamThatSendsHugeResponseFactory(int64_t body_bytes) | 2261 explicit ServerStreamThatSendsHugeResponseFactory(int64_t body_bytes) |
2276 : body_bytes_(body_bytes) {} | 2262 : body_bytes_(body_bytes) {} |
2277 | 2263 |
2278 ~ServerStreamThatSendsHugeResponseFactory() override{}; | 2264 ~ServerStreamThatSendsHugeResponseFactory() override{}; |
2279 | 2265 |
2280 QuicSimpleServerStream* CreateStream( | 2266 QuicSimpleServerStream* CreateStream( |
2281 QuicStreamId id, | 2267 QuicStreamId id, |
2282 QuicSpdySession* session, | 2268 QuicSpdySession* session, |
2283 QuicInMemoryCache* in_memory_cache) override { | 2269 QuicHttpResponseCache* response_cache) override { |
2284 return new ServerStreamThatSendsHugeResponse(id, session, in_memory_cache, | 2270 return new ServerStreamThatSendsHugeResponse(id, session, response_cache, |
2285 body_bytes_); | 2271 body_bytes_); |
2286 } | 2272 } |
2287 | 2273 |
2288 int64_t body_bytes_; | 2274 int64_t body_bytes_; |
2289 }; | 2275 }; |
2290 | 2276 |
2291 // A test client stream that drops all received body. | 2277 // A test client stream that drops all received body. |
2292 class ClientStreamThatDropsBody : public QuicSpdyClientStream { | 2278 class ClientStreamThatDropsBody : public QuicSpdyClientStream { |
2293 public: | 2279 public: |
2294 ClientStreamThatDropsBody(QuicStreamId id, QuicClientSession* session) | 2280 ClientStreamThatDropsBody(QuicStreamId id, QuicClientSession* session) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2378 set_smaller_flow_control_receive_window(); | 2364 set_smaller_flow_control_receive_window(); |
2379 | 2365 |
2380 // Verify that an incoming FIN is recorded in a stream object even if the read | 2366 // Verify that an incoming FIN is recorded in a stream object even if the read |
2381 // side has been closed. This prevents an entry from being made in | 2367 // side has been closed. This prevents an entry from being made in |
2382 // locally_close_streams_highest_offset_ (which will never be deleted). | 2368 // locally_close_streams_highest_offset_ (which will never be deleted). |
2383 // To set up the test condition, the server must do the following in order: | 2369 // To set up the test condition, the server must do the following in order: |
2384 // start sending the response and call CloseReadSide | 2370 // start sending the response and call CloseReadSide |
2385 // receive the FIN of the request | 2371 // receive the FIN of the request |
2386 // send the FIN of the response | 2372 // send the FIN of the response |
2387 | 2373 |
2388 string response_body; | |
2389 // The response body must be larger than the flow control window so the server | 2374 // The response body must be larger than the flow control window so the server |
2390 // must receive a window update from the client before it can finish sending | 2375 // must receive a window update from the client before it can finish sending |
2391 // it. | 2376 // it. |
2392 uint32_t response_body_size = | 2377 uint32_t response_body_size = |
2393 2 * client_config_.GetInitialStreamFlowControlWindowToSend(); | 2378 2 * client_config_.GetInitialStreamFlowControlWindowToSend(); |
2394 GenerateBody(&response_body, response_body_size); | 2379 string response_body(response_body_size, 'a'); |
2395 | 2380 |
2396 StreamWithErrorFactory stream_factory(response_body); | 2381 StreamWithErrorFactory stream_factory(response_body); |
2397 SetSpdyStreamFactory(&stream_factory); | 2382 SetSpdyStreamFactory(&stream_factory); |
2398 | 2383 |
2399 ASSERT_TRUE(Initialize()); | 2384 ASSERT_TRUE(Initialize()); |
2400 | 2385 |
2401 client_->client()->WaitForCryptoHandshakeConfirmed(); | 2386 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
2402 | 2387 |
2403 // A POST that gets an early error response, after the headers are received | 2388 // A POST that gets an early error response, after the headers are received |
2404 // and before the body is received, due to invalid content-length. | 2389 // and before the body is received, due to invalid content-length. |
2405 // Set an invalid content-length, so the request will receive an early 500 | 2390 // Set an invalid content-length, so the request will receive an early 500 |
2406 // response. | 2391 // response. |
2407 SpdyHeaderBlock headers; | 2392 SpdyHeaderBlock headers; |
2408 headers[":method"] = "POST"; | 2393 headers[":method"] = "POST"; |
2409 headers[":path"] = "/garbage"; | 2394 headers[":path"] = "/garbage"; |
2410 headers[":scheme"] = "https"; | 2395 headers[":scheme"] = "https"; |
2411 headers[":authority"] = server_hostname_; | 2396 headers[":authority"] = server_hostname_; |
2412 headers["content-length"] = "-1"; | 2397 headers["content-length"] = "-1"; |
2413 | 2398 |
2414 // The body must be large enough that the FIN will be in a different packet | 2399 // The body must be large enough that the FIN will be in a different packet |
2415 // than the end of the headers, but short enough to not require a flow control | 2400 // than the end of the headers, but short enough to not require a flow control |
2416 // update. This allows headers processing to trigger the error response | 2401 // update. This allows headers processing to trigger the error response |
2417 // before the request FIN is processed but receive the request FIN before the | 2402 // before the request FIN is processed but receive the request FIN before the |
2418 // response is sent completely. | 2403 // response is sent completely. |
2419 const uint32_t kRequestBodySize = kMaxPacketSize + 10; | 2404 const uint32_t kRequestBodySize = kMaxPacketSize + 10; |
2420 string request_body; | 2405 string request_body(kRequestBodySize, 'a'); |
2421 GenerateBody(&request_body, kRequestBodySize); | |
2422 | 2406 |
2423 // Send the request. | 2407 // Send the request. |
2424 client_->SendMessage(headers, request_body); | 2408 client_->SendMessage(headers, request_body); |
2425 client_->WaitForResponse(); | 2409 client_->WaitForResponse(); |
2426 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); | 2410 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); |
2427 | 2411 |
2428 // Pause the server so we can access the server's internals without races. | 2412 // Pause the server so we can access the server's internals without races. |
2429 server_thread_->Pause(); | 2413 server_thread_->Pause(); |
2430 | 2414 |
2431 QuicDispatcher* dispatcher = | 2415 QuicDispatcher* dispatcher = |
(...skipping 14 matching lines...) Expand all Loading... |
2446 | 2430 |
2447 TEST_P(EndToEndTest, LargePostEarlyResponse) { | 2431 TEST_P(EndToEndTest, LargePostEarlyResponse) { |
2448 const uint32_t kWindowSize = 65536; | 2432 const uint32_t kWindowSize = 65536; |
2449 set_client_initial_stream_flow_control_receive_window(kWindowSize); | 2433 set_client_initial_stream_flow_control_receive_window(kWindowSize); |
2450 set_client_initial_session_flow_control_receive_window(kWindowSize); | 2434 set_client_initial_session_flow_control_receive_window(kWindowSize); |
2451 set_server_initial_stream_flow_control_receive_window(kWindowSize); | 2435 set_server_initial_stream_flow_control_receive_window(kWindowSize); |
2452 set_server_initial_session_flow_control_receive_window(kWindowSize); | 2436 set_server_initial_session_flow_control_receive_window(kWindowSize); |
2453 | 2437 |
2454 ASSERT_TRUE(Initialize()); | 2438 ASSERT_TRUE(Initialize()); |
2455 | 2439 |
2456 client_->client()->WaitForCryptoHandshakeConfirmed(); | 2440 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
2457 | 2441 |
2458 // POST to a URL that gets an early error response, after the headers are | 2442 // POST to a URL that gets an early error response, after the headers are |
2459 // received and before the body is received. | 2443 // received and before the body is received. |
2460 SpdyHeaderBlock headers; | 2444 SpdyHeaderBlock headers; |
2461 headers[":method"] = "POST"; | 2445 headers[":method"] = "POST"; |
2462 headers[":path"] = "/foo"; | 2446 headers[":path"] = "/foo"; |
2463 headers[":scheme"] = "https"; | 2447 headers[":scheme"] = "https"; |
2464 headers[":authority"] = server_hostname_; | 2448 headers[":authority"] = server_hostname_; |
2465 headers["content-length"] = "-1"; | 2449 headers["content-length"] = "-1"; |
2466 | 2450 |
2467 // Tell the client to not close the stream if it receives an early response. | 2451 // Tell the client to not close the stream if it receives an early response. |
2468 client_->set_allow_bidirectional_data(true); | 2452 client_->set_allow_bidirectional_data(true); |
2469 // Send the headers. | 2453 // Send the headers. |
2470 client_->SendMessage(headers, "", /*fin=*/false); | 2454 client_->SendMessage(headers, "", /*fin=*/false); |
2471 | 2455 |
2472 // Receive the response and let the server close writing. | 2456 // Receive the response and let the server close writing. |
2473 client_->WaitForInitialResponse(); | 2457 client_->WaitForInitialResponse(); |
2474 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); | 2458 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); |
2475 | 2459 |
2476 // Receive the reset stream from server on early response. | 2460 // Receive the reset stream from server on early response. |
2477 QuicStream* stream = | 2461 QuicStream* stream = |
2478 client_->client()->session()->GetOrCreateStream(kClientDataStreamId1); | 2462 client_->client()->session()->GetOrCreateStream(kClientDataStreamId1); |
2479 // The stream is reset by server's reset stream. | 2463 // The stream is reset by server's reset stream. |
2480 EXPECT_EQ(stream, nullptr); | 2464 EXPECT_EQ(stream, nullptr); |
2481 } | 2465 } |
2482 | 2466 |
2483 TEST_P(EndToEndTest, Trailers) { | 2467 TEST_P(EndToEndTest, Trailers) { |
2484 // Test sending and receiving HTTP/2 Trailers (trailing HEADERS frames). | 2468 // Test sending and receiving HTTP/2 Trailers (trailing HEADERS frames). |
2485 ASSERT_TRUE(Initialize()); | 2469 ASSERT_TRUE(Initialize()); |
2486 client_->client()->WaitForCryptoHandshakeConfirmed(); | 2470 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
2487 | 2471 |
2488 // Set reordering to ensure that Trailers arriving before body is ok. | 2472 // Set reordering to ensure that Trailers arriving before body is ok. |
2489 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); | 2473 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); |
2490 SetReorderPercentage(30); | 2474 SetReorderPercentage(30); |
2491 | 2475 |
2492 // Add a response with headers, body, and trailers. | 2476 // Add a response with headers, body, and trailers. |
2493 const string kBody = "body content"; | 2477 const string kBody = "body content"; |
2494 | 2478 |
2495 SpdyHeaderBlock headers; | 2479 SpdyHeaderBlock headers; |
2496 headers[":status"] = "200"; | 2480 headers[":status"] = "200"; |
2497 headers[":version"] = "HTTP/1.1"; | 2481 headers[":version"] = "HTTP/1.1"; |
2498 headers["content-length"] = IntToString(kBody.size()); | 2482 headers["content-length"] = IntToString(kBody.size()); |
2499 | 2483 |
2500 SpdyHeaderBlock trailers; | 2484 SpdyHeaderBlock trailers; |
2501 trailers["some-trailing-header"] = "trailing-header-value"; | 2485 trailers["some-trailing-header"] = "trailing-header-value"; |
2502 | 2486 |
2503 in_memory_cache_.AddResponse(server_hostname_, "/trailer_url", | 2487 response_cache_.AddResponse(server_hostname_, "/trailer_url", |
2504 std::move(headers), kBody, trailers.Clone()); | 2488 std::move(headers), kBody, trailers.Clone()); |
2505 | 2489 |
2506 EXPECT_EQ(kBody, client_->SendSynchronousRequest("/trailer_url")); | 2490 EXPECT_EQ(kBody, client_->SendSynchronousRequest("/trailer_url")); |
2507 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); | 2491 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
2508 EXPECT_EQ(trailers, client_->response_trailers()); | 2492 EXPECT_EQ(trailers, client_->response_trailers()); |
2509 } | 2493 } |
2510 | 2494 |
2511 class EndToEndTestServerPush : public EndToEndTest { | 2495 class EndToEndTestServerPush : public EndToEndTest { |
2512 protected: | 2496 protected: |
2513 const size_t kNumMaxStreams = 10; | 2497 const size_t kNumMaxStreams = 10; |
2514 | 2498 |
(...skipping 14 matching lines...) Expand all Loading... |
2529 string path, | 2513 string path, |
2530 string response_body, | 2514 string response_body, |
2531 string* push_urls, | 2515 string* push_urls, |
2532 const size_t num_resources, | 2516 const size_t num_resources, |
2533 const size_t resource_size) { | 2517 const size_t resource_size) { |
2534 bool use_large_response = resource_size != 0; | 2518 bool use_large_response = resource_size != 0; |
2535 string large_resource; | 2519 string large_resource; |
2536 if (use_large_response) { | 2520 if (use_large_response) { |
2537 // Generate a response common body larger than flow control window for | 2521 // Generate a response common body larger than flow control window for |
2538 // push response. | 2522 // push response. |
2539 GenerateBody(&large_resource, resource_size); | 2523 large_resource = string(resource_size, 'a'); |
2540 } | 2524 } |
2541 std::list<QuicInMemoryCache::ServerPushInfo> push_resources; | 2525 std::list<QuicHttpResponseCache::ServerPushInfo> push_resources; |
2542 for (size_t i = 0; i < num_resources; ++i) { | 2526 for (size_t i = 0; i < num_resources; ++i) { |
2543 string url = push_urls[i]; | 2527 string url = push_urls[i]; |
2544 GURL resource_url(url); | 2528 GURL resource_url(url); |
2545 string body = use_large_response | 2529 string body = use_large_response |
2546 ? large_resource | 2530 ? large_resource |
2547 : "This is server push response body for " + url; | 2531 : "This is server push response body for " + url; |
2548 SpdyHeaderBlock response_headers; | 2532 SpdyHeaderBlock response_headers; |
2549 response_headers[":version"] = "HTTP/1.1"; | 2533 response_headers[":version"] = "HTTP/1.1"; |
2550 response_headers[":status"] = "200"; | 2534 response_headers[":status"] = "200"; |
2551 response_headers["content-length"] = IntToString(body.size()); | 2535 response_headers["content-length"] = IntToString(body.size()); |
2552 push_resources.push_back(QuicInMemoryCache::ServerPushInfo( | 2536 push_resources.push_back(QuicHttpResponseCache::ServerPushInfo( |
2553 resource_url, std::move(response_headers), kV3LowestPriority, body)); | 2537 resource_url, std::move(response_headers), kV3LowestPriority, body)); |
2554 } | 2538 } |
2555 | 2539 |
2556 in_memory_cache_.AddSimpleResponseWithServerPushResources( | 2540 response_cache_.AddSimpleResponseWithServerPushResources( |
2557 host, path, 200, response_body, push_resources); | 2541 host, path, 200, response_body, push_resources); |
2558 } | 2542 } |
2559 }; | 2543 }; |
2560 | 2544 |
2561 // Run all server push end to end tests with all supported versions. | 2545 // Run all server push end to end tests with all supported versions. |
2562 INSTANTIATE_TEST_CASE_P(EndToEndTestsServerPush, | 2546 INSTANTIATE_TEST_CASE_P(EndToEndTestsServerPush, |
2563 EndToEndTestServerPush, | 2547 EndToEndTestServerPush, |
2564 ::testing::ValuesIn(GetTestParams())); | 2548 ::testing::ValuesIn(GetTestParams())); |
2565 | 2549 |
2566 TEST_P(EndToEndTestServerPush, ServerPush) { | 2550 TEST_P(EndToEndTestServerPush, ServerPush) { |
2567 ASSERT_TRUE(Initialize()); | 2551 ASSERT_TRUE(Initialize()); |
2568 client_->client()->WaitForCryptoHandshakeConfirmed(); | 2552 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
2569 | 2553 |
2570 // Set reordering to ensure that body arriving before PUSH_PROMISE is ok. | 2554 // Set reordering to ensure that body arriving before PUSH_PROMISE is ok. |
2571 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); | 2555 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); |
2572 SetReorderPercentage(30); | 2556 SetReorderPercentage(30); |
2573 | 2557 |
2574 // Add a response with headers, body, and push resources. | 2558 // Add a response with headers, body, and push resources. |
2575 const string kBody = "body content"; | 2559 const string kBody = "body content"; |
2576 size_t kNumResources = 4; | 2560 size_t kNumResources = 4; |
2577 string push_urls[] = {"https://example.com/font.woff", | 2561 string push_urls[] = {"https://example.com/font.woff", |
2578 "https://example.com/script.js", | 2562 "https://example.com/script.js", |
(...skipping 26 matching lines...) Expand all Loading... |
2605 EXPECT_NE(FLAGS_quic_headers_stream_release_sequencer_buffer, | 2589 EXPECT_NE(FLAGS_quic_headers_stream_release_sequencer_buffer, |
2606 QuicStreamSequencerPeer::IsUnderlyingBufferAllocated(sequencer)); | 2590 QuicStreamSequencerPeer::IsUnderlyingBufferAllocated(sequencer)); |
2607 } | 2591 } |
2608 | 2592 |
2609 TEST_P(EndToEndTestServerPush, ServerPushUnderLimit) { | 2593 TEST_P(EndToEndTestServerPush, ServerPushUnderLimit) { |
2610 // Tests that sending a request which has 4 push resources will trigger server | 2594 // Tests that sending a request which has 4 push resources will trigger server |
2611 // to push those 4 resources and client can handle pushed resources and match | 2595 // to push those 4 resources and client can handle pushed resources and match |
2612 // them with requests later. | 2596 // them with requests later. |
2613 ASSERT_TRUE(Initialize()); | 2597 ASSERT_TRUE(Initialize()); |
2614 | 2598 |
2615 client_->client()->WaitForCryptoHandshakeConfirmed(); | 2599 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
2616 | 2600 |
2617 // Set reordering to ensure that body arriving before PUSH_PROMISE is ok. | 2601 // Set reordering to ensure that body arriving before PUSH_PROMISE is ok. |
2618 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); | 2602 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); |
2619 SetReorderPercentage(30); | 2603 SetReorderPercentage(30); |
2620 | 2604 |
2621 // Add a response with headers, body, and push resources. | 2605 // Add a response with headers, body, and push resources. |
2622 const string kBody = "body content"; | 2606 const string kBody = "body content"; |
2623 size_t const kNumResources = 4; | 2607 size_t const kNumResources = 4; |
2624 string push_urls[] = { | 2608 string push_urls[] = { |
2625 "https://example.com/font.woff", "https://example.com/script.js", | 2609 "https://example.com/font.woff", "https://example.com/script.js", |
(...skipping 26 matching lines...) Expand all Loading... |
2652 EXPECT_EQ(1u, client_->num_requests()); | 2636 EXPECT_EQ(1u, client_->num_requests()); |
2653 EXPECT_EQ(1u + kNumResources, client_->num_responses()); | 2637 EXPECT_EQ(1u + kNumResources, client_->num_responses()); |
2654 } | 2638 } |
2655 | 2639 |
2656 TEST_P(EndToEndTestServerPush, ServerPushOverLimitNonBlocking) { | 2640 TEST_P(EndToEndTestServerPush, ServerPushOverLimitNonBlocking) { |
2657 // Tests that when streams are not blocked by flow control or congestion | 2641 // Tests that when streams are not blocked by flow control or congestion |
2658 // control, pushing even more resources than max number of open outgoing | 2642 // control, pushing even more resources than max number of open outgoing |
2659 // streams should still work because all response streams get closed | 2643 // streams should still work because all response streams get closed |
2660 // immediately after pushing resources. | 2644 // immediately after pushing resources. |
2661 ASSERT_TRUE(Initialize()); | 2645 ASSERT_TRUE(Initialize()); |
2662 client_->client()->WaitForCryptoHandshakeConfirmed(); | 2646 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
2663 | 2647 |
2664 // Set reordering to ensure that body arriving before PUSH_PROMISE is ok. | 2648 // Set reordering to ensure that body arriving before PUSH_PROMISE is ok. |
2665 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); | 2649 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); |
2666 SetReorderPercentage(30); | 2650 SetReorderPercentage(30); |
2667 | 2651 |
2668 // Add a response with headers, body, and push resources. | 2652 // Add a response with headers, body, and push resources. |
2669 const string kBody = "body content"; | 2653 const string kBody = "body content"; |
2670 | 2654 |
2671 // One more resource than max number of outgoing stream of this session. | 2655 // One more resource than max number of outgoing stream of this session. |
2672 const size_t kNumResources = 1 + kNumMaxStreams; // 11. | 2656 const size_t kNumResources = 1 + kNumMaxStreams; // 11. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2710 size_t kFlowControlWnd = 20 * 1024; // 20KB. | 2694 size_t kFlowControlWnd = 20 * 1024; // 20KB. |
2711 // Response body is larger than 1 flow controlblock window. | 2695 // Response body is larger than 1 flow controlblock window. |
2712 size_t kBodySize = kFlowControlWnd * 2; | 2696 size_t kBodySize = kFlowControlWnd * 2; |
2713 set_client_initial_stream_flow_control_receive_window(kFlowControlWnd); | 2697 set_client_initial_stream_flow_control_receive_window(kFlowControlWnd); |
2714 // Make sure conntection level flow control window is large enough not to | 2698 // Make sure conntection level flow control window is large enough not to |
2715 // block data being sent out though they will be blocked by stream level one. | 2699 // block data being sent out though they will be blocked by stream level one. |
2716 set_client_initial_session_flow_control_receive_window( | 2700 set_client_initial_session_flow_control_receive_window( |
2717 kBodySize * kNumMaxStreams + 1024); | 2701 kBodySize * kNumMaxStreams + 1024); |
2718 | 2702 |
2719 ASSERT_TRUE(Initialize()); | 2703 ASSERT_TRUE(Initialize()); |
2720 client_->client()->WaitForCryptoHandshakeConfirmed(); | 2704 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
2721 | 2705 |
2722 // Set reordering to ensure that body arriving before PUSH_PROMISE is ok. | 2706 // Set reordering to ensure that body arriving before PUSH_PROMISE is ok. |
2723 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); | 2707 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); |
2724 SetReorderPercentage(30); | 2708 SetReorderPercentage(30); |
2725 | 2709 |
2726 // Add a response with headers, body, and push resources. | 2710 // Add a response with headers, body, and push resources. |
2727 const string kBody = "body content"; | 2711 const string kBody = "body content"; |
2728 | 2712 |
2729 const size_t kNumResources = kNumMaxStreams + 1; | 2713 const size_t kNumResources = kNumMaxStreams + 1; |
2730 string push_urls[11]; | 2714 string push_urls[11]; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2823 // This test tests a huge post with introduced packet loss from client to | 2807 // This test tests a huge post with introduced packet loss from client to |
2824 // server and body size greater than 4GB, making sure QUIC code does not break | 2808 // server and body size greater than 4GB, making sure QUIC code does not break |
2825 // for 32-bit builds. | 2809 // for 32-bit builds. |
2826 ServerStreamThatDropsBodyFactory stream_factory; | 2810 ServerStreamThatDropsBodyFactory stream_factory; |
2827 SetSpdyStreamFactory(&stream_factory); | 2811 SetSpdyStreamFactory(&stream_factory); |
2828 ASSERT_TRUE(Initialize()); | 2812 ASSERT_TRUE(Initialize()); |
2829 // Set client's epoll server's time out to 0 to make this test be finished | 2813 // Set client's epoll server's time out to 0 to make this test be finished |
2830 // within a short time. | 2814 // within a short time. |
2831 client_->epoll_server()->set_timeout_in_us(0); | 2815 client_->epoll_server()->set_timeout_in_us(0); |
2832 | 2816 |
2833 client_->client()->WaitForCryptoHandshakeConfirmed(); | 2817 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
2834 SetPacketLossPercentage(1); | 2818 SetPacketLossPercentage(1); |
2835 // To avoid storing the whole request body in memory, use a loop to repeatedly | 2819 // To avoid storing the whole request body in memory, use a loop to repeatedly |
2836 // send body size of kSizeBytes until the whole request body size is reached. | 2820 // send body size of kSizeBytes until the whole request body size is reached. |
2837 const int kSizeBytes = 128 * 1024; | 2821 const int kSizeBytes = 128 * 1024; |
2838 // Request body size is 4G plus one more kSizeBytes. | 2822 // Request body size is 4G plus one more kSizeBytes. |
2839 int64_t request_body_size_bytes = pow(2, 32) + kSizeBytes; | 2823 int64_t request_body_size_bytes = pow(2, 32) + kSizeBytes; |
2840 ASSERT_LT(INT64_C(4294967296), request_body_size_bytes); | 2824 ASSERT_LT(INT64_C(4294967296), request_body_size_bytes); |
2841 string body; | 2825 string body(kSizeBytes, 'a'); |
2842 GenerateBody(&body, kSizeBytes); | |
2843 | 2826 |
2844 SpdyHeaderBlock headers; | 2827 SpdyHeaderBlock headers; |
2845 headers[":method"] = "POST"; | 2828 headers[":method"] = "POST"; |
2846 headers[":path"] = "/foo"; | 2829 headers[":path"] = "/foo"; |
2847 headers[":scheme"] = "https"; | 2830 headers[":scheme"] = "https"; |
2848 headers[":authority"] = server_hostname_; | 2831 headers[":authority"] = server_hostname_; |
2849 headers["content-length"] = IntToString(request_body_size_bytes); | 2832 headers["content-length"] = IntToString(request_body_size_bytes); |
2850 | 2833 |
2851 client_->SendMessage(headers, "", /*fin=*/false); | 2834 client_->SendMessage(headers, "", /*fin=*/false); |
2852 | 2835 |
(...skipping 28 matching lines...) Expand all Loading... |
2881 client_.reset(client); | 2864 client_.reset(client); |
2882 static EpollEvent event(EPOLLOUT, false); | 2865 static EpollEvent event(EPOLLOUT, false); |
2883 client_writer_->Initialize( | 2866 client_writer_->Initialize( |
2884 QuicConnectionPeer::GetHelper(client_->client()->session()->connection()), | 2867 QuicConnectionPeer::GetHelper(client_->client()->session()->connection()), |
2885 QuicConnectionPeer::GetAlarmFactory( | 2868 QuicConnectionPeer::GetAlarmFactory( |
2886 client_->client()->session()->connection()), | 2869 client_->client()->session()->connection()), |
2887 new ClientDelegate(client_->client())); | 2870 new ClientDelegate(client_->client())); |
2888 initialized_ = true; | 2871 initialized_ = true; |
2889 ASSERT_TRUE(client_->client()->connected()); | 2872 ASSERT_TRUE(client_->client()->connected()); |
2890 | 2873 |
2891 client_->client()->WaitForCryptoHandshakeConfirmed(); | 2874 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
2892 SetPacketLossPercentage(1); | 2875 SetPacketLossPercentage(1); |
2893 client_->SendRequest("/huge_response"); | 2876 client_->SendRequest("/huge_response"); |
2894 client_->WaitForResponse(); | 2877 client_->WaitForResponse(); |
2895 // TODO(fayang): Fix this test to work with stateless rejects. | 2878 // TODO(fayang): Fix this test to work with stateless rejects. |
2896 if (!BothSidesSupportStatelessRejects()) { | 2879 if (!BothSidesSupportStatelessRejects()) { |
2897 VerifyCleanConnection(true); | 2880 VerifyCleanConnection(true); |
2898 } | 2881 } |
2899 } | 2882 } |
2900 | 2883 |
2901 TEST_P(EndToEndTest, ReleaseHeadersStreamBufferWhenIdle) { | 2884 TEST_P(EndToEndTest, ReleaseHeadersStreamBufferWhenIdle) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2957 client_->WaitForResponse(); | 2940 client_->WaitForResponse(); |
2958 EXPECT_EQ(kBarResponseBody, client_->response_body()); | 2941 EXPECT_EQ(kBarResponseBody, client_->response_body()); |
2959 QuicConnectionStats client_stats = | 2942 QuicConnectionStats client_stats = |
2960 client_->client()->session()->connection()->GetStats(); | 2943 client_->client()->session()->connection()->GetStats(); |
2961 EXPECT_EQ(0u, client_stats.packets_lost); | 2944 EXPECT_EQ(0u, client_stats.packets_lost); |
2962 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); | 2945 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); |
2963 } | 2946 } |
2964 } // namespace | 2947 } // namespace |
2965 } // namespace test | 2948 } // namespace test |
2966 } // namespace net | 2949 } // namespace net |
OLD | NEW |