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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 // Run all tests with the cross products of all versions. | 68 // Run all tests with the cross products of all versions. |
69 struct TestParams { | 69 struct TestParams { |
70 TestParams(const QuicVersionVector& client_supported_versions, | 70 TestParams(const QuicVersionVector& client_supported_versions, |
71 const QuicVersionVector& server_supported_versions, | 71 const QuicVersionVector& server_supported_versions, |
72 QuicVersion negotiated_version, | 72 QuicVersion negotiated_version, |
73 bool use_pacing) | 73 bool use_pacing) |
74 : client_supported_versions(client_supported_versions), | 74 : client_supported_versions(client_supported_versions), |
75 server_supported_versions(server_supported_versions), | 75 server_supported_versions(server_supported_versions), |
76 negotiated_version(negotiated_version), | 76 negotiated_version(negotiated_version), |
77 use_pacing(use_pacing) { | 77 use_pacing(use_pacing) {} |
78 } | |
79 | 78 |
80 friend ostream& operator<<(ostream& os, const TestParams& p) { | 79 friend ostream& operator<<(ostream& os, const TestParams& p) { |
81 os << "{ server_supported_versions: " | 80 os << "{ server_supported_versions: " |
82 << QuicVersionVectorToString(p.server_supported_versions); | 81 << QuicVersionVectorToString(p.server_supported_versions); |
83 os << " client_supported_versions: " | 82 os << " client_supported_versions: " |
84 << QuicVersionVectorToString(p.client_supported_versions); | 83 << QuicVersionVectorToString(p.client_supported_versions); |
85 os << " negotiated_version: " << QuicVersionToString(p.negotiated_version); | 84 os << " negotiated_version: " << QuicVersionToString(p.negotiated_version); |
86 os << " use_pacing: " << p.use_pacing << " }"; | 85 os << " use_pacing: " << p.use_pacing << " }"; |
87 return os; | 86 return os; |
88 } | 87 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 124 } |
126 return params; | 125 return params; |
127 } | 126 } |
128 | 127 |
129 class ServerDelegate : public PacketDroppingTestWriter::Delegate { | 128 class ServerDelegate : public PacketDroppingTestWriter::Delegate { |
130 public: | 129 public: |
131 explicit ServerDelegate(QuicDispatcher* dispatcher) | 130 explicit ServerDelegate(QuicDispatcher* dispatcher) |
132 : dispatcher_(dispatcher) {} | 131 : dispatcher_(dispatcher) {} |
133 virtual ~ServerDelegate() {} | 132 virtual ~ServerDelegate() {} |
134 virtual void OnCanWrite() OVERRIDE { dispatcher_->OnCanWrite(); } | 133 virtual void OnCanWrite() OVERRIDE { dispatcher_->OnCanWrite(); } |
| 134 |
135 private: | 135 private: |
136 QuicDispatcher* dispatcher_; | 136 QuicDispatcher* dispatcher_; |
137 }; | 137 }; |
138 | 138 |
139 class ClientDelegate : public PacketDroppingTestWriter::Delegate { | 139 class ClientDelegate : public PacketDroppingTestWriter::Delegate { |
140 public: | 140 public: |
141 explicit ClientDelegate(QuicClient* client) : client_(client) {} | 141 explicit ClientDelegate(QuicClient* client) : client_(client) {} |
142 virtual ~ClientDelegate() {} | 142 virtual ~ClientDelegate() {} |
143 virtual void OnCanWrite() OVERRIDE { | 143 virtual void OnCanWrite() OVERRIDE { |
144 EpollEvent event(EPOLLOUT, false); | 144 EpollEvent event(EPOLLOUT, false); |
145 client_->OnEvent(client_->fd(), &event); | 145 client_->OnEvent(client_->fd(), &event); |
146 } | 146 } |
| 147 |
147 private: | 148 private: |
148 QuicClient* client_; | 149 QuicClient* client_; |
149 }; | 150 }; |
150 | 151 |
151 class EndToEndTest : public ::testing::TestWithParam<TestParams> { | 152 class EndToEndTest : public ::testing::TestWithParam<TestParams> { |
152 protected: | 153 protected: |
153 EndToEndTest() | 154 EndToEndTest() |
154 : server_hostname_("example.com"), | 155 : server_hostname_("example.com"), |
155 server_started_(false), | 156 server_started_(false), |
156 strike_register_no_startup_period_(false) { | 157 strike_register_no_startup_period_(false) { |
(...skipping 14 matching lines...) Expand all Loading... |
171 client_config_.SetDefaults(); | 172 client_config_.SetDefaults(); |
172 server_config_.SetDefaults(); | 173 server_config_.SetDefaults(); |
173 | 174 |
174 // Use different flow control windows for client/server. | 175 // Use different flow control windows for client/server. |
175 client_initial_flow_control_receive_window_ = | 176 client_initial_flow_control_receive_window_ = |
176 2 * kInitialFlowControlWindowForTest; | 177 2 * kInitialFlowControlWindowForTest; |
177 server_initial_flow_control_receive_window_ = | 178 server_initial_flow_control_receive_window_ = |
178 3 * kInitialFlowControlWindowForTest; | 179 3 * kInitialFlowControlWindowForTest; |
179 | 180 |
180 QuicInMemoryCachePeer::ResetForTests(); | 181 QuicInMemoryCachePeer::ResetForTests(); |
181 AddToCache("GET", "https://www.google.com/foo", | 182 AddToCache("GET", |
182 "HTTP/1.1", "200", "OK", kFooResponseBody); | 183 "https://www.google.com/foo", |
183 AddToCache("GET", "https://www.google.com/bar", | 184 "HTTP/1.1", |
184 "HTTP/1.1", "200", "OK", kBarResponseBody); | 185 "200", |
| 186 "OK", |
| 187 kFooResponseBody); |
| 188 AddToCache("GET", |
| 189 "https://www.google.com/bar", |
| 190 "HTTP/1.1", |
| 191 "200", |
| 192 "OK", |
| 193 kBarResponseBody); |
185 } | 194 } |
186 | 195 |
187 virtual ~EndToEndTest() { | 196 virtual ~EndToEndTest() { |
188 // TODO(rtenneti): port RecycleUnusedPort if needed. | 197 // TODO(rtenneti): port RecycleUnusedPort if needed. |
189 // RecycleUnusedPort(server_address_.port()); | 198 // RecycleUnusedPort(server_address_.port()); |
190 QuicInMemoryCachePeer::ResetForTests(); | 199 QuicInMemoryCachePeer::ResetForTests(); |
191 } | 200 } |
192 | 201 |
193 QuicTestClient* CreateQuicClient(QuicPacketWriterWrapper* writer) { | 202 QuicTestClient* CreateQuicClient(QuicPacketWriterWrapper* writer) { |
194 QuicTestClient* client = new QuicTestClient( | 203 QuicTestClient* client = |
195 server_address_, | 204 new QuicTestClient(server_address_, |
196 server_hostname_, | 205 server_hostname_, |
197 false, // not secure | 206 false, // not secure |
198 client_config_, | 207 client_config_, |
199 client_supported_versions_, | 208 client_supported_versions_, |
200 client_initial_flow_control_receive_window_); | 209 client_initial_flow_control_receive_window_); |
201 client->UseWriter(writer); | 210 client->UseWriter(writer); |
202 client->Connect(); | 211 client->Connect(); |
203 return client; | 212 return client; |
204 } | 213 } |
205 | 214 |
206 void set_client_initial_flow_control_receive_window(uint32 window) { | 215 void set_client_initial_flow_control_receive_window(uint32 window) { |
207 CHECK(client_.get() == NULL); | 216 CHECK(client_.get() == NULL); |
208 DVLOG(1) << "Setting client initial flow control window: " << window; | 217 DVLOG(1) << "Setting client initial flow control window: " << window; |
209 client_initial_flow_control_receive_window_ = window; | 218 client_initial_flow_control_receive_window_ = window; |
210 } | 219 } |
(...skipping 18 matching lines...) Expand all Loading... |
229 return client_->client()->connected(); | 238 return client_->client()->connected(); |
230 } | 239 } |
231 | 240 |
232 virtual void SetUp() OVERRIDE { | 241 virtual void SetUp() OVERRIDE { |
233 // The ownership of these gets transferred to the QuicPacketWriterWrapper | 242 // The ownership of these gets transferred to the QuicPacketWriterWrapper |
234 // and QuicDispatcher when Initialize() is executed. | 243 // and QuicDispatcher when Initialize() is executed. |
235 client_writer_ = new PacketDroppingTestWriter(); | 244 client_writer_ = new PacketDroppingTestWriter(); |
236 server_writer_ = new PacketDroppingTestWriter(); | 245 server_writer_ = new PacketDroppingTestWriter(); |
237 } | 246 } |
238 | 247 |
239 virtual void TearDown() OVERRIDE { | 248 virtual void TearDown() OVERRIDE { StopServer(); } |
240 StopServer(); | |
241 } | |
242 | 249 |
243 void StartServer() { | 250 void StartServer() { |
244 server_thread_.reset( | 251 server_thread_.reset( |
245 new ServerThread(server_address_, | 252 new ServerThread(server_address_, |
246 server_config_, | 253 server_config_, |
247 server_supported_versions_, | 254 server_supported_versions_, |
248 strike_register_no_startup_period_, | 255 strike_register_no_startup_period_, |
249 server_initial_flow_control_receive_window_)); | 256 server_initial_flow_control_receive_window_)); |
250 server_thread_->Initialize(); | 257 server_thread_->Initialize(); |
251 server_address_ = IPEndPoint(server_address_.address(), | 258 server_address_ = |
252 server_thread_->GetPort()); | 259 IPEndPoint(server_address_.address(), server_thread_->GetPort()); |
253 QuicDispatcher* dispatcher = | 260 QuicDispatcher* dispatcher = |
254 QuicServerPeer::GetDispatcher(server_thread_->server()); | 261 QuicServerPeer::GetDispatcher(server_thread_->server()); |
255 QuicDispatcherPeer::UseWriter(dispatcher, server_writer_); | 262 QuicDispatcherPeer::UseWriter(dispatcher, server_writer_); |
256 server_writer_->Initialize( | 263 server_writer_->Initialize(QuicDispatcherPeer::GetHelper(dispatcher), |
257 QuicDispatcherPeer::GetHelper(dispatcher), | 264 new ServerDelegate(dispatcher)); |
258 new ServerDelegate(dispatcher)); | |
259 server_thread_->Start(); | 265 server_thread_->Start(); |
260 server_started_ = true; | 266 server_started_ = true; |
261 } | 267 } |
262 | 268 |
263 void StopServer() { | 269 void StopServer() { |
264 if (!server_started_) | 270 if (!server_started_) |
265 return; | 271 return; |
266 if (server_thread_.get()) { | 272 if (server_thread_.get()) { |
267 server_thread_->Quit(); | 273 server_thread_->Quit(); |
268 server_thread_->Join(); | 274 server_thread_->Join(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 server_address_ = IPEndPoint(ip, server_address_.port()); | 375 server_address_ = IPEndPoint(ip, server_address_.port()); |
370 ASSERT_TRUE(Initialize()); | 376 ASSERT_TRUE(Initialize()); |
371 | 377 |
372 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 378 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
373 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 379 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
374 } | 380 } |
375 | 381 |
376 TEST_P(EndToEndTest, SeparateFinPacket) { | 382 TEST_P(EndToEndTest, SeparateFinPacket) { |
377 ASSERT_TRUE(Initialize()); | 383 ASSERT_TRUE(Initialize()); |
378 | 384 |
379 HTTPMessage request(HttpConstants::HTTP_1_1, | 385 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
380 HttpConstants::POST, "/foo"); | |
381 request.set_has_complete_message(false); | 386 request.set_has_complete_message(false); |
382 | 387 |
383 client_->SendMessage(request); | 388 client_->SendMessage(request); |
384 | 389 |
385 client_->SendData(string(), true); | 390 client_->SendData(string(), true); |
386 | 391 |
387 client_->WaitForResponse(); | 392 client_->WaitForResponse(); |
388 EXPECT_EQ(kFooResponseBody, client_->response_body()); | 393 EXPECT_EQ(kFooResponseBody, client_->response_body()); |
389 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 394 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
390 | 395 |
(...skipping 12 matching lines...) Expand all Loading... |
403 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 408 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
404 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 409 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
405 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); | 410 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); |
406 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 411 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
407 } | 412 } |
408 | 413 |
409 TEST_P(EndToEndTest, MultipleClients) { | 414 TEST_P(EndToEndTest, MultipleClients) { |
410 ASSERT_TRUE(Initialize()); | 415 ASSERT_TRUE(Initialize()); |
411 scoped_ptr<QuicTestClient> client2(CreateQuicClient(NULL)); | 416 scoped_ptr<QuicTestClient> client2(CreateQuicClient(NULL)); |
412 | 417 |
413 HTTPMessage request(HttpConstants::HTTP_1_1, | 418 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
414 HttpConstants::POST, "/foo"); | |
415 request.AddHeader("content-length", "3"); | 419 request.AddHeader("content-length", "3"); |
416 request.set_has_complete_message(false); | 420 request.set_has_complete_message(false); |
417 | 421 |
418 client_->SendMessage(request); | 422 client_->SendMessage(request); |
419 client2->SendMessage(request); | 423 client2->SendMessage(request); |
420 | 424 |
421 client_->SendData("bar", true); | 425 client_->SendData("bar", true); |
422 client_->WaitForResponse(); | 426 client_->WaitForResponse(); |
423 EXPECT_EQ(kFooResponseBody, client_->response_body()); | 427 EXPECT_EQ(kFooResponseBody, client_->response_body()); |
424 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 428 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
(...skipping 27 matching lines...) Expand all Loading... |
452 SetReorderPercentage(50); | 456 SetReorderPercentage(50); |
453 | 457 |
454 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest(huge_request)); | 458 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest(huge_request)); |
455 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 459 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
456 } | 460 } |
457 | 461 |
458 TEST_P(EndToEndTest, PostMissingBytes) { | 462 TEST_P(EndToEndTest, PostMissingBytes) { |
459 ASSERT_TRUE(Initialize()); | 463 ASSERT_TRUE(Initialize()); |
460 | 464 |
461 // Add a content length header with no body. | 465 // Add a content length header with no body. |
462 HTTPMessage request(HttpConstants::HTTP_1_1, | 466 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
463 HttpConstants::POST, "/foo"); | |
464 request.AddHeader("content-length", "3"); | 467 request.AddHeader("content-length", "3"); |
465 request.set_skip_message_validation(true); | 468 request.set_skip_message_validation(true); |
466 | 469 |
467 // This should be detected as stream fin without complete request, | 470 // This should be detected as stream fin without complete request, |
468 // triggering an error response. | 471 // triggering an error response. |
469 client_->SendCustomSynchronousRequest(request); | 472 client_->SendCustomSynchronousRequest(request); |
470 EXPECT_EQ("bad", client_->response_body()); | 473 EXPECT_EQ("bad", client_->response_body()); |
471 EXPECT_EQ(500u, client_->response_headers()->parsed_response_code()); | 474 EXPECT_EQ(500u, client_->response_headers()->parsed_response_code()); |
472 } | 475 } |
473 | 476 |
474 // TODO(rtenneti): DISABLED_LargePostNoPacketLoss seems to be flaky. | 477 // TODO(rtenneti): DISABLED_LargePostNoPacketLoss seems to be flaky. |
475 // http://crbug.com/297040. | 478 // http://crbug.com/297040. |
476 TEST_P(EndToEndTest, DISABLED_LargePostNoPacketLoss) { | 479 TEST_P(EndToEndTest, DISABLED_LargePostNoPacketLoss) { |
477 ASSERT_TRUE(Initialize()); | 480 ASSERT_TRUE(Initialize()); |
478 | 481 |
479 client_->client()->WaitForCryptoHandshakeConfirmed(); | 482 client_->client()->WaitForCryptoHandshakeConfirmed(); |
480 | 483 |
481 // 1 Mb body. | 484 // 1 Mb body. |
482 string body; | 485 string body; |
483 GenerateBody(&body, 1024 * 1024); | 486 GenerateBody(&body, 1024 * 1024); |
484 | 487 |
485 HTTPMessage request(HttpConstants::HTTP_1_1, | 488 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
486 HttpConstants::POST, "/foo"); | |
487 request.AddBody(body, true); | 489 request.AddBody(body, true); |
488 | 490 |
489 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | 491 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); |
490 VerifyCleanConnection(false); | 492 VerifyCleanConnection(false); |
491 } | 493 } |
492 | 494 |
493 TEST_P(EndToEndTest, LargePostNoPacketLoss1sRTT) { | 495 TEST_P(EndToEndTest, LargePostNoPacketLoss1sRTT) { |
494 ASSERT_TRUE(Initialize()); | 496 ASSERT_TRUE(Initialize()); |
495 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(1000)); | 497 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(1000)); |
496 | 498 |
497 client_->client()->WaitForCryptoHandshakeConfirmed(); | 499 client_->client()->WaitForCryptoHandshakeConfirmed(); |
498 | 500 |
499 // 1 Mb body. | 501 // 1 Mb body. |
500 string body; | 502 string body; |
501 GenerateBody(&body, 100 * 1024); | 503 GenerateBody(&body, 100 * 1024); |
502 | 504 |
503 HTTPMessage request(HttpConstants::HTTP_1_1, | 505 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
504 HttpConstants::POST, "/foo"); | |
505 request.AddBody(body, true); | 506 request.AddBody(body, true); |
506 | 507 |
507 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | 508 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); |
508 VerifyCleanConnection(false); | 509 VerifyCleanConnection(false); |
509 } | 510 } |
510 | 511 |
511 TEST_P(EndToEndTest, LargePostWithPacketLoss) { | 512 TEST_P(EndToEndTest, LargePostWithPacketLoss) { |
512 // Connect with lower fake packet loss than we'd like to test. Until | 513 // Connect with lower fake packet loss than we'd like to test. Until |
513 // b/10126687 is fixed, losing handshake packets is pretty brutal. | 514 // b/10126687 is fixed, losing handshake packets is pretty brutal. |
514 SetPacketLossPercentage(5); | 515 SetPacketLossPercentage(5); |
515 ASSERT_TRUE(Initialize()); | 516 ASSERT_TRUE(Initialize()); |
516 | 517 |
517 // Wait for the server SHLO before upping the packet loss. | 518 // Wait for the server SHLO before upping the packet loss. |
518 client_->client()->WaitForCryptoHandshakeConfirmed(); | 519 client_->client()->WaitForCryptoHandshakeConfirmed(); |
519 SetPacketLossPercentage(30); | 520 SetPacketLossPercentage(30); |
520 | 521 |
521 // 10 Kb body. | 522 // 10 Kb body. |
522 string body; | 523 string body; |
523 GenerateBody(&body, 1024 * 10); | 524 GenerateBody(&body, 1024 * 10); |
524 | 525 |
525 HTTPMessage request(HttpConstants::HTTP_1_1, | 526 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
526 HttpConstants::POST, "/foo"); | |
527 request.AddBody(body, true); | 527 request.AddBody(body, true); |
528 | 528 |
529 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | 529 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); |
530 } | 530 } |
531 | 531 |
532 TEST_P(EndToEndTest, LargePostNoPacketLossWithDelayAndReordering) { | 532 TEST_P(EndToEndTest, LargePostNoPacketLossWithDelayAndReordering) { |
533 ASSERT_TRUE(Initialize()); | 533 ASSERT_TRUE(Initialize()); |
534 | 534 |
535 client_->client()->WaitForCryptoHandshakeConfirmed(); | 535 client_->client()->WaitForCryptoHandshakeConfirmed(); |
536 // Both of these must be called when the writer is not actively used. | 536 // Both of these must be called when the writer is not actively used. |
537 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); | 537 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); |
538 SetReorderPercentage(30); | 538 SetReorderPercentage(30); |
539 | 539 |
540 // 1 Mb body. | 540 // 1 Mb body. |
541 string body; | 541 string body; |
542 GenerateBody(&body, 1024 * 1024); | 542 GenerateBody(&body, 1024 * 1024); |
543 | 543 |
544 HTTPMessage request(HttpConstants::HTTP_1_1, | 544 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
545 HttpConstants::POST, "/foo"); | |
546 request.AddBody(body, true); | 545 request.AddBody(body, true); |
547 | 546 |
548 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | 547 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); |
549 VerifyCleanConnection(true); | 548 VerifyCleanConnection(true); |
550 } | 549 } |
551 | 550 |
552 TEST_P(EndToEndTest, LargePostWithPacketLossAndBlockedSocket) { | 551 TEST_P(EndToEndTest, LargePostWithPacketLossAndBlockedSocket) { |
553 // Connect with lower fake packet loss than we'd like to test. Until | 552 // Connect with lower fake packet loss than we'd like to test. Until |
554 // b/10126687 is fixed, losing handshake packets is pretty brutal. | 553 // b/10126687 is fixed, losing handshake packets is pretty brutal. |
555 SetPacketLossPercentage(5); | 554 SetPacketLossPercentage(5); |
556 ASSERT_TRUE(Initialize()); | 555 ASSERT_TRUE(Initialize()); |
557 | 556 |
558 // Wait for the server SHLO before upping the packet loss. | 557 // Wait for the server SHLO before upping the packet loss. |
559 client_->client()->WaitForCryptoHandshakeConfirmed(); | 558 client_->client()->WaitForCryptoHandshakeConfirmed(); |
560 SetPacketLossPercentage(10); | 559 SetPacketLossPercentage(10); |
561 client_writer_->set_fake_blocked_socket_percentage(10); | 560 client_writer_->set_fake_blocked_socket_percentage(10); |
562 | 561 |
563 // 10 Kb body. | 562 // 10 Kb body. |
564 string body; | 563 string body; |
565 GenerateBody(&body, 1024 * 10); | 564 GenerateBody(&body, 1024 * 10); |
566 | 565 |
567 HTTPMessage request(HttpConstants::HTTP_1_1, | 566 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
568 HttpConstants::POST, "/foo"); | |
569 request.AddBody(body, true); | 567 request.AddBody(body, true); |
570 | 568 |
571 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | 569 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); |
572 } | 570 } |
573 | 571 |
574 // TODO(rtenneti): rch is investigating the root cause. Will enable after we | 572 // TODO(rtenneti): rch is investigating the root cause. Will enable after we |
575 // find the bug. | 573 // find the bug. |
576 TEST_P(EndToEndTest, DISABLED_LargePostZeroRTTFailure) { | 574 TEST_P(EndToEndTest, DISABLED_LargePostZeroRTTFailure) { |
577 // Have the server accept 0-RTT without waiting a startup period. | 575 // Have the server accept 0-RTT without waiting a startup period. |
578 strike_register_no_startup_period_ = true; | 576 strike_register_no_startup_period_ = true; |
579 | 577 |
580 // Send a request and then disconnect. This prepares the client to attempt | 578 // Send a request and then disconnect. This prepares the client to attempt |
581 // a 0-RTT handshake for the next request. | 579 // a 0-RTT handshake for the next request. |
582 ASSERT_TRUE(Initialize()); | 580 ASSERT_TRUE(Initialize()); |
583 | 581 |
584 string body; | 582 string body; |
585 GenerateBody(&body, 20480); | 583 GenerateBody(&body, 20480); |
586 | 584 |
587 HTTPMessage request(HttpConstants::HTTP_1_1, | 585 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
588 HttpConstants::POST, "/foo"); | |
589 request.AddBody(body, true); | 586 request.AddBody(body, true); |
590 | 587 |
591 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | 588 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); |
592 EXPECT_EQ(2, client_->client()->session()->GetNumSentClientHellos()); | 589 EXPECT_EQ(2, client_->client()->session()->GetNumSentClientHellos()); |
593 | 590 |
594 client_->Disconnect(); | 591 client_->Disconnect(); |
595 | 592 |
596 // The 0-RTT handshake should succeed. | 593 // The 0-RTT handshake should succeed. |
597 client_->Connect(); | 594 client_->Connect(); |
598 if (client_supported_versions_[0] >= QUIC_VERSION_17 && | 595 if (client_supported_versions_[0] >= QUIC_VERSION_17 && |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 | 634 |
638 // Wait for the server SHLO before upping the packet loss. | 635 // Wait for the server SHLO before upping the packet loss. |
639 client_->client()->WaitForCryptoHandshakeConfirmed(); | 636 client_->client()->WaitForCryptoHandshakeConfirmed(); |
640 SetPacketLossPercentage(30); | 637 SetPacketLossPercentage(30); |
641 | 638 |
642 client_->options()->max_packets_per_fec_group = 6; | 639 client_->options()->max_packets_per_fec_group = 6; |
643 | 640 |
644 string body; | 641 string body; |
645 GenerateBody(&body, 10240); | 642 GenerateBody(&body, 10240); |
646 | 643 |
647 HTTPMessage request(HttpConstants::HTTP_1_1, | 644 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
648 HttpConstants::POST, "/foo"); | |
649 request.AddBody(body, true); | 645 request.AddBody(body, true); |
650 | 646 |
651 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | 647 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); |
652 VerifyCleanConnection(true); | 648 VerifyCleanConnection(true); |
653 } | 649 } |
654 | 650 |
655 TEST_P(EndToEndTest, LargePostLargeBuffer) { | 651 TEST_P(EndToEndTest, LargePostLargeBuffer) { |
656 ASSERT_TRUE(Initialize()); | 652 ASSERT_TRUE(Initialize()); |
657 SetPacketSendDelay(QuicTime::Delta::FromMicroseconds(1)); | 653 SetPacketSendDelay(QuicTime::Delta::FromMicroseconds(1)); |
658 // 1Mbit per second with a 128k buffer from server to client. Wireless | 654 // 1Mbit per second with a 128k buffer from server to client. Wireless |
659 // clients commonly have larger buffers, but our max CWND is 200. | 655 // clients commonly have larger buffers, but our max CWND is 200. |
660 server_writer_->set_max_bandwidth_and_buffer_size( | 656 server_writer_->set_max_bandwidth_and_buffer_size( |
661 QuicBandwidth::FromBytesPerSecond(256 * 1024), 128 * 1024); | 657 QuicBandwidth::FromBytesPerSecond(256 * 1024), 128 * 1024); |
662 | 658 |
663 client_->client()->WaitForCryptoHandshakeConfirmed(); | 659 client_->client()->WaitForCryptoHandshakeConfirmed(); |
664 | 660 |
665 // 1 Mb body. | 661 // 1 Mb body. |
666 string body; | 662 string body; |
667 GenerateBody(&body, 1024 * 1024); | 663 GenerateBody(&body, 1024 * 1024); |
668 | 664 |
669 HTTPMessage request(HttpConstants::HTTP_1_1, | 665 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
670 HttpConstants::POST, "/foo"); | |
671 request.AddBody(body, true); | 666 request.AddBody(body, true); |
672 | 667 |
673 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | 668 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); |
674 VerifyCleanConnection(false); | 669 VerifyCleanConnection(false); |
675 } | 670 } |
676 | 671 |
677 TEST_P(EndToEndTest, InvalidStream) { | 672 TEST_P(EndToEndTest, InvalidStream) { |
678 ASSERT_TRUE(Initialize()); | 673 ASSERT_TRUE(Initialize()); |
679 client_->client()->WaitForCryptoHandshakeConfirmed(); | 674 client_->client()->WaitForCryptoHandshakeConfirmed(); |
680 | 675 |
681 string body; | 676 string body; |
682 GenerateBody(&body, kMaxPacketSize); | 677 GenerateBody(&body, kMaxPacketSize); |
683 | 678 |
684 HTTPMessage request(HttpConstants::HTTP_1_1, | 679 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
685 HttpConstants::POST, "/foo"); | |
686 request.AddBody(body, true); | 680 request.AddBody(body, true); |
687 // Force the client to write with a stream ID belonging to a nonexistent | 681 // Force the client to write with a stream ID belonging to a nonexistent |
688 // server-side stream. | 682 // server-side stream. |
689 QuicSessionPeer::SetNextStreamId(client_->client()->session(), 2); | 683 QuicSessionPeer::SetNextStreamId(client_->client()->session(), 2); |
690 | 684 |
691 client_->SendCustomSynchronousRequest(request); | 685 client_->SendCustomSynchronousRequest(request); |
692 // EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); | 686 // EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); |
693 EXPECT_EQ(QUIC_PACKET_FOR_NONEXISTENT_STREAM, client_->connection_error()); | 687 EXPECT_EQ(QUIC_PACKET_FOR_NONEXISTENT_STREAM, client_->connection_error()); |
694 } | 688 } |
695 | 689 |
696 // TODO(rch): this test seems to cause net_unittests timeouts :| | 690 // TODO(rch): this test seems to cause net_unittests timeouts :| |
697 TEST_P(EndToEndTest, DISABLED_MultipleTermination) { | 691 TEST_P(EndToEndTest, DISABLED_MultipleTermination) { |
698 ASSERT_TRUE(Initialize()); | 692 ASSERT_TRUE(Initialize()); |
699 | 693 |
700 HTTPMessage request(HttpConstants::HTTP_1_1, | 694 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
701 HttpConstants::POST, "/foo"); | |
702 request.AddHeader("content-length", "3"); | 695 request.AddHeader("content-length", "3"); |
703 request.set_has_complete_message(false); | 696 request.set_has_complete_message(false); |
704 | 697 |
705 // Set the offset so we won't frame. Otherwise when we pick up termination | 698 // Set the offset so we won't frame. Otherwise when we pick up termination |
706 // before HTTP framing is complete, we send an error and close the stream, | 699 // before HTTP framing is complete, we send an error and close the stream, |
707 // and the second write is picked up as writing on a closed stream. | 700 // and the second write is picked up as writing on a closed stream. |
708 QuicSpdyClientStream* stream = client_->GetOrCreateStream(); | 701 QuicSpdyClientStream* stream = client_->GetOrCreateStream(); |
709 ASSERT_TRUE(stream != NULL); | 702 ASSERT_TRUE(stream != NULL); |
710 ReliableQuicStreamPeer::SetStreamBytesWritten(3, stream); | 703 ReliableQuicStreamPeer::SetStreamBytesWritten(3, stream); |
711 | 704 |
712 client_->SendData("bar", true); | 705 client_->SendData("bar", true); |
713 client_->WaitForWriteToFlush(); | 706 client_->WaitForWriteToFlush(); |
714 | 707 |
715 // By default the stream protects itself from writes after terminte is set. | 708 // By default the stream protects itself from writes after terminte is set. |
716 // Override this to test the server handling buggy clients. | 709 // Override this to test the server handling buggy clients. |
717 ReliableQuicStreamPeer::SetWriteSideClosed( | 710 ReliableQuicStreamPeer::SetWriteSideClosed(false, |
718 false, client_->GetOrCreateStream()); | 711 client_->GetOrCreateStream()); |
719 | 712 |
720 EXPECT_DFATAL(client_->SendData("eep", true), "Fin already buffered"); | 713 EXPECT_DFATAL(client_->SendData("eep", true), "Fin already buffered"); |
721 } | 714 } |
722 | 715 |
723 TEST_P(EndToEndTest, Timeout) { | 716 TEST_P(EndToEndTest, Timeout) { |
724 client_config_.set_idle_connection_state_lifetime( | 717 client_config_.set_idle_connection_state_lifetime( |
725 QuicTime::Delta::FromMicroseconds(500), | 718 QuicTime::Delta::FromMicroseconds(500), |
726 QuicTime::Delta::FromMicroseconds(500)); | 719 QuicTime::Delta::FromMicroseconds(500)); |
727 // Note: we do NOT ASSERT_TRUE: we may time out during initial handshake: | 720 // Note: we do NOT ASSERT_TRUE: we may time out during initial handshake: |
728 // that's enough to validate timeout in this case. | 721 // that's enough to validate timeout in this case. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 client_sent_packet_manager.GetRttStats()->initial_rtt_us()); | 775 client_sent_packet_manager.GetRttStats()->initial_rtt_us()); |
783 EXPECT_EQ(1u, server_sent_packet_manager.GetRttStats()->initial_rtt_us()); | 776 EXPECT_EQ(1u, server_sent_packet_manager.GetRttStats()->initial_rtt_us()); |
784 | 777 |
785 // Now use the negotiated limits with packet loss. | 778 // Now use the negotiated limits with packet loss. |
786 SetPacketLossPercentage(30); | 779 SetPacketLossPercentage(30); |
787 | 780 |
788 // 10 Kb body. | 781 // 10 Kb body. |
789 string body; | 782 string body; |
790 GenerateBody(&body, 1024 * 10); | 783 GenerateBody(&body, 1024 * 10); |
791 | 784 |
792 HTTPMessage request(HttpConstants::HTTP_1_1, | 785 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
793 HttpConstants::POST, "/foo"); | |
794 request.AddBody(body, true); | 786 request.AddBody(body, true); |
795 | 787 |
796 server_thread_->Resume(); | 788 server_thread_->Resume(); |
797 | 789 |
798 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); | 790 EXPECT_EQ(kFooResponseBody, client_->SendCustomSynchronousRequest(request)); |
799 } | 791 } |
800 | 792 |
801 TEST_P(EndToEndTest, MaxInitialRTT) { | 793 TEST_P(EndToEndTest, MaxInitialRTT) { |
802 // Client tries to suggest twice the server's max initial rtt and the server | 794 // Client tries to suggest twice the server's max initial rtt and the server |
803 // uses the max. | 795 // uses the max. |
804 client_config_.SetInitialRoundTripTimeUsToSend( | 796 client_config_.SetInitialRoundTripTimeUsToSend(2 * |
805 2 * kMaxInitialRoundTripTimeUs); | 797 kMaxInitialRoundTripTimeUs); |
806 | 798 |
807 ASSERT_TRUE(Initialize()); | 799 ASSERT_TRUE(Initialize()); |
808 client_->client()->WaitForCryptoHandshakeConfirmed(); | 800 client_->client()->WaitForCryptoHandshakeConfirmed(); |
809 server_thread_->WaitForCryptoHandshakeConfirmed(); | 801 server_thread_->WaitForCryptoHandshakeConfirmed(); |
810 | 802 |
811 server_thread_->Pause(); | 803 server_thread_->Pause(); |
812 QuicDispatcher* dispatcher = | 804 QuicDispatcher* dispatcher = |
813 QuicServerPeer::GetDispatcher(server_thread_->server()); | 805 QuicServerPeer::GetDispatcher(server_thread_->server()); |
814 ASSERT_EQ(1u, dispatcher->session_map().size()); | 806 ASSERT_EQ(1u, dispatcher->session_map().size()); |
815 QuicSession* session = dispatcher->session_map().begin()->second; | 807 QuicSession* session = dispatcher->session_map().begin()->second; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 865 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
874 } | 866 } |
875 | 867 |
876 TEST_P(EndToEndTest, MaxStreamsUberTest) { | 868 TEST_P(EndToEndTest, MaxStreamsUberTest) { |
877 SetPacketLossPercentage(1); | 869 SetPacketLossPercentage(1); |
878 ASSERT_TRUE(Initialize()); | 870 ASSERT_TRUE(Initialize()); |
879 string large_body; | 871 string large_body; |
880 GenerateBody(&large_body, 10240); | 872 GenerateBody(&large_body, 10240); |
881 int max_streams = 100; | 873 int max_streams = 100; |
882 | 874 |
883 AddToCache("GET", "/large_response", "HTTP/1.1", "200", "OK", large_body);; | 875 AddToCache("GET", "/large_response", "HTTP/1.1", "200", "OK", large_body); |
| 876 ; |
884 | 877 |
885 client_->client()->WaitForCryptoHandshakeConfirmed(); | 878 client_->client()->WaitForCryptoHandshakeConfirmed(); |
886 SetPacketLossPercentage(10); | 879 SetPacketLossPercentage(10); |
887 | 880 |
888 for (int i = 0; i < max_streams; ++i) { | 881 for (int i = 0; i < max_streams; ++i) { |
889 EXPECT_LT(0, client_->SendRequest("/large_response")); | 882 EXPECT_LT(0, client_->SendRequest("/large_response")); |
890 } | 883 } |
891 | 884 |
892 // WaitForEvents waits 50ms and returns true if there are outstanding | 885 // WaitForEvents waits 50ms and returns true if there are outstanding |
893 // requests. | 886 // requests. |
(...skipping 30 matching lines...) Expand all Loading... |
924 } | 917 } |
925 | 918 |
926 class WrongAddressWriter : public QuicPacketWriterWrapper { | 919 class WrongAddressWriter : public QuicPacketWriterWrapper { |
927 public: | 920 public: |
928 WrongAddressWriter() { | 921 WrongAddressWriter() { |
929 IPAddressNumber ip; | 922 IPAddressNumber ip; |
930 CHECK(net::ParseIPLiteralToNumber("127.0.0.2", &ip)); | 923 CHECK(net::ParseIPLiteralToNumber("127.0.0.2", &ip)); |
931 self_address_ = IPEndPoint(ip, 0); | 924 self_address_ = IPEndPoint(ip, 0); |
932 } | 925 } |
933 | 926 |
934 virtual WriteResult WritePacket( | 927 virtual WriteResult WritePacket(const char* buffer, |
935 const char* buffer, | 928 size_t buf_len, |
936 size_t buf_len, | 929 const IPAddressNumber& real_self_address, |
937 const IPAddressNumber& real_self_address, | 930 const IPEndPoint& peer_address) OVERRIDE { |
938 const IPEndPoint& peer_address) OVERRIDE { | |
939 // Use wrong address! | 931 // Use wrong address! |
940 return QuicPacketWriterWrapper::WritePacket( | 932 return QuicPacketWriterWrapper::WritePacket( |
941 buffer, buf_len, self_address_.address(), peer_address); | 933 buffer, buf_len, self_address_.address(), peer_address); |
942 } | 934 } |
943 | 935 |
944 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { | 936 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { return false; } |
945 return false; | |
946 } | |
947 | 937 |
948 IPEndPoint self_address_; | 938 IPEndPoint self_address_; |
949 }; | 939 }; |
950 | 940 |
951 TEST_P(EndToEndTest, ConnectionMigration) { | 941 TEST_P(EndToEndTest, ConnectionMigration) { |
952 ASSERT_TRUE(Initialize()); | 942 ASSERT_TRUE(Initialize()); |
953 | 943 |
954 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 944 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
955 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 945 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
956 | 946 |
(...skipping 20 matching lines...) Expand all Loading... |
977 const uint32 kServerIFCW = 654321; | 967 const uint32 kServerIFCW = 654321; |
978 set_server_initial_flow_control_receive_window(kServerIFCW); | 968 set_server_initial_flow_control_receive_window(kServerIFCW); |
979 | 969 |
980 ASSERT_TRUE(Initialize()); | 970 ASSERT_TRUE(Initialize()); |
981 | 971 |
982 // Values are exchanged during crypto handshake, so wait for that to finish. | 972 // Values are exchanged during crypto handshake, so wait for that to finish. |
983 client_->client()->WaitForCryptoHandshakeConfirmed(); | 973 client_->client()->WaitForCryptoHandshakeConfirmed(); |
984 server_thread_->WaitForCryptoHandshakeConfirmed(); | 974 server_thread_->WaitForCryptoHandshakeConfirmed(); |
985 | 975 |
986 // Client should have the right value for server's receive window. | 976 // Client should have the right value for server's receive window. |
987 EXPECT_EQ(kServerIFCW, client_->client() | 977 EXPECT_EQ(kServerIFCW, |
988 ->session() | 978 client_->client() |
989 ->config() | 979 ->session() |
990 ->ReceivedInitialFlowControlWindowBytes()); | 980 ->config() |
| 981 ->ReceivedInitialFlowControlWindowBytes()); |
991 | 982 |
992 // Server should have the right value for client's receive window. | 983 // Server should have the right value for client's receive window. |
993 server_thread_->Pause(); | 984 server_thread_->Pause(); |
994 QuicDispatcher* dispatcher = | 985 QuicDispatcher* dispatcher = |
995 QuicServerPeer::GetDispatcher(server_thread_->server()); | 986 QuicServerPeer::GetDispatcher(server_thread_->server()); |
996 QuicSession* session = dispatcher->session_map().begin()->second; | 987 QuicSession* session = dispatcher->session_map().begin()->second; |
997 EXPECT_EQ(kClientIFCW, | 988 EXPECT_EQ(kClientIFCW, |
998 session->config()->ReceivedInitialFlowControlWindowBytes()); | 989 session->config()->ReceivedInitialFlowControlWindowBytes()); |
999 server_thread_->Resume(); | 990 server_thread_->Resume(); |
1000 } | 991 } |
1001 | 992 |
1002 } // namespace | 993 } // namespace |
1003 } // namespace test | 994 } // namespace test |
1004 } // namespace tools | 995 } // namespace tools |
1005 } // namespace net | 996 } // namespace net |
OLD | NEW |