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 <string> | 6 #include <string> |
7 #include <sys/epoll.h> | 7 #include <sys/epoll.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 1350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 QuicServerPeer::GetDispatcher(server_thread_->server()); | 1361 QuicServerPeer::GetDispatcher(server_thread_->server()); |
1362 ASSERT_EQ(1u, dispatcher->session_map().size()); | 1362 ASSERT_EQ(1u, dispatcher->session_map().size()); |
1363 const QuicSentPacketManager& client_sent_packet_manager = | 1363 const QuicSentPacketManager& client_sent_packet_manager = |
1364 client_->client()->session()->connection()->sent_packet_manager(); | 1364 client_->client()->session()->connection()->sent_packet_manager(); |
1365 const QuicSentPacketManager& server_sent_packet_manager = | 1365 const QuicSentPacketManager& server_sent_packet_manager = |
1366 *GetSentPacketManagerFromFirstServerSession(); | 1366 *GetSentPacketManagerFromFirstServerSession(); |
1367 EXPECT_TRUE(server_sent_packet_manager.using_pacing()); | 1367 EXPECT_TRUE(server_sent_packet_manager.using_pacing()); |
1368 EXPECT_TRUE(client_sent_packet_manager.using_pacing()); | 1368 EXPECT_TRUE(client_sent_packet_manager.using_pacing()); |
1369 } | 1369 } |
1370 | 1370 |
| 1371 // A TestAckNotifierDelegate verifies that its OnAckNotification method has been |
| 1372 // called exactly once on destruction. |
| 1373 class TestAckNotifierDelegate : public QuicAckNotifier::DelegateInterface { |
| 1374 public: |
| 1375 TestAckNotifierDelegate() {} |
| 1376 |
| 1377 void OnAckNotification(int /*num_original_packets*/, |
| 1378 int /*num_original_bytes*/, |
| 1379 int /*num_retransmitted_packets*/, |
| 1380 int /*num_retransmitted_bytes*/, |
| 1381 QuicTime::Delta /*delta_largest_observed*/) override { |
| 1382 ASSERT_FALSE(has_been_notified_); |
| 1383 has_been_notified_ = true; |
| 1384 } |
| 1385 |
| 1386 bool has_been_notified() const { return has_been_notified_; } |
| 1387 |
| 1388 protected: |
| 1389 // Object is ref counted. |
| 1390 ~TestAckNotifierDelegate() override { EXPECT_TRUE(has_been_notified_); } |
| 1391 |
| 1392 private: |
| 1393 bool has_been_notified_ = false; |
| 1394 }; |
| 1395 |
| 1396 TEST_P(EndToEndTest, AckNotifierWithPacketLoss) { |
| 1397 // Verify that even in the presence of packet loss, an AckNotifierDelegate |
| 1398 // will get informed that the data it is interested in has been ACKed. This |
| 1399 // tests end-to-end ACK notification, and demonstrates that retransmissions do |
| 1400 // not break this functionality. |
| 1401 ValueRestore<bool> old_flag(&FLAGS_quic_attach_ack_notifiers_to_packets, |
| 1402 true); |
| 1403 |
| 1404 SetPacketLossPercentage(5); |
| 1405 ASSERT_TRUE(Initialize()); |
| 1406 |
| 1407 // Wait for the server SHLO before upping the packet loss. |
| 1408 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 1409 SetPacketLossPercentage(30); |
| 1410 |
| 1411 // Create a POST request and send the headers only. |
| 1412 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
| 1413 request.set_has_complete_message(false); |
| 1414 client_->SendMessage(request); |
| 1415 |
| 1416 // The TestAckNotifierDelegate will cause a failure if not notified. |
| 1417 scoped_refptr<TestAckNotifierDelegate> delegate(new TestAckNotifierDelegate); |
| 1418 |
| 1419 // Test the AckNotifier's ability to track multiple packets by making the |
| 1420 // request body exceed the size of a single packet. |
| 1421 string request_string = |
| 1422 "a request body bigger than one packet" + string(kMaxPacketSize, '.'); |
| 1423 |
| 1424 // Send the request, and register the delegate for ACKs. |
| 1425 client_->SendData(request_string, true, delegate.get()); |
| 1426 client_->WaitForResponse(); |
| 1427 EXPECT_EQ(kFooResponseBody, client_->response_body()); |
| 1428 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 1429 |
| 1430 // Send another request to flush out any pending ACKs on the server. |
| 1431 client_->SendSynchronousRequest(request_string); |
| 1432 |
| 1433 // Make sure the delegate does get the notification it expects. |
| 1434 while (!delegate->has_been_notified()) { |
| 1435 // Waits for up to 50 ms. |
| 1436 client_->client()->WaitForEvents(); |
| 1437 } |
| 1438 } |
| 1439 |
1371 } // namespace | 1440 } // namespace |
1372 } // namespace test | 1441 } // namespace test |
1373 } // namespace tools | 1442 } // namespace tools |
1374 } // namespace net | 1443 } // namespace net |
OLD | NEW |