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

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

Issue 1208933004: QUIC - disable QUIC under recent pathological connection errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
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 "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "net/base/test_data_directory.h" 10 #include "net/base/test_data_directory.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } 145 }
146 146
147 static bool IsQuicDisabled(QuicStreamFactory* factory, uint16 port) { 147 static bool IsQuicDisabled(QuicStreamFactory* factory, uint16 port) {
148 return factory->IsQuicDisabled(port); 148 return factory->IsQuicDisabled(port);
149 } 149 }
150 150
151 static size_t GetNumberOfActiveJobs(QuicStreamFactory* factory, 151 static size_t GetNumberOfActiveJobs(QuicStreamFactory* factory,
152 const QuicServerId& server_id) { 152 const QuicServerId& server_id) {
153 return (factory->active_jobs_[server_id]).size(); 153 return (factory->active_jobs_[server_id]).size();
154 } 154 }
155
156 static void SetThresholdTimeoutsStreamsOpen(
157 QuicStreamFactory* factory,
158 int threshold_timeouts_streams_open) {
159 factory->threshold_timeouts_streams_open_ = threshold_timeouts_streams_open;
160 }
161
162 static int GetTimeoutsStreamsOpen(QuicStreamFactory* factory) {
163 return factory->timeouts_streams_open_;
Ryan Hamilton 2015/06/30 18:55:32 here and elsewhere, I think "timeouts with open st
Buck 2015/07/01 19:06:20 Done.
164 }
165
166 static void SetThresholdPublicResetsPostHandshake(
167 QuicStreamFactory* factory,
168 int threshold_public_resets_post_handshake) {
169 factory->threshold_public_resets_post_handshake_ =
170 threshold_public_resets_post_handshake;
171 }
172
173 static int GetPublicResetsPostHandshake(QuicStreamFactory* factory) {
174 return factory->public_resets_post_handshake_;
175 }
155 }; 176 };
156 177
157 class MockQuicServerInfo : public QuicServerInfo { 178 class MockQuicServerInfo : public QuicServerInfo {
158 public: 179 public:
159 MockQuicServerInfo(const QuicServerId& server_id) 180 MockQuicServerInfo(const QuicServerId& server_id)
160 : QuicServerInfo(server_id) {} 181 : QuicServerInfo(server_id) {}
161 ~MockQuicServerInfo() override {} 182 ~MockQuicServerInfo() override {}
162 183
163 void Start() override {} 184 void Start() override {}
164 185
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 /*enable_port_selection=*/true, 236 /*enable_port_selection=*/true,
216 /*always_require_handshake_confirmation=*/false, 237 /*always_require_handshake_confirmation=*/false,
217 /*disable_connection_pooling=*/false, 238 /*disable_connection_pooling=*/false,
218 /*load_server_info_timeout_srtt_multiplier=*/0.0f, 239 /*load_server_info_timeout_srtt_multiplier=*/0.0f,
219 /*enable_connection_racing=*/false, 240 /*enable_connection_racing=*/false,
220 /*enable_non_blocking_io=*/true, 241 /*enable_non_blocking_io=*/true,
221 /*disable_disk_cache=*/false, 242 /*disable_disk_cache=*/false,
222 /*prefer_aes=*/false, 243 /*prefer_aes=*/false,
223 /*max_number_of_lossy_connections=*/0, 244 /*max_number_of_lossy_connections=*/0,
224 /*packet_loss_threshold=*/1.0f, 245 /*packet_loss_threshold=*/1.0f,
246 /*max_epitaphs=*/3,
247 /*threshold_timeouts_streams_open=*/2,
248 /*threshold_pulic_resets_post_handshake=*/2,
225 /*receive_buffer_size=*/0, 249 /*receive_buffer_size=*/0,
226 QuicTagVector()), 250 QuicTagVector()),
227 host_port_pair_(kDefaultServerHostName, kDefaultServerPort), 251 host_port_pair_(kDefaultServerHostName, kDefaultServerPort),
228 is_https_(false), 252 is_https_(false),
229 privacy_mode_(PRIVACY_MODE_DISABLED) { 253 privacy_mode_(PRIVACY_MODE_DISABLED) {
230 factory_.set_require_confirmation(false); 254 factory_.set_require_confirmation(false);
231 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); 255 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1));
232 QuicStreamFactoryPeer::SetEnableConnectionRacing( 256 QuicStreamFactoryPeer::SetEnableConnectionRacing(
233 &factory_, GetParam().enable_connection_racing); 257 &factory_, GetParam().enable_connection_racing);
234 } 258 }
(...skipping 1497 matching lines...) Expand 10 before | Expand all | Expand 10 after
1732 EXPECT_TRUE(socket_data.AllReadDataConsumed()); 1756 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1733 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); 1757 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1734 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); 1758 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1735 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); 1759 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1736 EXPECT_TRUE(socket_data3.AllReadDataConsumed()); 1760 EXPECT_TRUE(socket_data3.AllReadDataConsumed());
1737 EXPECT_TRUE(socket_data3.AllWriteDataConsumed()); 1761 EXPECT_TRUE(socket_data3.AllWriteDataConsumed());
1738 EXPECT_TRUE(socket_data4.AllReadDataConsumed()); 1762 EXPECT_TRUE(socket_data4.AllReadDataConsumed());
1739 EXPECT_TRUE(socket_data4.AllWriteDataConsumed()); 1763 EXPECT_TRUE(socket_data4.AllWriteDataConsumed());
1740 } 1764 }
1741 1765
1766 TEST_P(QuicStreamFactoryTest, PublicResetPostHandshake) {
1767 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
1768 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
1769 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
1770 QuicStreamFactoryPeer::SetThresholdPublicResetsPostHandshake(&factory_, 2);
1771 EXPECT_FALSE(
1772 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1773 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1774 &factory_, host_port_pair_.port()));
1775
1776 MockRead reads[] = {
1777 MockRead(ASYNC, OK, 0) // EOF
1778 };
1779 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1780 socket_factory_.AddSocketDataProvider(&socket_data);
1781 socket_data.StopAfter(1);
1782
1783 // DeterministicSocketData socket_data2(nullptr, 0, nullptr, 0);
1784 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
1785 socket_factory_.AddSocketDataProvider(&socket_data2);
1786 socket_data2.StopAfter(1);
1787
1788 HostPortPair server2("mail.example.org", kDefaultServerPort);
1789
1790 crypto_client_stream_factory_.set_handshake_mode(
1791 MockCryptoClientStream::CONFIRM_HANDSHAKE);
1792 host_resolver_.set_synchronous_mode(true);
1793 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
1794 "192.168.0.1", "");
1795 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
1796
1797 QuicStreamRequest request(&factory_);
1798 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
1799 /*cert_verify_flags=*/0, host_port_pair_.host(),
1800 "GET", net_log_, callback_.callback()));
1801
1802 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
1803 &factory_, host_port_pair_, is_https_);
1804
1805 DVLOG(1) << "Create 1st session and trigger pulic reset post handshake";
Ryan Hamilton 2015/06/30 18:55:32 The session has already been created here, right?
Buck 2015/07/01 19:06:20 Done.
1806 session->connection()->CloseConnection(QUIC_PUBLIC_RESET, true);
1807 // Need to spin the loop now to ensure that
1808 // QuicStreamFactory::OnSessionClosed() runs.
1809 base::RunLoop run_loop;
1810 run_loop.RunUntilIdle();
Ryan Hamilton 2015/06/30 18:55:32 Does it work if you do base::RunLoop().RunUntilIdl
Buck 2015/07/01 19:06:20 Nope.
Ryan Hamilton 2015/07/06 18:25:41 *head explodes*
1811
1812 EXPECT_EQ(1, QuicStreamFactoryPeer::GetPublicResetsPostHandshake(&factory_));
1813 EXPECT_FALSE(
1814 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1815
1816 // Test N-in-a-row public reset post handshakes..
Ryan Hamilton 2015/06/30 18:55:32 Does "N-in-a-row" simply mean 2, or is there anoth
Buck 2015/07/01 19:06:20 It did mean two. I've revised the comment. I've
1817 DVLOG(1) << "Create 2nd session and trigger public reset post handshake";
1818 TestCompletionCallback callback2;
1819 QuicStreamRequest request2(&factory_);
1820 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
1821 /*cert_verify_flags=*/0, server2.host(), "GET",
1822 net_log_, callback2.callback()));
1823 QuicClientSession* session2 =
1824 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
1825
1826 session2->connection()->CloseConnection(QUIC_PUBLIC_RESET, true);
1827 // Need to spin the loop now to ensure that
1828 // QuicStreamFactory::OnSessionClosed() runs.
1829 base::RunLoop run_loop2;
1830 run_loop2.RunUntilIdle();
1831 EXPECT_EQ(2, QuicStreamFactoryPeer::GetPublicResetsPostHandshake(&factory_));
1832 EXPECT_TRUE(
1833 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
Ryan Hamilton 2015/06/30 18:55:32 Can you also test your disabled reason method here
Buck 2015/07/01 19:06:20 Done.
1834
1835 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1836 EXPECT_TRUE(stream.get());
1837 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
1838 EXPECT_TRUE(stream2.get());
1839 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1840 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1841 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1842 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1843 }
1844
1845 TEST_P(QuicStreamFactoryTest, TimeoutsStreamsOpen) {
1846 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
1847 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
1848 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
1849 QuicStreamFactoryPeer::SetThresholdTimeoutsStreamsOpen(&factory_, 2);
1850 EXPECT_FALSE(
1851 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1852 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1853 &factory_, host_port_pair_.port()));
1854
1855 MockRead reads[] = {
1856 MockRead(ASYNC, OK, 0) // EOF
1857 };
1858 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1859 socket_factory_.AddSocketDataProvider(&socket_data);
1860 socket_data.StopAfter(1);
1861
1862 // DeterministicSocketData socket_data2(nullptr, 0, nullptr, 0);
1863 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
1864 socket_factory_.AddSocketDataProvider(&socket_data2);
1865 socket_data2.StopAfter(1);
1866
1867 HostPortPair server2("mail.example.org", kDefaultServerPort);
1868
1869 crypto_client_stream_factory_.set_handshake_mode(
1870 MockCryptoClientStream::CONFIRM_HANDSHAKE);
1871 host_resolver_.set_synchronous_mode(true);
1872 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
1873 "192.168.0.1", "");
1874 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
1875
1876 QuicStreamRequest request(&factory_);
1877 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
1878 /*cert_verify_flags=*/0, host_port_pair_.host(),
1879 "GET", net_log_, callback_.callback()));
1880
1881 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
1882 &factory_, host_port_pair_, is_https_);
1883
1884 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1885 EXPECT_TRUE(stream.get());
1886 HttpRequestInfo request_info;
1887 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
1888 net_log_, CompletionCallback()));
1889
1890 DVLOG(1) << "Create 1st session and trigger pulic reset post handshake";
1891 session->connection()->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false);
1892 // Need to spin the loop now to ensure that
1893 // QuicStreamFactory::OnSessionClosed() runs.
1894 base::RunLoop run_loop;
1895 run_loop.RunUntilIdle();
1896
1897 EXPECT_EQ(1, QuicStreamFactoryPeer::GetTimeoutsStreamsOpen(&factory_));
1898 EXPECT_FALSE(
1899 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1900
1901 // Test N-in-a-row public reset post handshakes..
Ryan Hamilton 2015/06/30 18:55:32 s/public reset post handshakes/timeouts with open
Buck 2015/07/01 19:06:20 Done.
1902 DVLOG(1) << "Create 2nd session and trigger public reset post handshake";
1903 TestCompletionCallback callback2;
1904 QuicStreamRequest request2(&factory_);
1905 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
1906 /*cert_verify_flags=*/0, server2.host(), "GET",
1907 net_log_, callback2.callback()));
1908 QuicClientSession* session2 =
1909 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
1910
1911 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
1912 EXPECT_TRUE(stream2.get());
1913 EXPECT_EQ(OK, stream2->InitializeStream(&request_info, DEFAULT_PRIORITY,
1914 net_log_, CompletionCallback()));
1915
1916 session2->connection()->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false);
1917 // Need to spin the loop now to ensure that
1918 // QuicStreamFactory::OnSessionClosed() runs.
1919 base::RunLoop run_loop2;
1920 run_loop2.RunUntilIdle();
1921 EXPECT_EQ(2, QuicStreamFactoryPeer::GetTimeoutsStreamsOpen(&factory_));
1922 EXPECT_TRUE(
1923 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1924
1925 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1926 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1927 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1928 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1929 }
1930
1742 } // namespace test 1931 } // namespace test
1743 } // namespace net 1932 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698