Chromium Code Reviews| 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 <list> | 8 #include <list> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 675 IPEndPoint(IPAddress::IPv6Localhost(), server_address_.port()); | 675 IPEndPoint(IPAddress::IPv6Localhost(), server_address_.port()); |
| 676 ASSERT_TRUE(Initialize()); | 676 ASSERT_TRUE(Initialize()); |
| 677 | 677 |
| 678 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 678 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 679 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); | 679 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 680 } | 680 } |
| 681 | 681 |
| 682 TEST_P(EndToEndTest, SeparateFinPacket) { | 682 TEST_P(EndToEndTest, SeparateFinPacket) { |
| 683 ASSERT_TRUE(Initialize()); | 683 ASSERT_TRUE(Initialize()); |
| 684 | 684 |
| 685 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | |
| 686 request.set_has_complete_message(false); | |
| 687 | |
| 688 // Send a request in two parts: the request and then an empty packet with FIN. | 685 // Send a request in two parts: the request and then an empty packet with FIN. |
| 689 client_->SendMessage(request); | 686 SpdyHeaderBlock headers; |
| 687 headers[":method"] = "POST"; | |
| 688 headers[":path"] = "/foo"; | |
| 689 headers[":scheme"] = "https"; | |
| 690 headers[":authority"] = server_hostname_; | |
| 691 client_->SendMessage(headers, "", /*fin=*/false); | |
| 690 client_->SendData("", true); | 692 client_->SendData("", true); |
| 691 client_->WaitForResponse(); | 693 client_->WaitForResponse(); |
| 692 EXPECT_EQ(kFooResponseBody, client_->response_body()); | 694 EXPECT_EQ(kFooResponseBody, client_->response_body()); |
| 693 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); | 695 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 694 | 696 |
| 695 // Now do the same thing but with a content length. | 697 // Now do the same thing but with a content length. |
| 696 request.AddBody("foo", true); | 698 headers["content-length"] = "3"; |
| 697 client_->SendMessage(request); | 699 client_->SendMessage(headers, "", /*fin=*/false); |
| 698 client_->SendData("", true); | 700 client_->SendData("foo", true); |
| 699 client_->WaitForResponse(); | 701 client_->WaitForResponse(); |
| 700 EXPECT_EQ(kFooResponseBody, client_->response_body()); | 702 EXPECT_EQ(kFooResponseBody, client_->response_body()); |
| 701 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); | 703 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 702 } | 704 } |
| 703 | 705 |
| 704 TEST_P(EndToEndTest, MultipleRequestResponse) { | 706 TEST_P(EndToEndTest, MultipleRequestResponse) { |
| 705 ASSERT_TRUE(Initialize()); | 707 ASSERT_TRUE(Initialize()); |
| 706 | 708 |
| 707 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 709 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 708 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); | 710 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 709 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); | 711 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); |
| 710 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); | 712 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 711 } | 713 } |
| 712 | 714 |
| 713 TEST_P(EndToEndTest, MultipleClients) { | 715 TEST_P(EndToEndTest, MultipleClients) { |
| 714 ASSERT_TRUE(Initialize()); | 716 ASSERT_TRUE(Initialize()); |
| 715 std::unique_ptr<QuicTestClient> client2(CreateQuicClient(nullptr)); | 717 std::unique_ptr<QuicTestClient> client2(CreateQuicClient(nullptr)); |
| 716 | 718 |
| 717 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 719 SpdyHeaderBlock headers; |
| 718 request.AddHeader("content-length", "3"); | 720 headers[":method"] = "POST"; |
| 719 request.set_has_complete_message(false); | 721 headers[":path"] = "/foo"; |
| 722 headers[":scheme"] = "https"; | |
| 723 headers[":authority"] = server_hostname_; | |
| 724 headers["content-length"] = "3"; | |
| 720 | 725 |
| 721 client_->SendMessage(request); | 726 client_->SendMessage(headers, "", /*fin=*/false); |
| 722 client2->SendMessage(request); | 727 client2->SendMessage(headers, "", /*fin=*/false); |
| 723 | 728 |
| 724 client_->SendData("bar", true); | 729 client_->SendData("bar", true); |
| 725 client_->WaitForResponse(); | 730 client_->WaitForResponse(); |
| 726 EXPECT_EQ(kFooResponseBody, client_->response_body()); | 731 EXPECT_EQ(kFooResponseBody, client_->response_body()); |
| 727 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); | 732 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 728 | 733 |
| 729 client2->SendData("eep", true); | 734 client2->SendData("eep", true); |
| 730 client2->WaitForResponse(); | 735 client2->WaitForResponse(); |
| 731 EXPECT_EQ(kFooResponseBody, client2->response_body()); | 736 EXPECT_EQ(kFooResponseBody, client2->response_body()); |
| 732 EXPECT_EQ("200", client2->response_headers()->find(":status")->second); | 737 EXPECT_EQ("200", client2->response_headers()->find(":status")->second); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 753 SetReorderPercentage(50); | 758 SetReorderPercentage(50); |
| 754 | 759 |
| 755 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest(huge_request)); | 760 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest(huge_request)); |
| 756 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); | 761 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 757 } | 762 } |
| 758 | 763 |
| 759 TEST_P(EndToEndTest, PostMissingBytes) { | 764 TEST_P(EndToEndTest, PostMissingBytes) { |
| 760 ASSERT_TRUE(Initialize()); | 765 ASSERT_TRUE(Initialize()); |
| 761 | 766 |
| 762 // Add a content length header with no body. | 767 // Add a content length header with no body. |
| 763 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 768 SpdyHeaderBlock headers; |
| 764 request.AddHeader("content-length", "3"); | 769 headers[":method"] = "POST"; |
| 765 request.set_skip_message_validation(true); | 770 headers[":path"] = "/foo"; |
| 771 headers[":scheme"] = "https"; | |
| 772 headers[":authority"] = server_hostname_; | |
| 773 headers["content-length"] = "3"; | |
| 766 | 774 |
| 767 // This should be detected as stream fin without complete request, | 775 // This should be detected as stream fin without complete request, |
| 768 // triggering an error response. | 776 // triggering an error response. |
| 769 client_->SendCustomSynchronousRequest(request); | 777 client_->SendCustomSynchronousRequest(headers, ""); |
| 770 EXPECT_EQ(QuicSimpleServerStream::kErrorResponseBody, | 778 EXPECT_EQ(QuicSimpleServerStream::kErrorResponseBody, |
| 771 client_->response_body()); | 779 client_->response_body()); |
| 772 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); | 780 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); |
| 773 } | 781 } |
| 774 | 782 |
| 775 TEST_P(EndToEndTest, LargePostNoPacketLoss) { | 783 TEST_P(EndToEndTest, LargePostNoPacketLoss) { |
| 776 ASSERT_TRUE(Initialize()); | 784 ASSERT_TRUE(Initialize()); |
| 777 | 785 |
| 778 client_->client()->WaitForCryptoHandshakeConfirmed(); | 786 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 779 | 787 |
| 780 // 1 MB body. | 788 // 1 MB body. |
| 781 string body; | 789 string body; |
| 782 GenerateBody(&body, 1024 * 1024); | 790 GenerateBody(&body, 1024 * 1024); |
| 783 | 791 |
| 784 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 792 SpdyHeaderBlock headers; |
| 785 request.AddBody(body, true); | 793 headers[":method"] = "POST"; |
| 794 headers[":path"] = "/foo"; | |
| 795 headers[":scheme"] = "https"; | |
| 796 headers[":authority"] = server_hostname_; | |
| 786 | 797 |
| 787 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | 798 EXPECT_EQ(kFooResponseBody, |
| 799 client_->SendCustomSynchronousRequest(headers, body)); | |
| 788 // TODO(ianswett): There should not be packet loss in this test, but on some | 800 // TODO(ianswett): There should not be packet loss in this test, but on some |
| 789 // platforms the receive buffer overflows. | 801 // platforms the receive buffer overflows. |
| 790 VerifyCleanConnection(true); | 802 VerifyCleanConnection(true); |
| 791 } | 803 } |
| 792 | 804 |
| 793 TEST_P(EndToEndTest, LargePostNoPacketLoss1sRTT) { | 805 TEST_P(EndToEndTest, LargePostNoPacketLoss1sRTT) { |
| 794 ASSERT_TRUE(Initialize()); | 806 ASSERT_TRUE(Initialize()); |
| 795 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(1000)); | 807 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(1000)); |
| 796 | 808 |
| 797 client_->client()->WaitForCryptoHandshakeConfirmed(); | 809 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 798 | 810 |
| 799 // 100 KB body. | 811 // 100 KB body. |
| 800 string body; | 812 string body; |
| 801 GenerateBody(&body, 100 * 1024); | 813 GenerateBody(&body, 100 * 1024); |
| 814 SpdyHeaderBlock headers; | |
| 815 headers[":method"] = "POST"; | |
| 816 headers[":path"] = "/foo"; | |
| 817 headers[":scheme"] = "https"; | |
| 818 headers[":authority"] = server_hostname_; | |
| 802 | 819 |
| 803 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 820 EXPECT_EQ(kFooResponseBody, |
| 804 request.AddBody(body, true); | 821 client_->SendCustomSynchronousRequest(headers, body)); |
| 805 | |
| 806 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | |
| 807 VerifyCleanConnection(false); | 822 VerifyCleanConnection(false); |
| 808 } | 823 } |
| 809 | 824 |
| 810 TEST_P(EndToEndTest, LargePostWithPacketLoss) { | 825 TEST_P(EndToEndTest, LargePostWithPacketLoss) { |
| 811 if (!BothSidesSupportStatelessRejects()) { | 826 if (!BothSidesSupportStatelessRejects()) { |
| 812 // Connect with lower fake packet loss than we'd like to test. | 827 // Connect with lower fake packet loss than we'd like to test. |
| 813 // Until b/10126687 is fixed, losing handshake packets is pretty | 828 // Until b/10126687 is fixed, losing handshake packets is pretty |
| 814 // brutal. | 829 // brutal. |
| 815 // TODO(jokulik): Until we support redundant SREJ packets, don't | 830 // TODO(jokulik): Until we support redundant SREJ packets, don't |
| 816 // drop handshake packets for stateless rejects. | 831 // drop handshake packets for stateless rejects. |
| 817 SetPacketLossPercentage(5); | 832 SetPacketLossPercentage(5); |
| 818 } | 833 } |
| 819 ASSERT_TRUE(Initialize()); | 834 ASSERT_TRUE(Initialize()); |
| 820 | 835 |
| 821 // Wait for the server SHLO before upping the packet loss. | 836 // Wait for the server SHLO before upping the packet loss. |
| 822 client_->client()->WaitForCryptoHandshakeConfirmed(); | 837 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 823 SetPacketLossPercentage(30); | 838 SetPacketLossPercentage(30); |
| 824 | 839 |
| 825 // 10 KB body. | 840 // 10 KB body. |
| 826 string body; | 841 string body; |
| 827 GenerateBody(&body, 1024 * 10); | 842 GenerateBody(&body, 1024 * 10); |
| 843 test::GenerateBody(&body, 1024 * 10); | |
| 844 SpdyHeaderBlock headers; | |
| 845 headers[":method"] = "POST"; | |
| 846 headers[":path"] = "/foo"; | |
| 847 headers[":scheme"] = "https"; | |
| 848 headers[":authority"] = server_hostname_; | |
| 828 | 849 |
| 829 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 850 EXPECT_EQ(kFooResponseBody, |
| 830 request.AddBody(body, true); | 851 client_->SendCustomSynchronousRequest(headers, body)); |
| 831 | |
| 832 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | |
| 833 VerifyCleanConnection(true); | 852 VerifyCleanConnection(true); |
| 834 } | 853 } |
| 835 | 854 |
| 836 TEST_P(EndToEndTest, LargePostWithPacketLossAndBlockedSocket) { | 855 TEST_P(EndToEndTest, LargePostWithPacketLossAndBlockedSocket) { |
| 837 if (!BothSidesSupportStatelessRejects()) { | 856 if (!BothSidesSupportStatelessRejects()) { |
| 838 // Connect with lower fake packet loss than we'd like to test. Until | 857 // Connect with lower fake packet loss than we'd like to test. Until |
| 839 // b/10126687 is fixed, losing handshake packets is pretty brutal. | 858 // b/10126687 is fixed, losing handshake packets is pretty brutal. |
| 840 // TODO(jokulik): Until we support redundant SREJ packets, don't | 859 // TODO(jokulik): Until we support redundant SREJ packets, don't |
| 841 // drop handshake packets for stateless rejects. | 860 // drop handshake packets for stateless rejects. |
| 842 SetPacketLossPercentage(5); | 861 SetPacketLossPercentage(5); |
| 843 } | 862 } |
| 844 ASSERT_TRUE(Initialize()); | 863 ASSERT_TRUE(Initialize()); |
| 845 | 864 |
| 846 // Wait for the server SHLO before upping the packet loss. | 865 // Wait for the server SHLO before upping the packet loss. |
| 847 client_->client()->WaitForCryptoHandshakeConfirmed(); | 866 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 848 SetPacketLossPercentage(10); | 867 SetPacketLossPercentage(10); |
| 849 client_writer_->set_fake_blocked_socket_percentage(10); | 868 client_writer_->set_fake_blocked_socket_percentage(10); |
| 850 | 869 |
| 851 // 10 KB body. | 870 // 10 KB body. |
| 852 string body; | 871 string body; |
| 853 GenerateBody(&body, 1024 * 10); | 872 GenerateBody(&body, 1024 * 10); |
| 873 SpdyHeaderBlock headers; | |
| 874 headers[":method"] = "POST"; | |
| 875 headers[":path"] = "/foo"; | |
| 876 headers[":scheme"] = "https"; | |
| 877 headers[":authority"] = server_hostname_; | |
| 854 | 878 |
| 855 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 879 EXPECT_EQ(kFooResponseBody, |
| 856 request.AddBody(body, true); | 880 client_->SendCustomSynchronousRequest(headers, body)); |
| 857 | |
| 858 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | |
| 859 } | 881 } |
| 860 | 882 |
| 861 TEST_P(EndToEndTest, LargePostNoPacketLossWithDelayAndReordering) { | 883 TEST_P(EndToEndTest, LargePostNoPacketLossWithDelayAndReordering) { |
| 862 ASSERT_TRUE(Initialize()); | 884 ASSERT_TRUE(Initialize()); |
| 863 | 885 |
| 864 client_->client()->WaitForCryptoHandshakeConfirmed(); | 886 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 865 // Both of these must be called when the writer is not actively used. | 887 // Both of these must be called when the writer is not actively used. |
| 866 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); | 888 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); |
| 867 SetReorderPercentage(30); | 889 SetReorderPercentage(30); |
| 868 | 890 |
| 869 // 1 MB body. | 891 // 1 MB body. |
| 870 string body; | 892 string body; |
| 871 GenerateBody(&body, 1024 * 1024); | 893 GenerateBody(&body, 1024 * 1024); |
| 894 SpdyHeaderBlock headers; | |
| 895 headers[":method"] = "POST"; | |
| 896 headers[":path"] = "/foo"; | |
| 897 headers[":scheme"] = "https"; | |
| 898 headers[":authority"] = server_hostname_; | |
| 872 | 899 |
| 873 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 900 EXPECT_EQ(kFooResponseBody, |
| 874 request.AddBody(body, true); | 901 client_->SendCustomSynchronousRequest(headers, body)); |
| 875 | |
| 876 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | |
| 877 } | 902 } |
| 878 | 903 |
| 879 TEST_P(EndToEndTest, LargePostZeroRTTFailure) { | 904 TEST_P(EndToEndTest, LargePostZeroRTTFailure) { |
| 880 // Have the server accept 0-RTT without waiting a startup period. | 905 // Have the server accept 0-RTT without waiting a startup period. |
| 881 strike_register_no_startup_period_ = true; | 906 strike_register_no_startup_period_ = true; |
| 882 | 907 |
| 883 // Send a request and then disconnect. This prepares the client to attempt | 908 // Send a request and then disconnect. This prepares the client to attempt |
| 884 // a 0-RTT handshake for the next request. | 909 // a 0-RTT handshake for the next request. |
| 885 ASSERT_TRUE(Initialize()); | 910 ASSERT_TRUE(Initialize()); |
| 886 | 911 |
| 887 string body; | 912 string body; |
| 888 GenerateBody(&body, 20480); | 913 GenerateBody(&body, 20480); |
| 914 SpdyHeaderBlock headers; | |
| 915 headers[":method"] = "POST"; | |
| 916 headers[":path"] = "/foo"; | |
| 917 headers[":scheme"] = "https"; | |
| 918 headers[":authority"] = server_hostname_; | |
| 889 | 919 |
| 890 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 920 EXPECT_EQ(kFooResponseBody, |
| 891 request.AddBody(body, true); | 921 client_->SendCustomSynchronousRequest(headers, body)); |
| 892 | |
| 893 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | |
| 894 // In the non-stateless case, the same session is used for both | 922 // In the non-stateless case, the same session is used for both |
| 895 // hellos, so the number of hellos sent on that session is 2. In | 923 // hellos, so the number of hellos sent on that session is 2. In |
| 896 // the stateless case, the first client session will be completely | 924 // the stateless case, the first client session will be completely |
| 897 // torn down after the reject. The number of hellos on the latest | 925 // torn down after the reject. The number of hellos on the latest |
| 898 // session is 1. | 926 // session is 1. |
| 899 const int expected_num_hellos_latest_session = | 927 const int expected_num_hellos_latest_session = |
| 900 BothSidesSupportStatelessRejects() ? 1 : 2; | 928 BothSidesSupportStatelessRejects() ? 1 : 2; |
| 901 EXPECT_EQ(expected_num_hellos_latest_session, | 929 EXPECT_EQ(expected_num_hellos_latest_session, |
| 902 client_->client()->session()->GetNumSentClientHellos()); | 930 client_->client()->session()->GetNumSentClientHellos()); |
| 903 EXPECT_EQ(2, client_->client()->GetNumSentClientHellos()); | 931 EXPECT_EQ(2, client_->client()->GetNumSentClientHellos()); |
| 904 | 932 |
| 905 client_->Disconnect(); | 933 client_->Disconnect(); |
| 906 | 934 |
| 907 // The 0-RTT handshake should succeed. | 935 // The 0-RTT handshake should succeed. |
| 908 client_->Connect(); | 936 client_->Connect(); |
| 909 client_->WaitForResponseForMs(-1); | 937 client_->WaitForResponseForMs(-1); |
| 910 ASSERT_TRUE(client_->client()->connected()); | 938 ASSERT_TRUE(client_->client()->connected()); |
| 911 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | 939 EXPECT_EQ(kFooResponseBody, |
| 940 client_->SendCustomSynchronousRequest(headers, body)); | |
| 912 | 941 |
| 913 if (negotiated_version_ <= QUIC_VERSION_32) { | 942 if (negotiated_version_ <= QUIC_VERSION_32) { |
| 914 EXPECT_EQ(expected_num_hellos_latest_session, | 943 EXPECT_EQ(expected_num_hellos_latest_session, |
| 915 client_->client()->session()->GetNumSentClientHellos()); | 944 client_->client()->session()->GetNumSentClientHellos()); |
| 916 EXPECT_EQ(2, client_->client()->GetNumSentClientHellos()); | 945 EXPECT_EQ(2, client_->client()->GetNumSentClientHellos()); |
| 917 } else { | 946 } else { |
| 918 EXPECT_EQ(1, client_->client()->session()->GetNumSentClientHellos()); | 947 EXPECT_EQ(1, client_->client()->session()->GetNumSentClientHellos()); |
| 919 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); | 948 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); |
| 920 } | 949 } |
| 921 | 950 |
| 922 client_->Disconnect(); | 951 client_->Disconnect(); |
| 923 | 952 |
| 924 // Restart the server so that the 0-RTT handshake will take 1 RTT. | 953 // Restart the server so that the 0-RTT handshake will take 1 RTT. |
| 925 StopServer(); | 954 StopServer(); |
| 926 server_writer_ = new PacketDroppingTestWriter(); | 955 server_writer_ = new PacketDroppingTestWriter(); |
| 927 StartServer(); | 956 StartServer(); |
| 928 | 957 |
| 929 client_->Connect(); | 958 client_->Connect(); |
| 930 ASSERT_TRUE(client_->client()->connected()); | 959 ASSERT_TRUE(client_->client()->connected()); |
| 931 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | 960 EXPECT_EQ(kFooResponseBody, |
| 961 client_->SendCustomSynchronousRequest(headers, body)); | |
| 932 // In the non-stateless case, the same session is used for both | 962 // In the non-stateless case, the same session is used for both |
| 933 // hellos, so the number of hellos sent on that session is 2. In | 963 // hellos, so the number of hellos sent on that session is 2. In |
| 934 // the stateless case, the first client session will be completely | 964 // the stateless case, the first client session will be completely |
| 935 // torn down after the reject. The number of hellos sent on the | 965 // torn down after the reject. The number of hellos sent on the |
| 936 // latest session is 1. | 966 // latest session is 1. |
| 937 EXPECT_EQ(expected_num_hellos_latest_session, | 967 EXPECT_EQ(expected_num_hellos_latest_session, |
| 938 client_->client()->session()->GetNumSentClientHellos()); | 968 client_->client()->session()->GetNumSentClientHellos()); |
| 939 EXPECT_EQ(2, client_->client()->GetNumSentClientHellos()); | 969 EXPECT_EQ(2, client_->client()->GetNumSentClientHellos()); |
| 940 | 970 |
| 941 VerifyCleanConnection(false); | 971 VerifyCleanConnection(false); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1003 TEST_P(EndToEndTest, LargePostSynchronousRequest) { | 1033 TEST_P(EndToEndTest, LargePostSynchronousRequest) { |
| 1004 // Have the server accept 0-RTT without waiting a startup period. | 1034 // Have the server accept 0-RTT without waiting a startup period. |
| 1005 strike_register_no_startup_period_ = true; | 1035 strike_register_no_startup_period_ = true; |
| 1006 | 1036 |
| 1007 // Send a request and then disconnect. This prepares the client to attempt | 1037 // Send a request and then disconnect. This prepares the client to attempt |
| 1008 // a 0-RTT handshake for the next request. | 1038 // a 0-RTT handshake for the next request. |
| 1009 ASSERT_TRUE(Initialize()); | 1039 ASSERT_TRUE(Initialize()); |
| 1010 | 1040 |
| 1011 string body; | 1041 string body; |
| 1012 GenerateBody(&body, 20480); | 1042 GenerateBody(&body, 20480); |
| 1043 SpdyHeaderBlock headers; | |
| 1044 headers[":method"] = "POST"; | |
| 1045 headers[":path"] = "/foo"; | |
| 1046 headers[":scheme"] = "https"; | |
| 1047 headers[":authority"] = server_hostname_; | |
| 1013 | 1048 |
| 1014 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 1049 EXPECT_EQ(kFooResponseBody, |
| 1015 request.AddBody(body, true); | 1050 client_->SendCustomSynchronousRequest(headers, body)); |
| 1016 | |
| 1017 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | |
| 1018 // In the non-stateless case, the same session is used for both | 1051 // In the non-stateless case, the same session is used for both |
| 1019 // hellos, so the number of hellos sent on that session is 2. In | 1052 // hellos, so the number of hellos sent on that session is 2. In |
| 1020 // the stateless case, the first client session will be completely | 1053 // the stateless case, the first client session will be completely |
| 1021 // torn down after the reject. The number of hellos on the latest | 1054 // torn down after the reject. The number of hellos on the latest |
| 1022 // session is 1. | 1055 // session is 1. |
| 1023 const int expected_num_hellos_latest_session = | 1056 const int expected_num_hellos_latest_session = |
| 1024 BothSidesSupportStatelessRejects() ? 1 : 2; | 1057 BothSidesSupportStatelessRejects() ? 1 : 2; |
| 1025 EXPECT_EQ(expected_num_hellos_latest_session, | 1058 EXPECT_EQ(expected_num_hellos_latest_session, |
| 1026 client_->client()->session()->GetNumSentClientHellos()); | 1059 client_->client()->session()->GetNumSentClientHellos()); |
| 1027 EXPECT_EQ(2, client_->client()->GetNumSentClientHellos()); | 1060 EXPECT_EQ(2, client_->client()->GetNumSentClientHellos()); |
| 1028 | 1061 |
| 1029 client_->Disconnect(); | 1062 client_->Disconnect(); |
| 1030 | 1063 |
| 1031 // The 0-RTT handshake should succeed. | 1064 // The 0-RTT handshake should succeed. |
| 1032 client_->Connect(); | 1065 client_->Connect(); |
| 1033 client_->WaitForInitialResponse(); | 1066 client_->WaitForInitialResponse(); |
| 1034 ASSERT_TRUE(client_->client()->connected()); | 1067 ASSERT_TRUE(client_->client()->connected()); |
| 1035 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | 1068 EXPECT_EQ(kFooResponseBody, |
| 1069 client_->SendCustomSynchronousRequest(headers, body)); | |
| 1036 | 1070 |
| 1037 if (negotiated_version_ <= QUIC_VERSION_32) { | 1071 if (negotiated_version_ <= QUIC_VERSION_32) { |
| 1038 EXPECT_EQ(expected_num_hellos_latest_session, | 1072 EXPECT_EQ(expected_num_hellos_latest_session, |
| 1039 client_->client()->session()->GetNumSentClientHellos()); | 1073 client_->client()->session()->GetNumSentClientHellos()); |
| 1040 EXPECT_EQ(2, client_->client()->GetNumSentClientHellos()); | 1074 EXPECT_EQ(2, client_->client()->GetNumSentClientHellos()); |
| 1041 } else { | 1075 } else { |
| 1042 EXPECT_EQ(1, client_->client()->session()->GetNumSentClientHellos()); | 1076 EXPECT_EQ(1, client_->client()->session()->GetNumSentClientHellos()); |
| 1043 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); | 1077 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); |
| 1044 } | 1078 } |
| 1045 | 1079 |
| 1046 client_->Disconnect(); | 1080 client_->Disconnect(); |
| 1047 | 1081 |
| 1048 // Restart the server so that the 0-RTT handshake will take 1 RTT. | 1082 // Restart the server so that the 0-RTT handshake will take 1 RTT. |
| 1049 StopServer(); | 1083 StopServer(); |
| 1050 server_writer_ = new PacketDroppingTestWriter(); | 1084 server_writer_ = new PacketDroppingTestWriter(); |
| 1051 StartServer(); | 1085 StartServer(); |
| 1052 | 1086 |
| 1053 client_->Connect(); | 1087 client_->Connect(); |
| 1054 ASSERT_TRUE(client_->client()->connected()); | 1088 ASSERT_TRUE(client_->client()->connected()); |
| 1055 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1089 EXPECT_EQ(kFooResponseBody, |
| 1090 client_->SendCustomSynchronousRequest(headers, body)); | |
| 1056 // In the non-stateless case, the same session is used for both | 1091 // In the non-stateless case, the same session is used for both |
| 1057 // hellos, so the number of hellos sent on that session is 2. In | 1092 // hellos, so the number of hellos sent on that session is 2. In |
| 1058 // the stateless case, the first client session will be completely | 1093 // the stateless case, the first client session will be completely |
| 1059 // torn down after the reject. The number of hellos sent on the | 1094 // torn down after the reject. The number of hellos sent on the |
| 1060 // latest session is 1. | 1095 // latest session is 1. |
| 1061 EXPECT_EQ(expected_num_hellos_latest_session, | 1096 EXPECT_EQ(expected_num_hellos_latest_session, |
| 1062 client_->client()->session()->GetNumSentClientHellos()); | 1097 client_->client()->session()->GetNumSentClientHellos()); |
| 1063 EXPECT_EQ(2, client_->client()->GetNumSentClientHellos()); | 1098 EXPECT_EQ(2, client_->client()->GetNumSentClientHellos()); |
| 1064 | 1099 |
| 1065 VerifyCleanConnection(false); | 1100 VerifyCleanConnection(false); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1105 // 256KB per second with a 256KB buffer from server to client. Wireless | 1140 // 256KB per second with a 256KB buffer from server to client. Wireless |
| 1106 // clients commonly have larger buffers, but our max CWND is 200. | 1141 // clients commonly have larger buffers, but our max CWND is 200. |
| 1107 server_writer_->set_max_bandwidth_and_buffer_size( | 1142 server_writer_->set_max_bandwidth_and_buffer_size( |
| 1108 QuicBandwidth::FromBytesPerSecond(256 * 1024), 256 * 1024); | 1143 QuicBandwidth::FromBytesPerSecond(256 * 1024), 256 * 1024); |
| 1109 | 1144 |
| 1110 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1145 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 1111 | 1146 |
| 1112 // 1 MB body. | 1147 // 1 MB body. |
| 1113 string body; | 1148 string body; |
| 1114 GenerateBody(&body, 1024 * 1024); | 1149 GenerateBody(&body, 1024 * 1024); |
| 1150 SpdyHeaderBlock headers; | |
| 1151 headers[":method"] = "POST"; | |
| 1152 headers[":path"] = "/foo"; | |
| 1153 headers[":scheme"] = "https"; | |
| 1154 headers[":authority"] = server_hostname_; | |
| 1115 | 1155 |
| 1116 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 1156 EXPECT_EQ(kFooResponseBody, |
| 1117 request.AddBody(body, true); | 1157 client_->SendCustomSynchronousRequest(headers, body)); |
| 1118 | |
| 1119 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | |
| 1120 // This connection may drop packets, because the buffer is smaller than the | 1158 // This connection may drop packets, because the buffer is smaller than the |
| 1121 // max CWND. | 1159 // max CWND. |
| 1122 VerifyCleanConnection(true); | 1160 VerifyCleanConnection(true); |
| 1123 } | 1161 } |
| 1124 | 1162 |
| 1125 TEST_P(EndToEndTest, DoNotSetResumeWriteAlarmIfConnectionFlowControlBlocked) { | 1163 TEST_P(EndToEndTest, DoNotSetResumeWriteAlarmIfConnectionFlowControlBlocked) { |
| 1126 // Regression test for b/14677858. | 1164 // Regression test for b/14677858. |
| 1127 // Test that the resume write alarm is not set in QuicConnection::OnCanWrite | 1165 // Test that the resume write alarm is not set in QuicConnection::OnCanWrite |
| 1128 // if currently connection level flow control blocked. If set, this results in | 1166 // if currently connection level flow control blocked. If set, this results in |
| 1129 // an infinite loop in the EpollServer, as the alarm fires and is immediately | 1167 // an infinite loop in the EpollServer, as the alarm fires and is immediately |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1162 EXPECT_FALSE(resume_writes_alarm->IsSet()); | 1200 EXPECT_FALSE(resume_writes_alarm->IsSet()); |
| 1163 } | 1201 } |
| 1164 | 1202 |
| 1165 TEST_P(EndToEndTest, InvalidStream) { | 1203 TEST_P(EndToEndTest, InvalidStream) { |
| 1166 ASSERT_TRUE(Initialize()); | 1204 ASSERT_TRUE(Initialize()); |
| 1167 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1205 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 1168 | 1206 |
| 1169 string body; | 1207 string body; |
| 1170 GenerateBody(&body, kMaxPacketSize); | 1208 GenerateBody(&body, kMaxPacketSize); |
| 1171 | 1209 |
| 1172 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 1210 SpdyHeaderBlock headers; |
| 1173 request.AddBody(body, true); | 1211 headers[":method"] = "POST"; |
| 1212 headers[":path"] = "/foo"; | |
| 1213 headers[":scheme"] = "https"; | |
| 1214 headers[":authority"] = server_hostname_; | |
| 1174 // Force the client to write with a stream ID belonging to a nonexistent | 1215 // Force the client to write with a stream ID belonging to a nonexistent |
| 1175 // server-side stream. | 1216 // server-side stream. |
| 1176 QuicSessionPeer::SetNextOutgoingStreamId(client_->client()->session(), 2); | 1217 QuicSessionPeer::SetNextOutgoingStreamId(client_->client()->session(), 2); |
| 1177 | 1218 |
| 1178 client_->SendCustomSynchronousRequest(request); | 1219 client_->SendCustomSynchronousRequest(headers, body); |
| 1179 // EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); | 1220 // EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); |
| 1180 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); | 1221 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); |
| 1181 EXPECT_EQ(QUIC_INVALID_STREAM_ID, client_->connection_error()); | 1222 EXPECT_EQ(QUIC_INVALID_STREAM_ID, client_->connection_error()); |
| 1182 } | 1223 } |
| 1183 | 1224 |
| 1184 // Test that if the the server will close the connection if the client attempts | 1225 // Test that if the the server will close the connection if the client attempts |
| 1185 // to send a request with overly large headers. | 1226 // to send a request with overly large headers. |
| 1186 TEST_P(EndToEndTest, LargeHeaders) { | 1227 TEST_P(EndToEndTest, LargeHeaders) { |
| 1187 ASSERT_TRUE(Initialize()); | 1228 ASSERT_TRUE(Initialize()); |
| 1188 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1229 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 1189 | 1230 |
| 1190 string body; | 1231 string body; |
| 1191 test::GenerateBody(&body, kMaxPacketSize); | 1232 test::GenerateBody(&body, kMaxPacketSize); |
| 1192 | 1233 |
| 1193 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 1234 SpdyHeaderBlock headers; |
| 1194 request.AddHeader("key1", string(15 * 1024, 'a')); | 1235 headers[":method"] = "POST"; |
| 1195 request.AddHeader("key2", string(15 * 1024, 'a')); | 1236 headers[":path"] = "/foo"; |
| 1196 request.AddHeader("key3", string(15 * 1024, 'a')); | 1237 headers[":scheme"] = "https"; |
| 1197 request.AddBody(body, true); | 1238 headers[":authority"] = server_hostname_; |
| 1239 headers["key1"] = string(15 * 1024, 'a'); | |
| 1240 headers["key2"] = string(15 * 1024, 'a'); | |
| 1241 headers["key3"] = string(15 * 1024, 'a'); | |
| 1198 | 1242 |
| 1199 client_->SendCustomSynchronousRequest(request); | 1243 client_->SendMessage(headers, body); |
|
Zhongyi Shi
2016/11/03 15:15:22
I think this should be:
client_->SendCustomSynchro
Ryan Hamilton
2016/11/03 15:26:17
Done.
| |
| 1200 if (FLAGS_quic_limit_uncompressed_headers) { | 1244 if (FLAGS_quic_limit_uncompressed_headers) { |
| 1201 EXPECT_EQ(QUIC_HEADERS_TOO_LARGE, client_->stream_error()); | 1245 EXPECT_EQ(QUIC_HEADERS_TOO_LARGE, client_->stream_error()); |
| 1202 } else { | 1246 } else { |
| 1203 EXPECT_EQ(QUIC_STREAM_NO_ERROR, client_->stream_error()); | 1247 EXPECT_EQ(QUIC_STREAM_NO_ERROR, client_->stream_error()); |
| 1204 EXPECT_EQ(kFooResponseBody, client_->response_body()); | 1248 EXPECT_EQ(kFooResponseBody, client_->response_body()); |
| 1205 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); | 1249 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 1206 } | 1250 } |
| 1207 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); | 1251 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); |
| 1208 } | 1252 } |
| 1209 | 1253 |
| 1210 TEST_P(EndToEndTest, EarlyResponseWithQuicStreamNoError) { | 1254 TEST_P(EndToEndTest, EarlyResponseWithQuicStreamNoError) { |
| 1211 ASSERT_TRUE(Initialize()); | 1255 ASSERT_TRUE(Initialize()); |
| 1212 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1256 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 1213 | 1257 |
| 1214 string large_body; | 1258 string large_body; |
| 1215 GenerateBody(&large_body, 1024 * 1024); | 1259 GenerateBody(&large_body, 1024 * 1024); |
| 1216 | 1260 |
| 1217 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 1261 SpdyHeaderBlock headers; |
| 1218 request.AddBody(large_body, false); | 1262 headers[":method"] = "POST"; |
| 1263 headers[":path"] = "/foo"; | |
| 1264 headers[":scheme"] = "https"; | |
| 1265 headers[":authority"] = server_hostname_; | |
| 1219 | 1266 |
| 1220 // Insert an invalid content_length field in request to trigger an early | 1267 // Insert an invalid content_length field in request to trigger an early |
| 1221 // response from server. | 1268 // response from server. |
| 1222 request.AddHeader("content-length", "-3"); | 1269 headers["content-length"] = "-3"; |
| 1223 | 1270 |
| 1224 request.set_skip_message_validation(true); | 1271 client_->SendMessage(headers, large_body); |
|
Zhongyi Shi
2016/11/03 15:15:22
ditto
Ryan Hamilton
2016/11/03 15:26:17
Done.
| |
| 1225 client_->SendCustomSynchronousRequest(request); | |
| 1226 EXPECT_EQ("bad", client_->response_body()); | 1272 EXPECT_EQ("bad", client_->response_body()); |
| 1227 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); | 1273 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); |
| 1228 EXPECT_EQ(QUIC_STREAM_NO_ERROR, client_->stream_error()); | 1274 EXPECT_EQ(QUIC_STREAM_NO_ERROR, client_->stream_error()); |
| 1229 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); | 1275 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); |
| 1230 } | 1276 } |
| 1231 | 1277 |
| 1232 // TODO(rch): this test seems to cause net_unittests timeouts :| | 1278 // TODO(rch): this test seems to cause net_unittests timeouts :| |
| 1233 TEST_P(EndToEndTest, DISABLED_MultipleTermination) { | 1279 TEST_P(EndToEndTest, DISABLED_MultipleTermination) { |
| 1234 ASSERT_TRUE(Initialize()); | 1280 ASSERT_TRUE(Initialize()); |
| 1235 | 1281 |
| 1236 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | |
| 1237 request.AddHeader("content-length", "3"); | |
| 1238 request.set_has_complete_message(false); | |
| 1239 | |
| 1240 // Set the offset so we won't frame. Otherwise when we pick up termination | 1282 // Set the offset so we won't frame. Otherwise when we pick up termination |
| 1241 // before HTTP framing is complete, we send an error and close the stream, | 1283 // before HTTP framing is complete, we send an error and close the stream, |
| 1242 // and the second write is picked up as writing on a closed stream. | 1284 // and the second write is picked up as writing on a closed stream. |
| 1243 QuicSpdyClientStream* stream = client_->GetOrCreateStream(); | 1285 QuicSpdyClientStream* stream = client_->GetOrCreateStream(); |
| 1244 ASSERT_TRUE(stream != nullptr); | 1286 ASSERT_TRUE(stream != nullptr); |
| 1245 ReliableQuicStreamPeer::SetStreamBytesWritten(3, stream); | 1287 ReliableQuicStreamPeer::SetStreamBytesWritten(3, stream); |
| 1246 | 1288 |
| 1247 client_->SendData("bar", true); | 1289 client_->SendData("bar", true); |
| 1248 client_->WaitForWriteToFlush(); | 1290 client_->WaitForWriteToFlush(); |
| 1249 | 1291 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1275 if (negotiated_version_ > QUIC_VERSION_34) { | 1317 if (negotiated_version_ > QUIC_VERSION_34) { |
| 1276 // Newer versions use max incoming dynamic streams. | 1318 // Newer versions use max incoming dynamic streams. |
| 1277 return; | 1319 return; |
| 1278 } | 1320 } |
| 1279 | 1321 |
| 1280 // Make the client misbehave after negotiation. | 1322 // Make the client misbehave after negotiation. |
| 1281 const int kServerMaxStreams = kMaxStreamsMinimumIncrement + 1; | 1323 const int kServerMaxStreams = kMaxStreamsMinimumIncrement + 1; |
| 1282 QuicSessionPeer::SetMaxOpenOutgoingStreams(client_->client()->session(), | 1324 QuicSessionPeer::SetMaxOpenOutgoingStreams(client_->client()->session(), |
| 1283 kServerMaxStreams + 1); | 1325 kServerMaxStreams + 1); |
| 1284 | 1326 |
| 1285 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 1327 SpdyHeaderBlock headers; |
| 1286 request.AddHeader("content-length", "3"); | 1328 headers[":method"] = "POST"; |
| 1287 request.set_has_complete_message(false); | 1329 headers[":path"] = "/foo"; |
| 1330 headers[":scheme"] = "https"; | |
| 1331 headers[":authority"] = server_hostname_; | |
| 1332 headers["content-length"] = "3"; | |
| 1288 | 1333 |
| 1289 // The server supports a small number of additional streams beyond the | 1334 // The server supports a small number of additional streams beyond the |
| 1290 // negotiated limit. Open enough streams to go beyond that limit. | 1335 // negotiated limit. Open enough streams to go beyond that limit. |
| 1291 for (int i = 0; i < kServerMaxStreams + 1; ++i) { | 1336 for (int i = 0; i < kServerMaxStreams + 1; ++i) { |
| 1292 client_->SendMessage(request); | 1337 client_->SendMessage(headers, "", /*fin=*/false); |
| 1293 } | 1338 } |
| 1294 client_->WaitForResponse(); | 1339 client_->WaitForResponse(); |
| 1295 | 1340 |
| 1296 EXPECT_TRUE(client_->connected()); | 1341 EXPECT_TRUE(client_->connected()); |
| 1297 EXPECT_EQ(QUIC_REFUSED_STREAM, client_->stream_error()); | 1342 EXPECT_EQ(QUIC_REFUSED_STREAM, client_->stream_error()); |
| 1298 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); | 1343 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); |
| 1299 } | 1344 } |
| 1300 | 1345 |
| 1301 TEST_P(EndToEndTest, MaxIncomingDynamicStreamsLimitRespected) { | 1346 TEST_P(EndToEndTest, MaxIncomingDynamicStreamsLimitRespected) { |
| 1302 // Set a limit on maximum number of incoming dynamic streams. | 1347 // Set a limit on maximum number of incoming dynamic streams. |
| 1303 // Make sure the limit is respected. | 1348 // Make sure the limit is respected. |
| 1304 const uint32_t kServerMaxIncomingDynamicStreams = 1; | 1349 const uint32_t kServerMaxIncomingDynamicStreams = 1; |
| 1305 server_config_.SetMaxIncomingDynamicStreamsToSend( | 1350 server_config_.SetMaxIncomingDynamicStreamsToSend( |
| 1306 kServerMaxIncomingDynamicStreams); | 1351 kServerMaxIncomingDynamicStreams); |
| 1307 ASSERT_TRUE(Initialize()); | 1352 ASSERT_TRUE(Initialize()); |
| 1308 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1353 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 1309 | 1354 |
| 1310 if (negotiated_version_ <= QUIC_VERSION_34) { | 1355 if (negotiated_version_ <= QUIC_VERSION_34) { |
| 1311 // Earlier versions negotiated max open streams. | 1356 // Earlier versions negotiated max open streams. |
| 1312 return; | 1357 return; |
| 1313 } | 1358 } |
| 1314 | 1359 |
| 1315 // Make the client misbehave after negotiation. | 1360 // Make the client misbehave after negotiation. |
| 1316 const int kServerMaxStreams = | 1361 const int kServerMaxStreams = |
| 1317 kMaxStreamsMinimumIncrement + kServerMaxIncomingDynamicStreams; | 1362 kMaxStreamsMinimumIncrement + kServerMaxIncomingDynamicStreams; |
| 1318 QuicSessionPeer::SetMaxOpenOutgoingStreams(client_->client()->session(), | 1363 QuicSessionPeer::SetMaxOpenOutgoingStreams(client_->client()->session(), |
| 1319 kServerMaxStreams + 1); | 1364 kServerMaxStreams + 1); |
| 1320 | 1365 |
| 1321 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 1366 SpdyHeaderBlock headers; |
| 1322 request.AddHeader("content-length", "3"); | 1367 headers[":method"] = "POST"; |
| 1323 request.set_has_complete_message(false); | 1368 headers[":path"] = "/foo"; |
| 1369 headers[":scheme"] = "https"; | |
| 1370 headers[":authority"] = server_hostname_; | |
| 1371 headers["content-length"] = "3"; | |
| 1324 | 1372 |
| 1325 // The server supports a small number of additional streams beyond the | 1373 // The server supports a small number of additional streams beyond the |
| 1326 // negotiated limit. Open enough streams to go beyond that limit. | 1374 // negotiated limit. Open enough streams to go beyond that limit. |
| 1327 for (int i = 0; i < kServerMaxStreams + 1; ++i) { | 1375 for (int i = 0; i < kServerMaxStreams + 1; ++i) { |
| 1328 client_->SendMessage(request); | 1376 client_->SendMessage(headers, "", /*fin=*/false); |
| 1329 } | 1377 } |
| 1330 client_->WaitForResponse(); | 1378 client_->WaitForResponse(); |
| 1331 | 1379 |
| 1332 EXPECT_TRUE(client_->connected()); | 1380 EXPECT_TRUE(client_->connected()); |
| 1333 EXPECT_EQ(QUIC_REFUSED_STREAM, client_->stream_error()); | 1381 EXPECT_EQ(QUIC_REFUSED_STREAM, client_->stream_error()); |
| 1334 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); | 1382 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); |
| 1335 } | 1383 } |
| 1336 | 1384 |
| 1337 TEST_P(EndToEndTest, SetIndependentMaxIncomingDynamicStreamsLimits) { | 1385 TEST_P(EndToEndTest, SetIndependentMaxIncomingDynamicStreamsLimits) { |
| 1338 // Each endpoint can set max incoming dynamic streams independently. | 1386 // Each endpoint can set max incoming dynamic streams independently. |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1908 SetPacketLossPercentage(5); | 1956 SetPacketLossPercentage(5); |
| 1909 } | 1957 } |
| 1910 ASSERT_TRUE(Initialize()); | 1958 ASSERT_TRUE(Initialize()); |
| 1911 | 1959 |
| 1912 // Wait for the server SHLO before upping the packet loss. | 1960 // Wait for the server SHLO before upping the packet loss. |
| 1913 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1961 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 1914 SetPacketLossPercentage(30); | 1962 SetPacketLossPercentage(30); |
| 1915 client_writer_->set_fake_blocked_socket_percentage(10); | 1963 client_writer_->set_fake_blocked_socket_percentage(10); |
| 1916 | 1964 |
| 1917 // Create a POST request and send the headers only. | 1965 // Create a POST request and send the headers only. |
| 1918 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 1966 SpdyHeaderBlock headers; |
| 1919 request.set_has_complete_message(false); | 1967 headers[":method"] = "POST"; |
| 1920 client_->SendMessage(request); | 1968 headers[":path"] = "/foo"; |
| 1969 headers[":scheme"] = "https"; | |
| 1970 headers[":authority"] = server_hostname_; | |
| 1971 | |
| 1972 client_->SendMessage(headers, "", /*fin=*/false); | |
| 1921 | 1973 |
| 1922 // The TestAckListener will cause a failure if not notified. | 1974 // The TestAckListener will cause a failure if not notified. |
| 1923 scoped_refptr<TestAckListener> delegate(new TestAckListener(2)); | 1975 scoped_refptr<TestAckListener> delegate(new TestAckListener(2)); |
| 1924 | 1976 |
| 1925 // Test the AckNotifier's ability to track multiple packets by making the | 1977 // Test the AckNotifier's ability to track multiple packets by making the |
| 1926 // request body exceed the size of a single packet. | 1978 // request body exceed the size of a single packet. |
| 1927 string request_string = | 1979 string request_string = |
| 1928 "a request body bigger than one packet" + string(kMaxPacketSize, '.'); | 1980 "a request body bigger than one packet" + string(kMaxPacketSize, '.'); |
| 1929 | 1981 |
| 1930 // Send the request, and register the delegate for ACKs. | 1982 // Send the request, and register the delegate for ACKs. |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2423 | 2475 |
| 2424 StreamWithErrorFactory stream_factory(response_body); | 2476 StreamWithErrorFactory stream_factory(response_body); |
| 2425 SetSpdyStreamFactory(&stream_factory); | 2477 SetSpdyStreamFactory(&stream_factory); |
| 2426 | 2478 |
| 2427 ASSERT_TRUE(Initialize()); | 2479 ASSERT_TRUE(Initialize()); |
| 2428 | 2480 |
| 2429 client_->client()->WaitForCryptoHandshakeConfirmed(); | 2481 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 2430 | 2482 |
| 2431 // A POST that gets an early error response, after the headers are received | 2483 // A POST that gets an early error response, after the headers are received |
| 2432 // and before the body is received, due to invalid content-length. | 2484 // and before the body is received, due to invalid content-length. |
| 2433 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/garbage"); | 2485 SpdyHeaderBlock headers; |
| 2486 headers[":method"] = "POST"; | |
| 2487 headers[":path"] = "/garbage"; | |
| 2488 headers[":scheme"] = "https"; | |
| 2489 headers[":authority"] = server_hostname_; | |
| 2490 | |
| 2434 // The body must be large enough that the FIN will be in a different packet | 2491 // The body must be large enough that the FIN will be in a different packet |
| 2435 // than the end of the headers, but short enough to not require a flow control | 2492 // than the end of the headers, but short enough to not require a flow control |
| 2436 // update. This allows headers processing to trigger the error response | 2493 // update. This allows headers processing to trigger the error response |
| 2437 // before the request FIN is processed but receive the request FIN before the | 2494 // before the request FIN is processed but receive the request FIN before the |
| 2438 // response is sent completely. | 2495 // response is sent completely. |
| 2439 const uint32_t kRequestBodySize = kMaxPacketSize + 10; | 2496 const uint32_t kRequestBodySize = kMaxPacketSize + 10; |
| 2440 string request_body; | 2497 string request_body; |
| 2441 GenerateBody(&request_body, kRequestBodySize); | 2498 GenerateBody(&request_body, kRequestBodySize); |
| 2442 request.AddBody(request_body, false); | |
| 2443 // Set an invalid content-length, so the request will receive an early 500 | 2499 // Set an invalid content-length, so the request will receive an early 500 |
| 2444 // response. Must be done after AddBody, which also sets content-length. | 2500 // response. Must be done after AddBody, which also sets content-length. |
| 2445 request.AddHeader("content-length", "-1"); | 2501 headers["content-length"] = "-1"; |
| 2446 request.set_skip_message_validation(true); | |
| 2447 | 2502 |
| 2448 // Send the request. | 2503 // Send the request. |
| 2449 client_->SendMessage(request); | 2504 client_->SendMessage(headers, request_body); |
| 2450 client_->WaitForResponse(); | 2505 client_->WaitForResponse(); |
| 2451 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); | 2506 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); |
| 2452 | 2507 |
| 2453 // Pause the server so we can access the server's internals without races. | 2508 // Pause the server so we can access the server's internals without races. |
| 2454 server_thread_->Pause(); | 2509 server_thread_->Pause(); |
| 2455 | 2510 |
| 2456 QuicDispatcher* dispatcher = | 2511 QuicDispatcher* dispatcher = |
| 2457 QuicServerPeer::GetDispatcher(server_thread_->server()); | 2512 QuicServerPeer::GetDispatcher(server_thread_->server()); |
| 2458 QuicDispatcher::SessionMap const& map = | 2513 QuicDispatcher::SessionMap const& map = |
| 2459 QuicDispatcherPeer::session_map(dispatcher); | 2514 QuicDispatcherPeer::session_map(dispatcher); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 2475 set_client_initial_session_flow_control_receive_window(kWindowSize); | 2530 set_client_initial_session_flow_control_receive_window(kWindowSize); |
| 2476 set_server_initial_stream_flow_control_receive_window(kWindowSize); | 2531 set_server_initial_stream_flow_control_receive_window(kWindowSize); |
| 2477 set_server_initial_session_flow_control_receive_window(kWindowSize); | 2532 set_server_initial_session_flow_control_receive_window(kWindowSize); |
| 2478 | 2533 |
| 2479 ASSERT_TRUE(Initialize()); | 2534 ASSERT_TRUE(Initialize()); |
| 2480 | 2535 |
| 2481 client_->client()->WaitForCryptoHandshakeConfirmed(); | 2536 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 2482 | 2537 |
| 2483 // POST to a URL that gets an early error response, after the headers are | 2538 // POST to a URL that gets an early error response, after the headers are |
| 2484 // received and before the body is received. | 2539 // received and before the body is received. |
| 2485 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/garbage"); | 2540 SpdyHeaderBlock headers; |
| 2541 headers[":method"] = "POST"; | |
| 2542 headers[":path"] = "/garbage"; | |
| 2543 headers[":scheme"] = "https"; | |
| 2544 headers[":authority"] = server_hostname_; | |
| 2545 | |
| 2486 // Invalid content-length so the request will receive an early 500 response. | 2546 // Invalid content-length so the request will receive an early 500 response. |
| 2487 request.AddHeader("content-length", "-1"); | 2547 headers["content-length"] = "-1"; |
| 2488 request.set_skip_message_validation(true); | |
| 2489 request.set_has_complete_message(false); | |
| 2490 | 2548 |
| 2491 // Tell the client to not close the stream if it receives an early response. | 2549 // Tell the client to not close the stream if it receives an early response. |
| 2492 client_->set_allow_bidirectional_data(true); | 2550 client_->set_allow_bidirectional_data(true); |
| 2493 // Send the headers. | 2551 // Send the headers. |
| 2494 client_->SendMessage(request); | 2552 client_->SendMessage(headers, "", false); |
| 2495 // Receive the response and let the server close writing. | 2553 // Receive the response and let the server close writing. |
| 2496 client_->WaitForInitialResponse(); | 2554 client_->WaitForInitialResponse(); |
| 2497 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); | 2555 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); |
| 2498 | 2556 |
| 2499 // Receive the reset stream from server on early response. | 2557 // Receive the reset stream from server on early response. |
| 2500 ReliableQuicStream* stream = | 2558 ReliableQuicStream* stream = |
| 2501 client_->client()->session()->GetOrCreateStream(kClientDataStreamId1); | 2559 client_->client()->session()->GetOrCreateStream(kClientDataStreamId1); |
| 2502 // The stream is reset by server's reset stream. | 2560 // The stream is reset by server's reset stream. |
| 2503 EXPECT_EQ(stream, nullptr); | 2561 EXPECT_EQ(stream, nullptr); |
| 2504 } | 2562 } |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2854 ASSERT_TRUE(Initialize()); | 2912 ASSERT_TRUE(Initialize()); |
| 2855 // Set client's epoll server's time out to 0 to make this test be finished | 2913 // Set client's epoll server's time out to 0 to make this test be finished |
| 2856 // within a short time. | 2914 // within a short time. |
| 2857 client_->epoll_server()->set_timeout_in_us(0); | 2915 client_->epoll_server()->set_timeout_in_us(0); |
| 2858 | 2916 |
| 2859 client_->client()->WaitForCryptoHandshakeConfirmed(); | 2917 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 2860 SetPacketLossPercentage(1); | 2918 SetPacketLossPercentage(1); |
| 2861 // To avoid storing the whole request body in memory, use a loop to repeatedly | 2919 // To avoid storing the whole request body in memory, use a loop to repeatedly |
| 2862 // send body size of kSizeBytes until the whole request body size is reached. | 2920 // send body size of kSizeBytes until the whole request body size is reached. |
| 2863 const int kSizeBytes = 128 * 1024; | 2921 const int kSizeBytes = 128 * 1024; |
| 2864 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 2922 SpdyHeaderBlock headers; |
| 2923 headers[":method"] = "POST"; | |
| 2924 headers[":path"] = "/foo"; | |
| 2925 headers[":scheme"] = "https"; | |
| 2926 headers[":authority"] = server_hostname_; | |
| 2927 | |
| 2865 // Request body size is 4G plus one more kSizeBytes. | 2928 // Request body size is 4G plus one more kSizeBytes. |
| 2866 int64_t request_body_size_bytes = pow(2, 32) + kSizeBytes; | 2929 int64_t request_body_size_bytes = pow(2, 32) + kSizeBytes; |
| 2867 ASSERT_LT(INT64_C(4294967296), request_body_size_bytes); | 2930 ASSERT_LT(INT64_C(4294967296), request_body_size_bytes); |
| 2868 request.AddHeader("content-length", IntToString(request_body_size_bytes)); | 2931 headers["content-length"] = IntToString(request_body_size_bytes); |
| 2869 request.set_has_complete_message(false); | |
| 2870 string body; | 2932 string body; |
| 2871 test::GenerateBody(&body, kSizeBytes); | 2933 test::GenerateBody(&body, kSizeBytes); |
| 2872 | 2934 |
| 2873 client_->SendMessage(request); | 2935 client_->SendMessage(headers, "", /*fin=*/false); |
| 2874 for (int i = 0; i < request_body_size_bytes / kSizeBytes; ++i) { | 2936 for (int i = 0; i < request_body_size_bytes / kSizeBytes; ++i) { |
| 2875 bool fin = (i == request_body_size_bytes - 1); | 2937 bool fin = (i == request_body_size_bytes - 1); |
| 2876 client_->SendData(string(body.data(), kSizeBytes), fin); | 2938 client_->SendData(string(body.data(), kSizeBytes), fin); |
| 2877 client_->client()->WaitForEvents(); | 2939 client_->client()->WaitForEvents(); |
| 2878 } | 2940 } |
| 2879 VerifyCleanConnection(true); | 2941 VerifyCleanConnection(true); |
| 2880 } | 2942 } |
| 2881 | 2943 |
| 2882 // TODO(fayang): this test seems to cause net_unittests timeouts :| | 2944 // TODO(fayang): this test seems to cause net_unittests timeouts :| |
| 2883 TEST_P(EndToEndTest, DISABLED_TestHugeResponseWithPacketLoss) { | 2945 TEST_P(EndToEndTest, DISABLED_TestHugeResponseWithPacketLoss) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2971 client_->Disconnect(); | 3033 client_->Disconnect(); |
| 2972 | 3034 |
| 2973 // Client get valid STK now. Do a 0-rtt request. | 3035 // Client get valid STK now. Do a 0-rtt request. |
| 2974 // Buffer a CHLO till another packets sent out. | 3036 // Buffer a CHLO till another packets sent out. |
| 2975 reorder_writer_->SetDelay(1); | 3037 reorder_writer_->SetDelay(1); |
| 2976 // Only send out a CHLO. | 3038 // Only send out a CHLO. |
| 2977 client_->client()->Initialize(); | 3039 client_->client()->Initialize(); |
| 2978 client_->client()->StartConnect(); | 3040 client_->client()->StartConnect(); |
| 2979 ASSERT_TRUE(client_->client()->connected()); | 3041 ASSERT_TRUE(client_->client()->connected()); |
| 2980 // Send a request before handshake finishes. | 3042 // Send a request before handshake finishes. |
| 2981 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::GET, "/bar"); | 3043 SpdyHeaderBlock headers; |
| 2982 client_->SendMessage(request); | 3044 headers[":method"] = "POST"; |
| 3045 headers[":path"] = "/bar"; | |
| 3046 headers[":scheme"] = "https"; | |
| 3047 headers[":authority"] = server_hostname_; | |
| 3048 | |
| 3049 client_->SendMessage(headers, ""); | |
| 2983 client_->WaitForResponse(); | 3050 client_->WaitForResponse(); |
| 2984 EXPECT_EQ(kBarResponseBody, client_->response_body()); | 3051 EXPECT_EQ(kBarResponseBody, client_->response_body()); |
| 2985 QuicConnectionStats client_stats = | 3052 QuicConnectionStats client_stats = |
| 2986 client_->client()->session()->connection()->GetStats(); | 3053 client_->client()->session()->connection()->GetStats(); |
| 2987 EXPECT_EQ(0u, client_stats.packets_lost); | 3054 EXPECT_EQ(0u, client_stats.packets_lost); |
| 2988 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); | 3055 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); |
| 2989 } | 3056 } |
| 2990 } // namespace | 3057 } // namespace |
| 2991 } // namespace test | 3058 } // namespace test |
| 2992 } // namespace net | 3059 } // namespace net |
| OLD | NEW |