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
3 // found in the LICENSE file.
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/singleton.h"
13 #include "base/strings/string_number_conversions.h"
14 #include "base/synchronization/waitable_event.h"
15 #include "base/time/time.h"
16 #include "net/base/ip_endpoint.h"
17 #include "net/quic/congestion_control/tcp_cubic_sender.h"
18 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h"
19 #include "net/quic/crypto/null_encrypter.h"
20 #include "net/quic/quic_flags.h"
21 #include "net/quic/quic_framer.h"
22 #include "net/quic/quic_packet_creator.h"
23 #include "net/quic/quic_protocol.h"
24 #include "net/quic/quic_server_id.h"
25 #include "net/quic/quic_utils.h"
26 #include "net/quic/test_tools/quic_connection_peer.h"
27 #include "net/quic/test_tools/quic_flow_controller_peer.h"
28 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h"
29 #include "net/quic/test_tools/quic_session_peer.h"
30 #include "net/quic/test_tools/quic_test_utils.h"
31 #include "net/quic/test_tools/reliable_quic_stream_peer.h"
32 #include "net/test/gtest_util.h"
33 #include "net/tools/epoll_server/epoll_server.h"
34 #include "net/tools/quic/quic_epoll_connection_helper.h"
35 #include "net/tools/quic/quic_in_memory_cache.h"
36 #include "net/tools/quic/quic_packet_writer_wrapper.h"
37 #include "net/tools/quic/quic_server.h"
38 #include "net/tools/quic/quic_socket_utils.h"
39 #include "net/tools/quic/quic_spdy_client_stream.h"
40 #include "net/tools/quic/test_tools/http_message.h"
41 #include "net/tools/quic/test_tools/packet_dropping_test_writer.h"
42 #include "net/tools/quic/test_tools/quic_client_peer.h"
43 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h"
44 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h"
45 #include "net/tools/quic/test_tools/quic_server_peer.h"
46 #include "net/tools/quic/test_tools/quic_test_client.h"
47 #include "net/tools/quic/test_tools/server_thread.h"
48 #include "testing/gtest/include/gtest/gtest.h"
50 using base::StringPiece
;
51 using base::WaitableEvent
;
52 using net::EpollServer
;
53 using net::test::GenerateBody
;
54 using net::test::QuicConnectionPeer
;
55 using net::test::QuicFlowControllerPeer
;
56 using net::test::QuicSentPacketManagerPeer
;
57 using net::test::QuicSessionPeer
;
58 using net::test::ReliableQuicStreamPeer
;
59 using net::test::ValueRestore
;
60 using net::test::kClientDataStreamId1
;
61 using net::tools::test::PacketDroppingTestWriter
;
62 using net::tools::test::QuicDispatcherPeer
;
63 using net::tools::test::QuicServerPeer
;
73 const char* kFooResponseBody
= "Artichoke hearts make me happy.";
74 const char* kBarResponseBody
= "Palm hearts are pretty delicious, also.";
76 // Run all tests with the cross products of all versions.
78 TestParams(const QuicVersionVector
& client_supported_versions
,
79 const QuicVersionVector
& server_supported_versions
,
80 QuicVersion negotiated_version
,
83 QuicTag congestion_control_tag
)
84 : client_supported_versions(client_supported_versions
),
85 server_supported_versions(server_supported_versions
),
86 negotiated_version(negotiated_version
),
87 use_pacing(use_pacing
),
89 congestion_control_tag(congestion_control_tag
) {
92 friend ostream
& operator<<(ostream
& os
, const TestParams
& p
) {
93 os
<< "{ server_supported_versions: "
94 << QuicVersionVectorToString(p
.server_supported_versions
);
95 os
<< " client_supported_versions: "
96 << QuicVersionVectorToString(p
.client_supported_versions
);
97 os
<< " negotiated_version: " << QuicVersionToString(p
.negotiated_version
);
98 os
<< " use_pacing: " << p
.use_pacing
;
99 os
<< " use_fec: " << p
.use_fec
;
100 os
<< " congestion_control_tag: "
101 << QuicUtils::TagToString(p
.congestion_control_tag
) << " }";
105 QuicVersionVector client_supported_versions
;
106 QuicVersionVector server_supported_versions
;
107 QuicVersion negotiated_version
;
110 QuicTag congestion_control_tag
;
113 // Constructs various test permutations.
114 vector
<TestParams
> GetTestParams() {
115 vector
<TestParams
> params
;
116 QuicVersionVector all_supported_versions
= QuicSupportedVersions();
117 // TODO(rtenneti): Add kTBBR after BBR code is checked in.
118 // QuicTag congestion_control_tags[] = {kRENO, kTBBR, kQBIC};
119 QuicTag congestion_control_tags
[] = {kRENO
, kQBIC
};
120 for (size_t congestion_control_index
= 0;
121 congestion_control_index
< arraysize(congestion_control_tags
);
122 congestion_control_index
++) {
123 QuicTag congestion_control_tag
=
124 congestion_control_tags
[congestion_control_index
];
125 for (int use_fec
= 0; use_fec
< 2; ++use_fec
) {
126 for (int use_pacing
= 0; use_pacing
< 2; ++use_pacing
) {
127 // Add an entry for server and client supporting all versions.
128 params
.push_back(TestParams(all_supported_versions
,
129 all_supported_versions
,
130 all_supported_versions
[0],
133 congestion_control_tag
));
135 // Test client supporting all versions and server supporting 1 version.
136 // Simulate an old server and exercise version downgrade in the client.
137 // Protocol negotiation should occur. Skip the i = 0 case because it is
138 // essentially the same as the default case.
139 for (size_t i
= 1; i
< all_supported_versions
.size(); ++i
) {
140 QuicVersionVector server_supported_versions
;
141 server_supported_versions
.push_back(all_supported_versions
[i
]);
142 params
.push_back(TestParams(all_supported_versions
,
143 server_supported_versions
,
144 server_supported_versions
[0],
147 congestion_control_tag
));
155 class ServerDelegate
: public PacketDroppingTestWriter::Delegate
{
157 ServerDelegate(TestWriterFactory
* writer_factory
,
158 QuicDispatcher
* dispatcher
)
159 : writer_factory_(writer_factory
),
160 dispatcher_(dispatcher
) {}
161 ~ServerDelegate() override
{}
162 void OnPacketSent(WriteResult result
) override
{
163 writer_factory_
->OnPacketSent(result
);
165 void OnCanWrite() override
{ dispatcher_
->OnCanWrite(); }
168 TestWriterFactory
* writer_factory_
;
169 QuicDispatcher
* dispatcher_
;
172 class ClientDelegate
: public PacketDroppingTestWriter::Delegate
{
174 explicit ClientDelegate(QuicClient
* client
) : client_(client
) {}
175 ~ClientDelegate() override
{}
176 void OnPacketSent(WriteResult result
) override
{}
177 void OnCanWrite() override
{
178 EpollEvent
event(EPOLLOUT
, false);
179 client_
->OnEvent(client_
->fd(), &event
);
186 class EndToEndTest
: public ::testing::TestWithParam
<TestParams
> {
189 : server_hostname_("example.com"),
190 server_started_(false),
191 strike_register_no_startup_period_(false) {
192 net::IPAddressNumber ip
;
193 CHECK(net::ParseIPLiteralToNumber("127.0.0.1", &ip
));
194 server_address_
= IPEndPoint(ip
, 0);
196 client_supported_versions_
= GetParam().client_supported_versions
;
197 server_supported_versions_
= GetParam().server_supported_versions
;
198 negotiated_version_
= GetParam().negotiated_version
;
199 FLAGS_enable_quic_fec
= GetParam().use_fec
;
201 VLOG(1) << "Using Configuration: " << GetParam();
203 // Use different flow control windows for client/server.
204 client_config_
.SetInitialFlowControlWindowToSend(
205 2 * kInitialSessionFlowControlWindowForTest
);
206 client_config_
.SetInitialStreamFlowControlWindowToSend(
207 2 * kInitialStreamFlowControlWindowForTest
);
208 client_config_
.SetInitialSessionFlowControlWindowToSend(
209 2 * kInitialSessionFlowControlWindowForTest
);
210 server_config_
.SetInitialFlowControlWindowToSend(
211 3 * kInitialSessionFlowControlWindowForTest
);
212 server_config_
.SetInitialStreamFlowControlWindowToSend(
213 3 * kInitialStreamFlowControlWindowForTest
);
214 server_config_
.SetInitialSessionFlowControlWindowToSend(
215 3 * kInitialSessionFlowControlWindowForTest
);
217 QuicInMemoryCachePeer::ResetForTests();
218 AddToCache("GET", "https://www.google.com/foo",
219 "HTTP/1.1", "200", "OK", kFooResponseBody
);
220 AddToCache("GET", "https://www.google.com/bar",
221 "HTTP/1.1", "200", "OK", kBarResponseBody
);
224 ~EndToEndTest() override
{
225 // TODO(rtenneti): port RecycleUnusedPort if needed.
226 // RecycleUnusedPort(server_address_.port());
227 QuicInMemoryCachePeer::ResetForTests();
230 QuicTestClient
* CreateQuicClient(QuicPacketWriterWrapper
* writer
) {
231 QuicTestClient
* client
= new QuicTestClient(
236 client_supported_versions_
);
237 client
->UseWriter(writer
);
242 void set_client_initial_flow_control_receive_window(uint32 window
) {
243 CHECK(client_
.get() == nullptr);
244 DVLOG(1) << "Setting client initial flow control window: " << window
;
245 client_config_
.SetInitialFlowControlWindowToSend(window
);
248 void set_client_initial_stream_flow_control_receive_window(uint32 window
) {
249 CHECK(client_
.get() == nullptr);
250 DVLOG(1) << "Setting client initial stream flow control window: " << window
;
251 client_config_
.SetInitialStreamFlowControlWindowToSend(window
);
254 void set_client_initial_session_flow_control_receive_window(uint32 window
) {
255 CHECK(client_
.get() == nullptr);
256 DVLOG(1) << "Setting client initial session flow control window: "
258 client_config_
.SetInitialSessionFlowControlWindowToSend(window
);
261 void set_server_initial_flow_control_receive_window(uint32 window
) {
262 CHECK(server_thread_
.get() == nullptr);
263 DVLOG(1) << "Setting server initial flow control window: " << window
;
264 server_config_
.SetInitialFlowControlWindowToSend(window
);
267 void set_server_initial_stream_flow_control_receive_window(uint32 window
) {
268 CHECK(server_thread_
.get() == nullptr);
269 DVLOG(1) << "Setting server initial stream flow control window: "
271 server_config_
.SetInitialStreamFlowControlWindowToSend(window
);
274 void set_server_initial_session_flow_control_receive_window(uint32 window
) {
275 CHECK(server_thread_
.get() == nullptr);
276 DVLOG(1) << "Setting server initial session flow control window: "
278 server_config_
.SetInitialSessionFlowControlWindowToSend(window
);
281 const QuicSentPacketManager
*
282 GetSentPacketManagerFromFirstServerSession() const {
283 QuicDispatcher
* dispatcher
=
284 QuicServerPeer::GetDispatcher(server_thread_
->server());
285 QuicSession
* session
= dispatcher
->session_map().begin()->second
;
286 return &session
->connection()->sent_packet_manager();
292 if (GetParam().use_pacing
) {
293 copt
.push_back(kPACE
);
295 server_config_
.SetConnectionOptionsToSend(copt
);
297 // TODO(nimia): Consider setting the congestion control algorithm for the
298 // client as well according to the test parameter.
299 copt
.push_back(GetParam().congestion_control_tag
);
301 if (GetParam().use_fec
) {
302 // Set FEC config in client's connection options and in client session.
303 copt
.push_back(kFHDR
);
306 client_config_
.SetConnectionOptionsToSend(copt
);
308 // Start the server first, because CreateQuicClient() attempts
309 // to connect to the server.
311 client_
.reset(CreateQuicClient(client_writer_
));
312 if (GetParam().use_fec
) {
313 // Set FecPolicy to always protect data on all streams.
314 client_
->SetFecPolicy(FEC_PROTECT_ALWAYS
);
316 static EpollEvent
event(EPOLLOUT
, false);
317 client_writer_
->Initialize(
318 reinterpret_cast<QuicEpollConnectionHelper
*>(
319 QuicConnectionPeer::GetHelper(
320 client_
->client()->session()->connection())),
321 new ClientDelegate(client_
->client()));
322 return client_
->client()->connected();
325 void SetUp() override
{
326 // The ownership of these gets transferred to the QuicPacketWriterWrapper
327 // and TestWriterFactory when Initialize() is executed.
328 client_writer_
= new PacketDroppingTestWriter();
329 server_writer_
= new PacketDroppingTestWriter();
332 void TearDown() override
{ StopServer(); }
335 server_thread_
.reset(
337 new QuicServer(server_config_
, server_supported_versions_
),
339 strike_register_no_startup_period_
));
340 server_thread_
->Initialize();
341 server_address_
= IPEndPoint(server_address_
.address(),
342 server_thread_
->GetPort());
343 QuicDispatcher
* dispatcher
=
344 QuicServerPeer::GetDispatcher(server_thread_
->server());
345 TestWriterFactory
* packet_writer_factory
= new TestWriterFactory();
346 QuicDispatcherPeer::SetPacketWriterFactory(dispatcher
,
347 packet_writer_factory
);
348 QuicDispatcherPeer::UseWriter(dispatcher
, server_writer_
);
349 server_writer_
->Initialize(
350 QuicDispatcherPeer::GetHelper(dispatcher
),
351 new ServerDelegate(packet_writer_factory
, dispatcher
));
352 server_thread_
->Start();
353 server_started_
= true;
357 if (!server_started_
)
359 if (server_thread_
.get()) {
360 server_thread_
->Quit();
361 server_thread_
->Join();
365 void AddToCache(StringPiece method
,
368 StringPiece response_code
,
369 StringPiece response_detail
,
371 QuicInMemoryCache::GetInstance()->AddSimpleResponse(
372 method
, path
, version
, response_code
, response_detail
, body
);
375 void SetPacketLossPercentage(int32 loss
) {
376 // TODO(rtenneti): enable when we can do random packet loss tests in
378 if (loss
!= 0 && loss
!= 100)
380 client_writer_
->set_fake_packet_loss_percentage(loss
);
381 server_writer_
->set_fake_packet_loss_percentage(loss
);
384 void SetPacketSendDelay(QuicTime::Delta delay
) {
385 // TODO(rtenneti): enable when we can do random packet send delay tests in
387 // client_writer_->set_fake_packet_delay(delay);
388 // server_writer_->set_fake_packet_delay(delay);
391 void SetReorderPercentage(int32 reorder
) {
392 // TODO(rtenneti): enable when we can do random packet reorder tests in
394 // client_writer_->set_fake_reorder_percentage(reorder);
395 // server_writer_->set_fake_reorder_percentage(reorder);
398 // Verifies that the client and server connections were both free of packets
399 // being discarded, based on connection stats.
400 // Calls server_thread_ Pause() and Resume(), which may only be called once
402 void VerifyCleanConnection(bool had_packet_loss
) {
403 QuicConnectionStats client_stats
=
404 client_
->client()->session()->connection()->GetStats();
405 if (!had_packet_loss
) {
406 EXPECT_EQ(0u, client_stats
.packets_lost
);
408 EXPECT_EQ(0u, client_stats
.packets_discarded
);
409 EXPECT_EQ(0u, client_stats
.packets_dropped
);
410 EXPECT_EQ(client_stats
.packets_received
, client_stats
.packets_processed
);
412 server_thread_
->Pause();
413 QuicDispatcher
* dispatcher
=
414 QuicServerPeer::GetDispatcher(server_thread_
->server());
415 ASSERT_EQ(1u, dispatcher
->session_map().size());
416 QuicSession
* session
= dispatcher
->session_map().begin()->second
;
417 QuicConnectionStats server_stats
= session
->connection()->GetStats();
418 if (!had_packet_loss
) {
419 EXPECT_EQ(0u, server_stats
.packets_lost
);
421 EXPECT_EQ(0u, server_stats
.packets_discarded
);
422 // TODO(ianswett): Restore the check for packets_dropped equals 0.
423 // The expect for packets received is equal to packets processed fails
424 // due to version negotiation packets.
425 server_thread_
->Resume();
428 IPEndPoint server_address_
;
429 string server_hostname_
;
430 scoped_ptr
<ServerThread
> server_thread_
;
431 scoped_ptr
<QuicTestClient
> client_
;
432 PacketDroppingTestWriter
* client_writer_
;
433 PacketDroppingTestWriter
* server_writer_
;
434 bool server_started_
;
435 QuicConfig client_config_
;
436 QuicConfig server_config_
;
437 QuicVersionVector client_supported_versions_
;
438 QuicVersionVector server_supported_versions_
;
439 QuicVersion negotiated_version_
;
440 bool strike_register_no_startup_period_
;
443 // Run all end to end tests with all supported versions.
444 INSTANTIATE_TEST_CASE_P(EndToEndTests
,
446 ::testing::ValuesIn(GetTestParams()));
448 TEST_P(EndToEndTest
, SimpleRequestResponse
) {
449 ASSERT_TRUE(Initialize());
451 EXPECT_EQ(kFooResponseBody
, client_
->SendSynchronousRequest("/foo"));
452 EXPECT_EQ(200u, client_
->response_headers()->parsed_response_code());
455 // TODO(rch): figure out how to detect missing v6 supprt (like on the linux
456 // try bots) and selectively disable this test.
457 TEST_P(EndToEndTest
, DISABLED_SimpleRequestResponsev6
) {
459 CHECK(net::ParseIPLiteralToNumber("::1", &ip
));
460 server_address_
= IPEndPoint(ip
, server_address_
.port());
461 ASSERT_TRUE(Initialize());
463 EXPECT_EQ(kFooResponseBody
, client_
->SendSynchronousRequest("/foo"));
464 EXPECT_EQ(200u, client_
->response_headers()->parsed_response_code());
467 TEST_P(EndToEndTest
, SeparateFinPacket
) {
468 ASSERT_TRUE(Initialize());
470 HTTPMessage
request(HttpConstants::HTTP_1_1
,
471 HttpConstants::POST
, "/foo");
472 request
.set_has_complete_message(false);
474 client_
->SendMessage(request
);
476 client_
->SendData(string(), true);
478 client_
->WaitForResponse();
479 EXPECT_EQ(kFooResponseBody
, client_
->response_body());
480 EXPECT_EQ(200u, client_
->response_headers()->parsed_response_code());
482 request
.AddBody("foo", true);
484 client_
->SendMessage(request
);
485 client_
->SendData(string(), true);
486 client_
->WaitForResponse();
487 EXPECT_EQ(kFooResponseBody
, client_
->response_body());
488 EXPECT_EQ(200u, client_
->response_headers()->parsed_response_code());
491 TEST_P(EndToEndTest
, MultipleRequestResponse
) {
492 ASSERT_TRUE(Initialize());
494 EXPECT_EQ(kFooResponseBody
, client_
->SendSynchronousRequest("/foo"));
495 EXPECT_EQ(200u, client_
->response_headers()->parsed_response_code());
496 EXPECT_EQ(kBarResponseBody
, client_
->SendSynchronousRequest("/bar"));
497 EXPECT_EQ(200u, client_
->response_headers()->parsed_response_code());
500 TEST_P(EndToEndTest
, MultipleClients
) {
501 ASSERT_TRUE(Initialize());
502 scoped_ptr
<QuicTestClient
> client2(CreateQuicClient(nullptr));
504 HTTPMessage
request(HttpConstants::HTTP_1_1
,
505 HttpConstants::POST
, "/foo");
506 request
.AddHeader("content-length", "3");
507 request
.set_has_complete_message(false);
509 client_
->SendMessage(request
);
510 client2
->SendMessage(request
);
512 client_
->SendData("bar", true);
513 client_
->WaitForResponse();
514 EXPECT_EQ(kFooResponseBody
, client_
->response_body());
515 EXPECT_EQ(200u, client_
->response_headers()->parsed_response_code());
517 client2
->SendData("eep", true);
518 client2
->WaitForResponse();
519 EXPECT_EQ(kFooResponseBody
, client2
->response_body());
520 EXPECT_EQ(200u, client2
->response_headers()->parsed_response_code());
523 TEST_P(EndToEndTest
, RequestOverMultiplePackets
) {
524 // Send a large enough request to guarantee fragmentation.
525 string huge_request
=
526 "https://www.google.com/some/path?query=" + string(kMaxPacketSize
, '.');
527 AddToCache("GET", huge_request
, "HTTP/1.1", "200", "OK", kBarResponseBody
);
529 ASSERT_TRUE(Initialize());
531 EXPECT_EQ(kBarResponseBody
, client_
->SendSynchronousRequest(huge_request
));
532 EXPECT_EQ(200u, client_
->response_headers()->parsed_response_code());
535 TEST_P(EndToEndTest
, MultiplePacketsRandomOrder
) {
536 // Send a large enough request to guarantee fragmentation.
537 string huge_request
=
538 "https://www.google.com/some/path?query=" + string(kMaxPacketSize
, '.');
539 AddToCache("GET", huge_request
, "HTTP/1.1", "200", "OK", kBarResponseBody
);
541 ASSERT_TRUE(Initialize());
542 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2));
543 SetReorderPercentage(50);
545 EXPECT_EQ(kBarResponseBody
, client_
->SendSynchronousRequest(huge_request
));
546 EXPECT_EQ(200u, client_
->response_headers()->parsed_response_code());
549 TEST_P(EndToEndTest
, PostMissingBytes
) {
550 ASSERT_TRUE(Initialize());
552 // Add a content length header with no body.
553 HTTPMessage
request(HttpConstants::HTTP_1_1
,
554 HttpConstants::POST
, "/foo");
555 request
.AddHeader("content-length", "3");
556 request
.set_skip_message_validation(true);
558 // This should be detected as stream fin without complete request,
559 // triggering an error response.
560 client_
->SendCustomSynchronousRequest(request
);
561 EXPECT_EQ("bad", client_
->response_body());
562 EXPECT_EQ(500u, client_
->response_headers()->parsed_response_code());
565 // TODO(rtenneti): DISABLED_LargePostNoPacketLoss seems to be flaky.
566 // http://crbug.com/297040.
567 TEST_P(EndToEndTest
, DISABLED_LargePostNoPacketLoss
) {
568 ASSERT_TRUE(Initialize());
570 client_
->client()->WaitForCryptoHandshakeConfirmed();
574 GenerateBody(&body
, 1024 * 1024);
576 HTTPMessage
request(HttpConstants::HTTP_1_1
,
577 HttpConstants::POST
, "/foo");
578 request
.AddBody(body
, true);
580 EXPECT_EQ(kFooResponseBody
, client_
->SendCustomSynchronousRequest(request
));
581 VerifyCleanConnection(false);
584 TEST_P(EndToEndTest
, LargePostNoPacketLoss1sRTT
) {
585 ASSERT_TRUE(Initialize());
586 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(1000));
588 client_
->client()->WaitForCryptoHandshakeConfirmed();
592 GenerateBody(&body
, 100 * 1024);
594 HTTPMessage
request(HttpConstants::HTTP_1_1
,
595 HttpConstants::POST
, "/foo");
596 request
.AddBody(body
, true);
598 EXPECT_EQ(kFooResponseBody
, client_
->SendCustomSynchronousRequest(request
));
599 VerifyCleanConnection(false);
602 TEST_P(EndToEndTest
, LargePostWithPacketLoss
) {
603 // Connect with lower fake packet loss than we'd like to test. Until
604 // b/10126687 is fixed, losing handshake packets is pretty brutal.
605 SetPacketLossPercentage(5);
606 ASSERT_TRUE(Initialize());
608 // Wait for the server SHLO before upping the packet loss.
609 client_
->client()->WaitForCryptoHandshakeConfirmed();
610 SetPacketLossPercentage(30);
614 GenerateBody(&body
, 1024 * 10);
616 HTTPMessage
request(HttpConstants::HTTP_1_1
,
617 HttpConstants::POST
, "/foo");
618 request
.AddBody(body
, true);
620 EXPECT_EQ(kFooResponseBody
, client_
->SendCustomSynchronousRequest(request
));
621 VerifyCleanConnection(true);
624 TEST_P(EndToEndTest
, LargePostWithPacketLossAndBlockedSocket
) {
625 // Connect with lower fake packet loss than we'd like to test. Until
626 // b/10126687 is fixed, losing handshake packets is pretty brutal.
627 SetPacketLossPercentage(5);
628 ASSERT_TRUE(Initialize());
630 // Wait for the server SHLO before upping the packet loss.
631 client_
->client()->WaitForCryptoHandshakeConfirmed();
632 SetPacketLossPercentage(10);
633 client_writer_
->set_fake_blocked_socket_percentage(10);
637 GenerateBody(&body
, 1024 * 10);
639 HTTPMessage
request(HttpConstants::HTTP_1_1
,
640 HttpConstants::POST
, "/foo");
641 request
.AddBody(body
, true);
643 EXPECT_EQ(kFooResponseBody
, client_
->SendCustomSynchronousRequest(request
));
646 TEST_P(EndToEndTest
, LargePostNoPacketLossWithDelayAndReordering
) {
647 ASSERT_TRUE(Initialize());
649 client_
->client()->WaitForCryptoHandshakeConfirmed();
650 // Both of these must be called when the writer is not actively used.
651 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2));
652 SetReorderPercentage(30);
656 GenerateBody(&body
, 1024 * 1024);
658 HTTPMessage
request(HttpConstants::HTTP_1_1
,
659 HttpConstants::POST
, "/foo");
660 request
.AddBody(body
, true);
662 EXPECT_EQ(kFooResponseBody
, client_
->SendCustomSynchronousRequest(request
));
665 TEST_P(EndToEndTest
, LargePostZeroRTTFailure
) {
666 // Have the server accept 0-RTT without waiting a startup period.
667 strike_register_no_startup_period_
= true;
669 // Send a request and then disconnect. This prepares the client to attempt
670 // a 0-RTT handshake for the next request.
671 ASSERT_TRUE(Initialize());
674 GenerateBody(&body
, 20480);
676 HTTPMessage
request(HttpConstants::HTTP_1_1
,
677 HttpConstants::POST
, "/foo");
678 request
.AddBody(body
, true);
680 EXPECT_EQ(kFooResponseBody
, client_
->SendCustomSynchronousRequest(request
));
681 EXPECT_EQ(2, client_
->client()->session()->GetNumSentClientHellos());
683 client_
->Disconnect();
685 // The 0-RTT handshake should succeed.
687 client_
->WaitForResponseForMs(-1);
688 ASSERT_TRUE(client_
->client()->connected());
689 EXPECT_EQ(kFooResponseBody
, client_
->SendCustomSynchronousRequest(request
));
690 EXPECT_EQ(1, client_
->client()->session()->GetNumSentClientHellos());
692 client_
->Disconnect();
694 // Restart the server so that the 0-RTT handshake will take 1 RTT.
696 server_writer_
= new PacketDroppingTestWriter();
700 ASSERT_TRUE(client_
->client()->connected());
701 EXPECT_EQ(kFooResponseBody
, client_
->SendCustomSynchronousRequest(request
));
702 EXPECT_EQ(2, client_
->client()->session()->GetNumSentClientHellos());
703 VerifyCleanConnection(false);
706 TEST_P(EndToEndTest
, CorrectlyConfiguredFec
) {
707 ASSERT_TRUE(Initialize());
708 client_
->client()->WaitForCryptoHandshakeConfirmed();
709 server_thread_
->WaitForCryptoHandshakeConfirmed();
711 FecPolicy expected_policy
=
712 GetParam().use_fec
? FEC_PROTECT_ALWAYS
: FEC_PROTECT_OPTIONAL
;
714 // Verify that server's FEC configuration is correct.
715 server_thread_
->Pause();
716 QuicDispatcher
* dispatcher
=
717 QuicServerPeer::GetDispatcher(server_thread_
->server());
718 ASSERT_EQ(1u, dispatcher
->session_map().size());
719 QuicSession
* session
= dispatcher
->session_map().begin()->second
;
720 EXPECT_EQ(expected_policy
,
721 QuicSessionPeer::GetHeadersStream(session
)->fec_policy());
722 server_thread_
->Resume();
724 // Verify that client's FEC configuration is correct.
725 EXPECT_EQ(expected_policy
,
726 QuicSessionPeer::GetHeadersStream(
727 client_
->client()->session())->fec_policy());
728 EXPECT_EQ(expected_policy
,
729 client_
->GetOrCreateStream()->fec_policy());
732 // TODO(shess): This is flaky on ChromiumOS bots.
733 // http://crbug.com/374871
734 TEST_P(EndToEndTest
, DISABLED_LargePostSmallBandwidthLargeBuffer
) {
735 ASSERT_TRUE(Initialize());
736 SetPacketSendDelay(QuicTime::Delta::FromMicroseconds(1));
737 // 256KB per second with a 256KB buffer from server to client. Wireless
738 // clients commonly have larger buffers, but our max CWND is 200.
739 server_writer_
->set_max_bandwidth_and_buffer_size(
740 QuicBandwidth::FromBytesPerSecond(256 * 1024), 256 * 1024);
742 client_
->client()->WaitForCryptoHandshakeConfirmed();
746 GenerateBody(&body
, 1024 * 1024);
748 HTTPMessage
request(HttpConstants::HTTP_1_1
,
749 HttpConstants::POST
, "/foo");
750 request
.AddBody(body
, true);
752 EXPECT_EQ(kFooResponseBody
, client_
->SendCustomSynchronousRequest(request
));
753 // This connection will not drop packets, because the buffer size is larger
754 // than the default receive window.
755 VerifyCleanConnection(false);
758 TEST_P(EndToEndTest
, DoNotSetResumeWriteAlarmIfConnectionFlowControlBlocked
) {
759 // Regression test for b/14677858.
760 // Test that the resume write alarm is not set in QuicConnection::OnCanWrite
761 // if currently connection level flow control blocked. If set, this results in
762 // an infinite loop in the EpollServer, as the alarm fires and is immediately
764 ASSERT_TRUE(Initialize());
765 client_
->client()->WaitForCryptoHandshakeConfirmed();
767 // Ensure both stream and connection level are flow control blocked by setting
768 // the send window offset to 0.
769 const uint64 kFlowControlWindow
=
770 server_config_
.GetInitialFlowControlWindowToSend();
771 QuicSpdyClientStream
* stream
= client_
->GetOrCreateStream();
772 QuicSession
* session
= client_
->client()->session();
773 QuicFlowControllerPeer::SetSendWindowOffset(stream
->flow_controller(), 0);
774 QuicFlowControllerPeer::SetSendWindowOffset(session
->flow_controller(), 0);
775 EXPECT_TRUE(stream
->flow_controller()->IsBlocked());
776 EXPECT_TRUE(session
->flow_controller()->IsBlocked());
778 // Make sure that the stream has data pending so that it will be marked as
779 // write blocked when it receives a stream level WINDOW_UPDATE.
780 stream
->SendBody("hello", false);
782 // The stream now attempts to write, fails because it is still connection
783 // level flow control blocked, and is added to the write blocked list.
784 QuicWindowUpdateFrame
window_update(stream
->id(), 2 * kFlowControlWindow
);
785 stream
->OnWindowUpdateFrame(window_update
);
787 // Prior to fixing b/14677858 this call would result in an infinite loop in
788 // Chromium. As a proxy for detecting this, we now check whether the
789 // resume_writes_alarm is set after OnCanWrite. It should not be, as the
790 // connection is still flow control blocked.
791 session
->connection()->OnCanWrite();
793 QuicAlarm
* resume_writes_alarm
=
794 QuicConnectionPeer::GetResumeWritesAlarm(session
->connection());
795 EXPECT_FALSE(resume_writes_alarm
->IsSet());
798 TEST_P(EndToEndTest
, InvalidStream
) {
799 ASSERT_TRUE(Initialize());
800 client_
->client()->WaitForCryptoHandshakeConfirmed();
803 GenerateBody(&body
, kMaxPacketSize
);
805 HTTPMessage
request(HttpConstants::HTTP_1_1
,
806 HttpConstants::POST
, "/foo");
807 request
.AddBody(body
, true);
808 // Force the client to write with a stream ID belonging to a nonexistent
809 // server-side stream.
810 QuicSessionPeer::SetNextStreamId(client_
->client()->session(), 2);
812 client_
->SendCustomSynchronousRequest(request
);
813 // EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error());
814 EXPECT_EQ(QUIC_PACKET_FOR_NONEXISTENT_STREAM
, client_
->connection_error());
817 // TODO(rch): this test seems to cause net_unittests timeouts :|
818 TEST_P(EndToEndTest
, DISABLED_MultipleTermination
) {
819 ASSERT_TRUE(Initialize());
821 HTTPMessage
request(HttpConstants::HTTP_1_1
,
822 HttpConstants::POST
, "/foo");
823 request
.AddHeader("content-length", "3");
824 request
.set_has_complete_message(false);
826 // Set the offset so we won't frame. Otherwise when we pick up termination
827 // before HTTP framing is complete, we send an error and close the stream,
828 // and the second write is picked up as writing on a closed stream.
829 QuicSpdyClientStream
* stream
= client_
->GetOrCreateStream();
830 ASSERT_TRUE(stream
!= nullptr);
831 ReliableQuicStreamPeer::SetStreamBytesWritten(3, stream
);
833 client_
->SendData("bar", true);
834 client_
->WaitForWriteToFlush();
836 // By default the stream protects itself from writes after terminte is set.
837 // Override this to test the server handling buggy clients.
838 ReliableQuicStreamPeer::SetWriteSideClosed(
839 false, client_
->GetOrCreateStream());
841 EXPECT_DFATAL(client_
->SendData("eep", true), "Fin already buffered");
844 TEST_P(EndToEndTest
, Timeout
) {
845 client_config_
.SetIdleConnectionStateLifetime(
846 QuicTime::Delta::FromMicroseconds(500),
847 QuicTime::Delta::FromMicroseconds(500));
848 // Note: we do NOT ASSERT_TRUE: we may time out during initial handshake:
849 // that's enough to validate timeout in this case.
851 while (client_
->client()->connected()) {
852 client_
->client()->WaitForEvents();
856 TEST_P(EndToEndTest
, NegotiateMaxOpenStreams
) {
857 // Negotiate 1 max open stream.
858 client_config_
.SetMaxStreamsPerConnection(1, 1);
859 ASSERT_TRUE(Initialize());
860 client_
->client()->WaitForCryptoHandshakeConfirmed();
862 // Make the client misbehave after negotiation.
863 const int kServerMaxStreams
= kMaxStreamsMinimumIncrement
+ 1;
864 QuicSessionPeer::SetMaxOpenStreams(client_
->client()->session(),
865 kServerMaxStreams
+ 1);
867 HTTPMessage
request(HttpConstants::HTTP_1_1
, HttpConstants::POST
, "/foo");
868 request
.AddHeader("content-length", "3");
869 request
.set_has_complete_message(false);
871 // The server supports a small number of additional streams beyond the
872 // negotiated limit. Open enough streams to go beyond that limit.
873 for (int i
= 0; i
< kServerMaxStreams
+ 1; ++i
) {
874 client_
->SendMessage(request
);
876 client_
->WaitForResponse();
878 EXPECT_FALSE(client_
->connected());
879 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR
, client_
->stream_error());
880 EXPECT_EQ(QUIC_TOO_MANY_OPEN_STREAMS
, client_
->connection_error());
883 TEST_P(EndToEndTest
, NegotiateCongestionControl
) {
884 ValueRestore
<bool> old_flag(&FLAGS_quic_allow_bbr
, true);
885 ASSERT_TRUE(Initialize());
886 client_
->client()->WaitForCryptoHandshakeConfirmed();
888 CongestionControlType expected_congestion_control_type
;
889 switch (GetParam().congestion_control_tag
) {
891 expected_congestion_control_type
= kReno
;
894 expected_congestion_control_type
= kBBR
;
897 expected_congestion_control_type
= kCubic
;
900 DLOG(FATAL
) << "Unexpected congestion control tag";
903 EXPECT_EQ(expected_congestion_control_type
,
904 QuicSentPacketManagerPeer::GetSendAlgorithm(
905 *GetSentPacketManagerFromFirstServerSession())
906 ->GetCongestionControlType());
909 TEST_P(EndToEndTest
, LimitMaxOpenStreams
) {
910 // Server limits the number of max streams to 2.
911 server_config_
.SetMaxStreamsPerConnection(2, 2);
912 // Client tries to negotiate for 10.
913 client_config_
.SetMaxStreamsPerConnection(10, 5);
915 ASSERT_TRUE(Initialize());
916 client_
->client()->WaitForCryptoHandshakeConfirmed();
917 QuicConfig
* client_negotiated_config
= client_
->client()->session()->config();
918 EXPECT_EQ(2u, client_negotiated_config
->MaxStreamsPerConnection());
921 TEST_P(EndToEndTest
, ClientSuggestsRTT
) {
922 // Client suggests initial RTT, verify it is used.
923 const uint32 kInitialRTT
= 20000;
924 client_config_
.SetInitialRoundTripTimeUsToSend(kInitialRTT
);
926 ASSERT_TRUE(Initialize());
927 client_
->client()->WaitForCryptoHandshakeConfirmed();
928 server_thread_
->WaitForCryptoHandshakeConfirmed();
930 // Pause the server so we can access the server's internals without races.
931 server_thread_
->Pause();
932 QuicDispatcher
* dispatcher
=
933 QuicServerPeer::GetDispatcher(server_thread_
->server());
934 ASSERT_EQ(1u, dispatcher
->session_map().size());
935 const QuicSentPacketManager
& client_sent_packet_manager
=
936 client_
->client()->session()->connection()->sent_packet_manager();
937 const QuicSentPacketManager
& server_sent_packet_manager
=
938 *GetSentPacketManagerFromFirstServerSession();
940 // BBR automatically enables pacing.
941 EXPECT_EQ(GetParam().use_pacing
||
942 (FLAGS_quic_allow_bbr
&&
943 GetParam().congestion_control_tag
== kTBBR
),
944 server_sent_packet_manager
.using_pacing());
945 EXPECT_EQ(GetParam().use_pacing
||
946 (FLAGS_quic_allow_bbr
&&
947 GetParam().congestion_control_tag
== kTBBR
),
948 client_sent_packet_manager
.using_pacing());
950 EXPECT_EQ(kInitialRTT
,
951 client_sent_packet_manager
.GetRttStats()->initial_rtt_us());
952 EXPECT_EQ(kInitialRTT
,
953 server_sent_packet_manager
.GetRttStats()->initial_rtt_us());
954 server_thread_
->Resume();
957 TEST_P(EndToEndTest
, MaxInitialRTT
) {
958 // Client tries to suggest twice the server's max initial rtt and the server
960 client_config_
.SetInitialRoundTripTimeUsToSend(
961 2 * kMaxInitialRoundTripTimeUs
);
963 ASSERT_TRUE(Initialize());
964 client_
->client()->WaitForCryptoHandshakeConfirmed();
965 server_thread_
->WaitForCryptoHandshakeConfirmed();
967 // Pause the server so we can access the server's internals without races.
968 server_thread_
->Pause();
969 QuicDispatcher
* dispatcher
=
970 QuicServerPeer::GetDispatcher(server_thread_
->server());
971 ASSERT_EQ(1u, dispatcher
->session_map().size());
972 QuicSession
* session
= dispatcher
->session_map().begin()->second
;
973 const QuicSentPacketManager
& client_sent_packet_manager
=
974 client_
->client()->session()->connection()->sent_packet_manager();
976 // Now that acks have been exchanged, the RTT estimate has decreased on the
977 // server and is not infinite on the client.
979 client_sent_packet_manager
.GetRttStats()->smoothed_rtt().IsInfinite());
980 const RttStats
& server_rtt_stats
=
981 *session
->connection()->sent_packet_manager().GetRttStats();
982 EXPECT_EQ(static_cast<int64
>(kMaxInitialRoundTripTimeUs
),
983 server_rtt_stats
.initial_rtt_us());
984 EXPECT_GE(static_cast<int64
>(kMaxInitialRoundTripTimeUs
),
985 server_rtt_stats
.smoothed_rtt().ToMicroseconds());
986 server_thread_
->Resume();
989 TEST_P(EndToEndTest
, MinInitialRTT
) {
990 // Client tries to suggest 0 and the server uses the default.
991 client_config_
.SetInitialRoundTripTimeUsToSend(0);
993 ASSERT_TRUE(Initialize());
994 client_
->client()->WaitForCryptoHandshakeConfirmed();
995 server_thread_
->WaitForCryptoHandshakeConfirmed();
997 // Pause the server so we can access the server's internals without races.
998 server_thread_
->Pause();
999 QuicDispatcher
* dispatcher
=
1000 QuicServerPeer::GetDispatcher(server_thread_
->server());
1001 ASSERT_EQ(1u, dispatcher
->session_map().size());
1002 QuicSession
* session
= dispatcher
->session_map().begin()->second
;
1003 const QuicSentPacketManager
& client_sent_packet_manager
=
1004 client_
->client()->session()->connection()->sent_packet_manager();
1005 const QuicSentPacketManager
& server_sent_packet_manager
=
1006 session
->connection()->sent_packet_manager();
1008 // Now that acks have been exchanged, the RTT estimate has decreased on the
1009 // server and is not infinite on the client.
1011 client_sent_packet_manager
.GetRttStats()->smoothed_rtt().IsInfinite());
1012 // Expect the default rtt of 100ms.
1013 EXPECT_EQ(static_cast<int64
>(100 * kNumMicrosPerMilli
),
1014 server_sent_packet_manager
.GetRttStats()->initial_rtt_us());
1015 // Ensure the bandwidth is valid.
1016 client_sent_packet_manager
.BandwidthEstimate();
1017 server_sent_packet_manager
.BandwidthEstimate();
1018 server_thread_
->Resume();
1021 TEST_P(EndToEndTest
, ResetConnection
) {
1022 ASSERT_TRUE(Initialize());
1023 client_
->client()->WaitForCryptoHandshakeConfirmed();
1025 EXPECT_EQ(kFooResponseBody
, client_
->SendSynchronousRequest("/foo"));
1026 EXPECT_EQ(200u, client_
->response_headers()->parsed_response_code());
1027 client_
->ResetConnection();
1028 EXPECT_EQ(kBarResponseBody
, client_
->SendSynchronousRequest("/bar"));
1029 EXPECT_EQ(200u, client_
->response_headers()->parsed_response_code());
1032 TEST_P(EndToEndTest
, MaxStreamsUberTest
) {
1033 SetPacketLossPercentage(1);
1034 ASSERT_TRUE(Initialize());
1036 GenerateBody(&large_body
, 10240);
1037 int max_streams
= 100;
1039 AddToCache("GET", "/large_response", "HTTP/1.1", "200", "OK", large_body
);;
1041 client_
->client()->WaitForCryptoHandshakeConfirmed();
1042 SetPacketLossPercentage(10);
1044 for (int i
= 0; i
< max_streams
; ++i
) {
1045 EXPECT_LT(0, client_
->SendRequest("/large_response"));
1048 // WaitForEvents waits 50ms and returns true if there are outstanding
1050 while (client_
->client()->WaitForEvents() == true) {
1054 TEST_P(EndToEndTest
, StreamCancelErrorTest
) {
1055 ASSERT_TRUE(Initialize());
1057 GenerateBody(&small_body
, 256);
1059 AddToCache("GET", "/small_response", "HTTP/1.1", "200", "OK", small_body
);
1061 client_
->client()->WaitForCryptoHandshakeConfirmed();
1063 QuicSession
* session
= client_
->client()->session();
1064 // Lose the request.
1065 SetPacketLossPercentage(100);
1066 EXPECT_LT(0, client_
->SendRequest("/small_response"));
1067 client_
->client()->WaitForEvents();
1068 // Transmit the cancel, and ensure the connection is torn down properly.
1069 SetPacketLossPercentage(0);
1070 QuicStreamId stream_id
= kClientDataStreamId1
;
1071 session
->SendRstStream(stream_id
, QUIC_STREAM_CANCELLED
, 0);
1073 // WaitForEvents waits 50ms and returns true if there are outstanding
1075 while (client_
->client()->WaitForEvents() == true) {
1077 // It should be completely fine to RST a stream before any data has been
1078 // received for that stream.
1079 EXPECT_EQ(QUIC_NO_ERROR
, client_
->connection_error());
1082 class WrongAddressWriter
: public QuicPacketWriterWrapper
{
1084 WrongAddressWriter() {
1086 CHECK(net::ParseIPLiteralToNumber("127.0.0.2", &ip
));
1087 self_address_
= IPEndPoint(ip
, 0);
1090 WriteResult
WritePacket(const char* buffer
,
1092 const IPAddressNumber
& real_self_address
,
1093 const IPEndPoint
& peer_address
) override
{
1094 // Use wrong address!
1095 return QuicPacketWriterWrapper::WritePacket(
1096 buffer
, buf_len
, self_address_
.address(), peer_address
);
1099 bool IsWriteBlockedDataBuffered() const override
{ return false; }
1101 IPEndPoint self_address_
;
1104 TEST_P(EndToEndTest
, ConnectionMigrationClientIPChanged
) {
1105 // Tests that the client's IP can not change during an established QUIC
1106 // connection. If it changes, the connection is closed by the server as we do
1107 // not yet support IP migration.
1108 ASSERT_TRUE(Initialize());
1110 EXPECT_EQ(kFooResponseBody
, client_
->SendSynchronousRequest("/foo"));
1111 EXPECT_EQ(200u, client_
->response_headers()->parsed_response_code());
1113 WrongAddressWriter
* writer
= new WrongAddressWriter();
1115 writer
->set_writer(new QuicDefaultPacketWriter(client_
->client()->fd()));
1116 QuicConnectionPeer::SetWriter(client_
->client()->session()->connection(),
1118 /* owns_writer= */ true);
1120 client_
->SendSynchronousRequest("/bar");
1122 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR
, client_
->stream_error());
1123 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS
, client_
->connection_error());
1126 TEST_P(EndToEndTest
, ConnectionMigrationClientPortChanged
) {
1127 // Tests that the client's port can change during an established QUIC
1128 // connection, and that doing so does not result in the connection being
1129 // closed by the server.
1130 ASSERT_TRUE(Initialize());
1132 EXPECT_EQ(kFooResponseBody
, client_
->SendSynchronousRequest("/foo"));
1133 EXPECT_EQ(200u, client_
->response_headers()->parsed_response_code());
1135 // Store the client address which was used to send the first request.
1136 IPEndPoint old_address
= client_
->client()->client_address();
1138 // Stop listening on the old FD.
1139 EpollServer
* eps
= client_
->epoll_server();
1140 int old_fd
= client_
->client()->fd();
1141 eps
->UnregisterFD(old_fd
);
1142 // Create a new socket before closing the old one, which will result in a new
1144 QuicClientPeer::CreateUDPSocket(client_
->client());
1147 // The packet writer needs to be updated to use the new FD.
1148 client_
->client()->CreateQuicPacketWriter();
1150 // Change the internal state of the client and connection to use the new port,
1151 // this is done because in a real NAT rebinding the client wouldn't see any
1152 // port change, and so expects no change to incoming port.
1153 // This is kind of ugly, but needed as we are simply swapping out the client
1154 // FD rather than any more complex NAT rebinding simulation.
1155 int new_port
= client_
->client()->client_address().port();
1156 QuicClientPeer::SetClientPort(client_
->client(), new_port
);
1157 QuicConnectionPeer::SetSelfAddress(
1158 client_
->client()->session()->connection(),
1160 client_
->client()->session()->connection()->self_address().address(),
1163 // Register the new FD for epoll events.
1164 int new_fd
= client_
->client()->fd();
1165 eps
->RegisterFD(new_fd
, client_
->client(), EPOLLIN
| EPOLLOUT
| EPOLLET
);
1167 // Send a second request, using the new FD.
1168 EXPECT_EQ(kBarResponseBody
, client_
->SendSynchronousRequest("/bar"));
1169 EXPECT_EQ(200u, client_
->response_headers()->parsed_response_code());
1171 // Verify that the client's ephemeral port is different.
1172 IPEndPoint new_address
= client_
->client()->client_address();
1173 EXPECT_EQ(old_address
.address(), new_address
.address());
1174 EXPECT_NE(old_address
.port(), new_address
.port());
1178 TEST_P(EndToEndTest
, DifferentFlowControlWindowsQ019
) {
1179 // TODO(rjshade): Remove this test when removing QUIC_VERSION_19.
1180 // Client and server can set different initial flow control receive windows.
1181 // These are sent in CHLO/SHLO. Tests that these values are exchanged properly
1182 // in the crypto handshake.
1184 const uint32 kClientIFCW
= 123456;
1185 set_client_initial_flow_control_receive_window(kClientIFCW
);
1187 const uint32 kServerIFCW
= 654321;
1188 set_server_initial_flow_control_receive_window(kServerIFCW
);
1190 ASSERT_TRUE(Initialize());
1191 if (negotiated_version_
> QUIC_VERSION_19
) {
1195 // Values are exchanged during crypto handshake, so wait for that to finish.
1196 client_
->client()->WaitForCryptoHandshakeConfirmed();
1197 server_thread_
->WaitForCryptoHandshakeConfirmed();
1199 // Client should have the right value for server's receive window.
1200 EXPECT_EQ(kServerIFCW
, client_
->client()
1203 ->ReceivedInitialFlowControlWindowBytes());
1205 // Server should have the right value for client's receive window.
1206 server_thread_
->Pause();
1207 QuicDispatcher
* dispatcher
=
1208 QuicServerPeer::GetDispatcher(server_thread_
->server());
1209 QuicSession
* session
= dispatcher
->session_map().begin()->second
;
1210 EXPECT_EQ(kClientIFCW
,
1211 session
->config()->ReceivedInitialFlowControlWindowBytes());
1212 server_thread_
->Resume();
1215 TEST_P(EndToEndTest
, DifferentFlowControlWindowsQ020
) {
1216 // TODO(rjshade): Rename to DifferentFlowControlWindows when removing
1218 // Client and server can set different initial flow control receive windows.
1219 // These are sent in CHLO/SHLO. Tests that these values are exchanged properly
1220 // in the crypto handshake.
1221 const uint32 kClientStreamIFCW
= 123456;
1222 const uint32 kClientSessionIFCW
= 234567;
1223 set_client_initial_stream_flow_control_receive_window(kClientStreamIFCW
);
1224 set_client_initial_session_flow_control_receive_window(kClientSessionIFCW
);
1226 const uint32 kServerStreamIFCW
= 654321;
1227 const uint32 kServerSessionIFCW
= 765432;
1228 set_server_initial_stream_flow_control_receive_window(kServerStreamIFCW
);
1229 set_server_initial_session_flow_control_receive_window(kServerSessionIFCW
);
1231 ASSERT_TRUE(Initialize());
1232 if (negotiated_version_
== QUIC_VERSION_19
) {
1236 // Values are exchanged during crypto handshake, so wait for that to finish.
1237 client_
->client()->WaitForCryptoHandshakeConfirmed();
1238 server_thread_
->WaitForCryptoHandshakeConfirmed();
1240 // Open a data stream to make sure the stream level flow control is updated.
1241 QuicSpdyClientStream
* stream
= client_
->GetOrCreateStream();
1242 stream
->SendBody("hello", false);
1244 // Client should have the right values for server's receive window.
1245 EXPECT_EQ(kServerStreamIFCW
,
1249 ->ReceivedInitialStreamFlowControlWindowBytes());
1250 EXPECT_EQ(kServerSessionIFCW
,
1254 ->ReceivedInitialSessionFlowControlWindowBytes());
1255 EXPECT_EQ(kServerStreamIFCW
, QuicFlowControllerPeer::SendWindowOffset(
1256 stream
->flow_controller()));
1257 EXPECT_EQ(kServerSessionIFCW
,
1258 QuicFlowControllerPeer::SendWindowOffset(
1259 client_
->client()->session()->flow_controller()));
1261 // Server should have the right values for client's receive window.
1262 server_thread_
->Pause();
1263 QuicDispatcher
* dispatcher
=
1264 QuicServerPeer::GetDispatcher(server_thread_
->server());
1265 QuicSession
* session
= dispatcher
->session_map().begin()->second
;
1266 EXPECT_EQ(kClientStreamIFCW
,
1267 session
->config()->ReceivedInitialStreamFlowControlWindowBytes());
1268 EXPECT_EQ(kClientSessionIFCW
,
1269 session
->config()->ReceivedInitialSessionFlowControlWindowBytes());
1270 EXPECT_EQ(kClientSessionIFCW
, QuicFlowControllerPeer::SendWindowOffset(
1271 session
->flow_controller()));
1272 server_thread_
->Resume();
1275 TEST_P(EndToEndTest
, HeadersAndCryptoStreamsNoConnectionFlowControl
) {
1276 // The special headers and crypto streams should be subject to per-stream flow
1277 // control limits, but should not be subject to connection level flow control.
1278 const uint32 kStreamIFCW
= 123456;
1279 const uint32 kSessionIFCW
= 234567;
1280 set_client_initial_stream_flow_control_receive_window(kStreamIFCW
);
1281 set_client_initial_session_flow_control_receive_window(kSessionIFCW
);
1282 set_server_initial_stream_flow_control_receive_window(kStreamIFCW
);
1283 set_server_initial_session_flow_control_receive_window(kSessionIFCW
);
1285 ASSERT_TRUE(Initialize());
1286 if (negotiated_version_
< QUIC_VERSION_21
) {
1290 // Wait for crypto handshake to finish. This should have contributed to the
1291 // crypto stream flow control window, but not affected the session flow
1293 client_
->client()->WaitForCryptoHandshakeConfirmed();
1294 server_thread_
->WaitForCryptoHandshakeConfirmed();
1296 QuicCryptoStream
* crypto_stream
=
1297 QuicSessionPeer::GetCryptoStream(client_
->client()->session());
1299 QuicFlowControllerPeer::SendWindowSize(crypto_stream
->flow_controller()),
1301 EXPECT_EQ(kSessionIFCW
, QuicFlowControllerPeer::SendWindowSize(
1302 client_
->client()->session()->flow_controller()));
1304 // Send a request with no body, and verify that the connection level window
1305 // has not been affected.
1306 EXPECT_EQ(kFooResponseBody
, client_
->SendSynchronousRequest("/foo"));
1308 QuicHeadersStream
* headers_stream
=
1309 QuicSessionPeer::GetHeadersStream(client_
->client()->session());
1311 QuicFlowControllerPeer::SendWindowSize(headers_stream
->flow_controller()),
1313 EXPECT_EQ(kSessionIFCW
, QuicFlowControllerPeer::SendWindowSize(
1314 client_
->client()->session()->flow_controller()));
1316 // Server should be in a similar state: connection flow control window should
1317 // not have any bytes marked as received.
1318 server_thread_
->Pause();
1319 QuicDispatcher
* dispatcher
=
1320 QuicServerPeer::GetDispatcher(server_thread_
->server());
1321 QuicSession
* session
= dispatcher
->session_map().begin()->second
;
1322 QuicFlowController
* server_connection_flow_controller
=
1323 session
->flow_controller();
1324 EXPECT_EQ(kSessionIFCW
, QuicFlowControllerPeer::ReceiveWindowSize(
1325 server_connection_flow_controller
));
1326 server_thread_
->Resume();
1329 TEST_P(EndToEndTest
, RequestWithNoBodyWillNeverSendStreamFrameWithFIN
) {
1330 // Regression test for b/16010251.
1331 // A stream created on receipt of a simple request with no body will never get
1332 // a stream frame with a FIN. Verify that we don't keep track of the stream in
1333 // the locally closed streams map: it will never be removed if so.
1334 ASSERT_TRUE(Initialize());
1336 // Send a simple headers only request, and receive response.
1337 EXPECT_EQ(kFooResponseBody
, client_
->SendSynchronousRequest("/foo"));
1338 EXPECT_EQ(200u, client_
->response_headers()->parsed_response_code());
1340 // Now verify that the server is not waiting for a final FIN or RST.
1341 server_thread_
->Pause();
1342 QuicDispatcher
* dispatcher
=
1343 QuicServerPeer::GetDispatcher(server_thread_
->server());
1344 QuicSession
* session
= dispatcher
->session_map().begin()->second
;
1345 EXPECT_EQ(0u, QuicSessionPeer::GetLocallyClosedStreamsHighestOffset(
1347 server_thread_
->Resume();
1350 TEST_P(EndToEndTest
, EnablePacingViaFlag
) {
1351 // When pacing is enabled via command-line flag, it will always be enabled,
1352 // regardless of the config. or the specific congestion-control algorithm.
1353 ValueRestore
<bool> old_flag(&FLAGS_quic_enable_pacing
, true);
1354 ASSERT_TRUE(Initialize());
1356 client_
->client()->WaitForCryptoHandshakeConfirmed();
1357 server_thread_
->WaitForCryptoHandshakeConfirmed();
1359 // Pause the server so we can access the server's internals without races.
1360 server_thread_
->Pause();
1361 QuicDispatcher
* dispatcher
=
1362 QuicServerPeer::GetDispatcher(server_thread_
->server());
1363 ASSERT_EQ(1u, dispatcher
->session_map().size());
1364 const QuicSentPacketManager
& client_sent_packet_manager
=
1365 client_
->client()->session()->connection()->sent_packet_manager();
1366 const QuicSentPacketManager
& server_sent_packet_manager
=
1367 *GetSentPacketManagerFromFirstServerSession();
1368 EXPECT_TRUE(server_sent_packet_manager
.using_pacing());
1369 EXPECT_TRUE(client_sent_packet_manager
.using_pacing());
1374 } // namespace tools