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

Side by Side Diff: net/tools/quic/end_to_end_test.cc

Issue 146033003: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile error Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/test_tools/quic_test_utils.cc ('k') | net/tools/quic/quic_client.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 <stddef.h> 5 #include <stddef.h>
6 #include <string> 6 #include <string>
7 #include <sys/epoll.h>
7 #include <vector> 8 #include <vector>
8 9
9 #include "base/basictypes.h" 10 #include "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
14 #include "net/base/ip_endpoint.h" 15 #include "net/base/ip_endpoint.h"
15 #include "net/quic/congestion_control/tcp_cubic_sender.h" 16 #include "net/quic/congestion_control/tcp_cubic_sender.h"
16 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" 17 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 params.push_back(TestParams(all_supported_versions, 140 params.push_back(TestParams(all_supported_versions,
140 server_supported_versions, 141 server_supported_versions,
141 server_supported_versions[0], 142 server_supported_versions[0],
142 use_pacing != 0)); 143 use_pacing != 0));
143 } 144 }
144 #endif 145 #endif
145 } 146 }
146 return params; 147 return params;
147 } 148 }
148 149
150 class ServerDelegate : public PacketDroppingTestWriter::Delegate {
151 public:
152 explicit ServerDelegate(QuicDispatcher* dispatcher)
153 : dispatcher_(dispatcher) {}
154 virtual ~ServerDelegate() {}
155 virtual void OnCanWrite() OVERRIDE { dispatcher_->OnCanWrite(); }
156 private:
157 QuicDispatcher* dispatcher_;
158 };
159
160 class ClientDelegate : public PacketDroppingTestWriter::Delegate {
161 public:
162 explicit ClientDelegate(QuicClient* client) : client_(client) {}
163 virtual ~ClientDelegate() {}
164 virtual void OnCanWrite() OVERRIDE {
165 EpollEvent event(EPOLLOUT, false);
166 client_->OnEvent(client_->fd(), &event);
167 }
168 private:
169 QuicClient* client_;
170 };
171
149 class EndToEndTest : public ::testing::TestWithParam<TestParams> { 172 class EndToEndTest : public ::testing::TestWithParam<TestParams> {
150 protected: 173 protected:
151 EndToEndTest() 174 EndToEndTest()
152 : server_hostname_("example.com"), 175 : server_hostname_("example.com"),
153 server_started_(false), 176 server_started_(false),
154 strike_register_no_startup_period_(false) { 177 strike_register_no_startup_period_(false) {
155 net::IPAddressNumber ip; 178 net::IPAddressNumber ip;
156 CHECK(net::ParseIPLiteralToNumber("127.0.0.1", &ip)); 179 CHECK(net::ParseIPLiteralToNumber("127.0.0.1", &ip));
157 server_address_ = IPEndPoint(ip, 0); 180 server_address_ = IPEndPoint(ip, 0);
158 181
(...skipping 14 matching lines...) Expand all
173 AddToCache("GET", "https://www.google.com/bar", 196 AddToCache("GET", "https://www.google.com/bar",
174 "HTTP/1.1", "200", "OK", kBarResponseBody); 197 "HTTP/1.1", "200", "OK", kBarResponseBody);
175 } 198 }
176 199
177 virtual ~EndToEndTest() { 200 virtual ~EndToEndTest() {
178 // TODO(rtenneti): port RecycleUnusedPort if needed. 201 // TODO(rtenneti): port RecycleUnusedPort if needed.
179 // RecycleUnusedPort(server_address_.port()); 202 // RecycleUnusedPort(server_address_.port());
180 QuicInMemoryCachePeer::ResetForTests(); 203 QuicInMemoryCachePeer::ResetForTests();
181 } 204 }
182 205
183 virtual QuicTestClient* CreateQuicClient(QuicPacketWriterWrapper* writer) { 206 QuicTestClient* CreateQuicClient(QuicPacketWriterWrapper* writer) {
184 QuicTestClient* client = new QuicTestClient(server_address_, 207 QuicTestClient* client = new QuicTestClient(server_address_,
185 server_hostname_, 208 server_hostname_,
186 false, // not secure 209 false, // not secure
187 client_config_, 210 client_config_,
188 client_supported_versions_); 211 client_supported_versions_);
189 client->UseWriter(writer); 212 client->UseWriter(writer);
190 client->Connect(); 213 client->Connect();
191 return client; 214 return client;
192 } 215 }
193 216
194 virtual bool Initialize() { 217 bool Initialize() {
195 // Start the server first, because CreateQuicClient() attempts 218 // Start the server first, because CreateQuicClient() attempts
196 // to connect to the server. 219 // to connect to the server.
197 StartServer(); 220 StartServer();
198 client_.reset(CreateQuicClient(client_writer_)); 221 client_.reset(CreateQuicClient(client_writer_));
199 QuicEpollConnectionHelper* helper = 222 static EpollEvent event(EPOLLOUT, false);
223 client_writer_->Initialize(
200 reinterpret_cast<QuicEpollConnectionHelper*>( 224 reinterpret_cast<QuicEpollConnectionHelper*>(
201 QuicConnectionPeer::GetHelper( 225 QuicConnectionPeer::GetHelper(
202 client_->client()->session()->connection())); 226 client_->client()->session()->connection())),
203 client_writer_->SetConnectionHelper(helper); 227 new ClientDelegate(client_->client()));
204 return client_->client()->connected(); 228 return client_->client()->connected();
205 } 229 }
206 230
207 virtual void SetUp() { 231 virtual void SetUp() OVERRIDE {
208 // The ownership of these gets transferred to the QuicPacketWriterWrapper 232 // The ownership of these gets transferred to the QuicPacketWriterWrapper
209 // and QuicDispatcher when Initialize() is executed. 233 // and QuicDispatcher when Initialize() is executed.
210 client_writer_ = new PacketDroppingTestWriter(); 234 client_writer_ = new PacketDroppingTestWriter();
211 server_writer_ = new PacketDroppingTestWriter(); 235 server_writer_ = new PacketDroppingTestWriter();
212 } 236 }
213 237
214 virtual void TearDown() { 238 virtual void TearDown() OVERRIDE {
215 StopServer(); 239 StopServer();
216 } 240 }
217 241
218 void StartServer() { 242 void StartServer() {
219 server_thread_.reset(new ServerThread(server_address_, server_config_, 243 server_thread_.reset(new ServerThread(server_address_, server_config_,
220 server_supported_versions_, 244 server_supported_versions_,
221 strike_register_no_startup_period_)); 245 strike_register_no_startup_period_));
222 server_thread_->Initialize(); 246 server_thread_->Initialize();
223 server_address_ = IPEndPoint(server_address_.address(), 247 server_address_ = IPEndPoint(server_address_.address(),
224 server_thread_->GetPort()); 248 server_thread_->GetPort());
225 QuicDispatcher* dispatcher = 249 QuicDispatcher* dispatcher =
226 QuicServerPeer::GetDispatcher(server_thread_->server()); 250 QuicServerPeer::GetDispatcher(server_thread_->server());
227 QuicDispatcherPeer::UseWriter(dispatcher, server_writer_); 251 QuicDispatcherPeer::UseWriter(dispatcher, server_writer_);
228 server_writer_->SetConnectionHelper( 252 server_writer_->Initialize(
229 QuicDispatcherPeer::GetHelper(dispatcher)); 253 QuicDispatcherPeer::GetHelper(dispatcher),
254 new ServerDelegate(dispatcher));
230 server_thread_->Start(); 255 server_thread_->Start();
231 server_started_ = true; 256 server_started_ = true;
232 } 257 }
233 258
234 void StopServer() { 259 void StopServer() {
235 if (!server_started_) 260 if (!server_started_)
236 return; 261 return;
237 if (server_thread_.get()) { 262 if (server_thread_.get()) {
238 server_thread_->Quit(); 263 server_thread_->Quit();
239 server_thread_->Join(); 264 server_thread_->Join();
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 string body; 484 string body;
460 GenerateBody(&body, 1024 * 1024); 485 GenerateBody(&body, 1024 * 1024);
461 486
462 HTTPMessage request(HttpConstants::HTTP_1_1, 487 HTTPMessage request(HttpConstants::HTTP_1_1,
463 HttpConstants::POST, "/foo"); 488 HttpConstants::POST, "/foo");
464 request.AddBody(body, true); 489 request.AddBody(body, true);
465 490
466 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); 491 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request));
467 } 492 }
468 493
469 // TODO(ianswett): Re-enable once b/12646613 and b/11206052 are fixed. 494 TEST_P(EndToEndTest, LargePostWithPacketLossAndBlockedSocket) {
470 TEST_P(EndToEndTest, DISABLED_LargePostWithPacketLossAndBlockedSocket) {
471 // Connect with lower fake packet loss than we'd like to test. Until 495 // Connect with lower fake packet loss than we'd like to test. Until
472 // b/10126687 is fixed, losing handshake packets is pretty brutal. 496 // b/10126687 is fixed, losing handshake packets is pretty brutal.
473 SetPacketLossPercentage(5); 497 SetPacketLossPercentage(5);
474 ASSERT_TRUE(Initialize()); 498 ASSERT_TRUE(Initialize());
475 499
476 // Wait for the server SHLO before upping the packet loss. 500 // Wait for the server SHLO before upping the packet loss.
477 client_->client()->WaitForCryptoHandshakeConfirmed(); 501 client_->client()->WaitForCryptoHandshakeConfirmed();
478 SetPacketLossPercentage(30); 502 SetPacketLossPercentage(10);
479 client_writer_->set_fake_blocked_socket_percentage(10); 503 client_writer_->set_fake_blocked_socket_percentage(10);
480 504
481 // 10 Kb body. 505 // 10 Kb body.
482 string body; 506 string body;
483 GenerateBody(&body, 1024 * 10); 507 GenerateBody(&body, 1024 * 10);
484 508
485 HTTPMessage request(HttpConstants::HTTP_1_1, 509 HTTPMessage request(HttpConstants::HTTP_1_1,
486 HttpConstants::POST, "/foo"); 510 HttpConstants::POST, "/foo");
487 request.AddBody(body, true); 511 request.AddBody(body, true);
488 512
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 WrongAddressWriter() { 831 WrongAddressWriter() {
808 IPAddressNumber ip; 832 IPAddressNumber ip;
809 CHECK(net::ParseIPLiteralToNumber("127.0.0.2", &ip)); 833 CHECK(net::ParseIPLiteralToNumber("127.0.0.2", &ip));
810 self_address_ = IPEndPoint(ip, 0); 834 self_address_ = IPEndPoint(ip, 0);
811 } 835 }
812 836
813 virtual WriteResult WritePacket( 837 virtual WriteResult WritePacket(
814 const char* buffer, 838 const char* buffer,
815 size_t buf_len, 839 size_t buf_len,
816 const IPAddressNumber& real_self_address, 840 const IPAddressNumber& real_self_address,
817 const IPEndPoint& peer_address, 841 const IPEndPoint& peer_address) OVERRIDE {
818 QuicBlockedWriterInterface* blocked_writer) OVERRIDE {
819 // Use wrong address! 842 // Use wrong address!
820 return QuicPacketWriterWrapper::WritePacket( 843 return QuicPacketWriterWrapper::WritePacket(
821 buffer, buf_len, self_address_.address(), peer_address, blocked_writer); 844 buffer, buf_len, self_address_.address(), peer_address);
822 } 845 }
823 846
824 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { 847 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE {
825 return false; 848 return false;
826 } 849 }
827 850
828 IPEndPoint self_address_; 851 IPEndPoint self_address_;
829 }; 852 };
830 853
831 TEST_P(EndToEndTest, ConnectionMigration) { 854 TEST_P(EndToEndTest, ConnectionMigration) {
(...skipping 12 matching lines...) Expand all
844 client_->SendSynchronousRequest("/bar"); 867 client_->SendSynchronousRequest("/bar");
845 868
846 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); 869 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error());
847 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); 870 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error());
848 } 871 }
849 872
850 } // namespace 873 } // namespace
851 } // namespace test 874 } // namespace test
852 } // namespace tools 875 } // namespace tools
853 } // namespace net 876 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_test_utils.cc ('k') | net/tools/quic/quic_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698