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

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

Issue 1025573002: QUIC - disable QUIC if packet loss rate is bad for a connection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed comments for Patch Set 7 Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_stream_factory.cc ('k') | net/quic/quic_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_stream_factory.h" 5 #include "net/quic/quic_stream_factory.h"
6 6
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "net/base/test_data_directory.h" 9 #include "net/base/test_data_directory.h"
10 #include "net/cert/cert_verifier.h" 10 #include "net/cert/cert_verifier.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 static void SetEnableConnectionRacing(QuicStreamFactory* factory, 128 static void SetEnableConnectionRacing(QuicStreamFactory* factory,
129 bool enable_connection_racing) { 129 bool enable_connection_racing) {
130 factory->enable_connection_racing_ = enable_connection_racing; 130 factory->enable_connection_racing_ = enable_connection_racing;
131 } 131 }
132 132
133 static void SetDisableDiskCache(QuicStreamFactory* factory, 133 static void SetDisableDiskCache(QuicStreamFactory* factory,
134 bool disable_disk_cache) { 134 bool disable_disk_cache) {
135 factory->disable_disk_cache_ = disable_disk_cache; 135 factory->disable_disk_cache_ = disable_disk_cache;
136 } 136 }
137 137
138 static void SetMaxNumberOfLossyConnections(
139 QuicStreamFactory* factory,
140 int max_number_of_lossy_connections) {
141 factory->max_number_of_lossy_connections_ = max_number_of_lossy_connections;
142 }
143
144 static int GetNumberOfLossyConnections(QuicStreamFactory* factory,
145 uint16 port) {
146 return factory->number_of_lossy_connections_[port];
147 }
148
149 static bool IsQuicDisabled(QuicStreamFactory* factory, uint16 port) {
150 return factory->IsQuicDisabled(port);
151 }
152
138 static size_t GetNumberOfActiveJobs(QuicStreamFactory* factory, 153 static size_t GetNumberOfActiveJobs(QuicStreamFactory* factory,
139 const QuicServerId& server_id) { 154 const QuicServerId& server_id) {
140 return (factory->active_jobs_[server_id]).size(); 155 return (factory->active_jobs_[server_id]).size();
141 } 156 }
142 }; 157 };
143 158
144 class MockQuicServerInfo : public QuicServerInfo { 159 class MockQuicServerInfo : public QuicServerInfo {
145 public: 160 public:
146 MockQuicServerInfo(const QuicServerId& server_id) 161 MockQuicServerInfo(const QuicServerId& server_id)
147 : QuicServerInfo(server_id) {} 162 : QuicServerInfo(server_id) {}
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 kDefaultMaxPacketSize, 214 kDefaultMaxPacketSize,
200 std::string(), 215 std::string(),
201 SupportedVersions(GetParam().version), 216 SupportedVersions(GetParam().version),
202 /*enable_port_selection=*/true, 217 /*enable_port_selection=*/true,
203 /*always_require_handshake_confirmation=*/false, 218 /*always_require_handshake_confirmation=*/false,
204 /*disable_connection_pooling=*/false, 219 /*disable_connection_pooling=*/false,
205 /*load_server_info_timeout_srtt_multiplier=*/0.0f, 220 /*load_server_info_timeout_srtt_multiplier=*/0.0f,
206 /*enable_connection_racing=*/false, 221 /*enable_connection_racing=*/false,
207 /*enable_non_blocking_io=*/true, 222 /*enable_non_blocking_io=*/true,
208 /*disable_disk_cache=*/false, 223 /*disable_disk_cache=*/false,
224 /*max_number_of_lossy_connections=*/0,
225 /*packet_loss_threshold=*/1.0f,
209 /*receive_buffer_size=*/0, 226 /*receive_buffer_size=*/0,
210 QuicTagVector()), 227 QuicTagVector()),
211 host_port_pair_(kDefaultServerHostName, kDefaultServerPort), 228 host_port_pair_(kDefaultServerHostName, kDefaultServerPort),
212 is_https_(false), 229 is_https_(false),
213 privacy_mode_(PRIVACY_MODE_DISABLED) { 230 privacy_mode_(PRIVACY_MODE_DISABLED) {
214 factory_.set_require_confirmation(false); 231 factory_.set_require_confirmation(false);
215 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); 232 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1));
216 QuicStreamFactoryPeer::SetEnableConnectionRacing( 233 QuicStreamFactoryPeer::SetEnableConnectionRacing(
217 &factory_, GetParam().enable_connection_racing); 234 &factory_, GetParam().enable_connection_racing);
218 } 235 }
(...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 // If we are waiting for disk cache, we would have posted a task. Verify that 1691 // If we are waiting for disk cache, we would have posted a task. Verify that
1675 // the CancelWaitForDataReady task hasn't been posted. 1692 // the CancelWaitForDataReady task hasn't been posted.
1676 ASSERT_EQ(0u, runner_->GetPostedTasks().size()); 1693 ASSERT_EQ(0u, runner_->GetPostedTasks().size());
1677 1694
1678 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); 1695 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1679 EXPECT_TRUE(stream.get()); 1696 EXPECT_TRUE(stream.get());
1680 EXPECT_TRUE(socket_data.at_read_eof()); 1697 EXPECT_TRUE(socket_data.at_read_eof());
1681 EXPECT_TRUE(socket_data.at_write_eof()); 1698 EXPECT_TRUE(socket_data.at_write_eof());
1682 } 1699 }
1683 1700
1701 TEST_P(QuicStreamFactoryTest, BadPacketLoss) {
1702 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
1703 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
1704 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
1705 QuicStreamFactoryPeer::SetMaxNumberOfLossyConnections(&factory_, 2);
1706 EXPECT_FALSE(
1707 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1708 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1709 &factory_, host_port_pair_.port()));
1710
1711 MockRead reads[] = {
1712 MockRead(ASYNC, OK, 0) // EOF
1713 };
1714 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1715 socket_factory_.AddSocketDataProvider(&socket_data);
1716 socket_data.StopAfter(1);
1717
1718 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
1719 socket_factory_.AddSocketDataProvider(&socket_data2);
1720 socket_data2.StopAfter(1);
1721
1722 DeterministicSocketData socket_data3(reads, arraysize(reads), nullptr, 0);
1723 socket_factory_.AddSocketDataProvider(&socket_data3);
1724 socket_data3.StopAfter(1);
1725
1726 HostPortPair server2("mail.example.org", kDefaultServerPort);
1727 HostPortPair server3("docs.example.org", kDefaultServerPort);
1728
1729 crypto_client_stream_factory_.set_handshake_mode(
1730 MockCryptoClientStream::ZERO_RTT);
1731 host_resolver_.set_synchronous_mode(true);
1732 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
1733 "192.168.0.1", "");
1734 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
1735 host_resolver_.rules()->AddIPLiteralRule(server3.host(), "192.168.0.1", "");
1736
1737 QuicStreamRequest request(&factory_);
1738 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
1739 "GET", net_log_, callback_.callback()));
1740
1741 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
1742 &factory_, host_port_pair_, is_https_);
1743
1744 DVLOG(1) << "Create 1st session and test packet loss";
1745
1746 // Set packet_loss_rate to a lower value than packet_loss_threshold.
1747 EXPECT_FALSE(
1748 factory_.OnHandshakeConfirmed(session, /*packet_loss_rate=*/0.9f));
1749 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(
1750 &factory_, host_port_pair_, is_https_));
1751 EXPECT_FALSE(
1752 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1753 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1754 &factory_, host_port_pair_.port()));
1755
1756 // Set packet_loss_rate to a higher value than packet_loss_threshold only once
1757 // and that should close the session, but shouldn't disable QUIC.
1758 EXPECT_TRUE(
1759 factory_.OnHandshakeConfirmed(session, /*packet_loss_rate=*/1.0f));
1760 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1761 &factory_, host_port_pair_.port()));
1762 EXPECT_FALSE(
1763 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1764 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(
1765 &factory_, host_port_pair_, is_https_));
1766 EXPECT_EQ(nullptr, CreateIfSessionExists(host_port_pair_, net_log_).get());
1767
1768 // Test N-in-a-row high packet loss connections.
1769
1770 DVLOG(1) << "Create 2nd session and test packet loss";
1771
1772 TestCompletionCallback callback2;
1773 QuicStreamRequest request2(&factory_);
1774 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_, "GET",
1775 net_log_, callback2.callback()));
1776 QuicClientSession* session2 =
1777 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
1778
1779 // If there is no packet loss during handshake confirmation, number of lossy
1780 // connections for the port should be 0.
1781 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1782 &factory_, server2.port()));
1783 EXPECT_FALSE(
1784 factory_.OnHandshakeConfirmed(session2, /*packet_loss_rate=*/0.9f));
1785 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1786 &factory_, server2.port()));
1787 EXPECT_FALSE(
1788 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, server2.port()));
1789
1790 // Set packet_loss_rate to a higher value than packet_loss_threshold only once
1791 // and that should close the session, but shouldn't disable QUIC.
1792 EXPECT_TRUE(
1793 factory_.OnHandshakeConfirmed(session2, /*packet_loss_rate=*/1.0f));
1794 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1795 &factory_, server2.port()));
1796 EXPECT_FALSE(
1797 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, server2.port()));
1798 EXPECT_FALSE(
1799 QuicStreamFactoryPeer::HasActiveSession(&factory_, server2, is_https_));
1800 EXPECT_EQ(nullptr, CreateIfSessionExists(server2, net_log_).get());
1801
1802 DVLOG(1) << "Create 3rd session which also has packet loss";
1803
1804 TestCompletionCallback callback3;
1805 QuicStreamRequest request3(&factory_);
1806 EXPECT_EQ(OK, request3.Request(server3, is_https_, privacy_mode_, "GET",
1807 net_log_, callback3.callback()));
1808 QuicClientSession* session3 =
1809 QuicStreamFactoryPeer::GetActiveSession(&factory_, server3, is_https_);
1810
1811 // Set packet_loss_rate to higher value than packet_loss_threshold 2nd time in
1812 // a row and that should close the session and disable QUIC.
1813 EXPECT_TRUE(
1814 factory_.OnHandshakeConfirmed(session3, /*packet_loss_rate=*/1.0f));
1815 EXPECT_EQ(2, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1816 &factory_, server3.port()));
1817 EXPECT_TRUE(QuicStreamFactoryPeer::IsQuicDisabled(&factory_, server3.port()));
1818 EXPECT_FALSE(
1819 QuicStreamFactoryPeer::HasActiveSession(&factory_, server3, is_https_));
1820 EXPECT_EQ(nullptr, CreateIfSessionExists(server3, net_log_).get());
1821
1822 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1823 EXPECT_TRUE(stream.get());
1824 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
1825 EXPECT_TRUE(stream2.get());
1826 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
1827 EXPECT_TRUE(stream3.get());
1828 EXPECT_TRUE(socket_data.at_read_eof());
1829 EXPECT_TRUE(socket_data.at_write_eof());
1830 EXPECT_TRUE(socket_data2.at_read_eof());
1831 EXPECT_TRUE(socket_data2.at_write_eof());
1832 EXPECT_TRUE(socket_data3.at_read_eof());
1833 EXPECT_TRUE(socket_data3.at_write_eof());
1834 }
1835
1684 } // namespace test 1836 } // namespace test
1685 } // namespace net 1837 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_stream_factory.cc ('k') | net/quic/quic_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698