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

Side by Side Diff: net/server/http_server_unittest.cc

Issue 245563002: Fixes flaky HttpServer.SendRaw failures. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review fixes Created 6 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <utility> 5 #include <utility>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 return connect_result_; 84 return connect_result_;
85 } 85 }
86 86
87 void Send(const std::string& data) { 87 void Send(const std::string& data) {
88 write_buffer_ = 88 write_buffer_ =
89 new DrainableIOBuffer(new StringIOBuffer(data), data.length()); 89 new DrainableIOBuffer(new StringIOBuffer(data), data.length());
90 Write(); 90 Write();
91 } 91 }
92 92
93 bool Read(std::string* message) { 93 bool Read(std::string* message) {
94 net::TestCompletionCallback callback; 94 return Read(message, 1);
95 ReadInternal(callback.callback()); 95 }
96 int bytes_received = callback.WaitForResult(); 96
97 if (bytes_received <= 0) 97 bool Read(std::string* message, int expected_bytes) {
98 return false; 98 int total_bytes_received = 0;
99 *message = std::string(read_buffer_->data(), bytes_received); 99 message->clear();
100 while (total_bytes_received < expected_bytes) {
101 net::TestCompletionCallback callback;
102 ReadInternal(callback.callback());
103 int bytes_received = callback.WaitForResult();
104 if (bytes_received <= 0)
105 return false;
106
107 total_bytes_received += bytes_received;
108 message->append(read_buffer_->data(), bytes_received);
109 }
100 return true; 110 return true;
101 } 111 }
102 112
103 private: 113 private:
104 void OnConnect(const base::Closure& quit_loop, int result) { 114 void OnConnect(const base::Closure& quit_loop, int result) {
105 connect_result_ = result; 115 connect_result_ = result;
106 quit_loop.Run(); 116 quit_loop.Run();
107 } 117 }
108 118
109 void Write() { 119 void Write() {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 client.Send("GET /test HTTP/1.1\r\n\r\n"); 311 client.Send("GET /test HTTP/1.1\r\n\r\n");
302 ASSERT_TRUE(RunUntilRequestsReceived(1)); 312 ASSERT_TRUE(RunUntilRequestsReceived(1));
303 server_->Send200(GetConnectionId(0), "Response!", "text/plain"); 313 server_->Send200(GetConnectionId(0), "Response!", "text/plain");
304 314
305 std::string response; 315 std::string response;
306 ASSERT_TRUE(client.Read(&response)); 316 ASSERT_TRUE(client.Read(&response));
307 ASSERT_TRUE(StartsWithASCII(response, "HTTP/1.1 200 OK", true)); 317 ASSERT_TRUE(StartsWithASCII(response, "HTTP/1.1 200 OK", true));
308 ASSERT_TRUE(EndsWith(response, "Response!", true)); 318 ASSERT_TRUE(EndsWith(response, "Response!", true));
309 } 319 }
310 320
311 // Flaky on at least OS X and Vista. http://crbug.com/365067. 321 TEST_F(HttpServerTest, SendRaw) {
312 TEST_F(HttpServerTest, DISABLED_SendRaw) {
313 TestHttpClient client; 322 TestHttpClient client;
314 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); 323 ASSERT_EQ(OK, client.ConnectAndWait(server_address_));
315 client.Send("GET /test HTTP/1.1\r\n\r\n"); 324 client.Send("GET /test HTTP/1.1\r\n\r\n");
316 ASSERT_TRUE(RunUntilRequestsReceived(1)); 325 ASSERT_TRUE(RunUntilRequestsReceived(1));
317 server_->SendRaw(GetConnectionId(0), "Raw Data "); 326 server_->SendRaw(GetConnectionId(0), "Raw Data ");
318 server_->SendRaw(GetConnectionId(0), "More Data"); 327 server_->SendRaw(GetConnectionId(0), "More Data");
319 server_->SendRaw(GetConnectionId(0), "Third Piece of Data"); 328 server_->SendRaw(GetConnectionId(0), "Third Piece of Data");
320 329
330 const std::string expected_response("Raw Data More DataThird Piece of Data");
321 std::string response; 331 std::string response;
322 ASSERT_TRUE(client.Read(&response)); 332 ASSERT_TRUE(client.Read(&response, expected_response.length()));
323 ASSERT_EQ("Raw Data More DataThird Piece of Data", response); 333 ASSERT_EQ(expected_response, response);
324 } 334 }
325 335
326 namespace { 336 namespace {
327 337
328 class MockStreamListenSocket : public StreamListenSocket { 338 class MockStreamListenSocket : public StreamListenSocket {
329 public: 339 public:
330 MockStreamListenSocket(StreamListenSocket::Delegate* delegate) 340 MockStreamListenSocket(StreamListenSocket::Delegate* delegate)
331 : StreamListenSocket(kInvalidSocket, delegate) {} 341 : StreamListenSocket(kInvalidSocket, delegate) {}
332 342
333 virtual void Accept() OVERRIDE { NOTREACHED(); } 343 virtual void Accept() OVERRIDE { NOTREACHED(); }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 403
394 ASSERT_EQ(client_connection_id, GetConnectionId(2)); 404 ASSERT_EQ(client_connection_id, GetConnectionId(2));
395 server_->Send200(client_connection_id, "Content for /test3", "text/plain"); 405 server_->Send200(client_connection_id, "Content for /test3", "text/plain");
396 std::string response3; 406 std::string response3;
397 ASSERT_TRUE(client.Read(&response3)); 407 ASSERT_TRUE(client.Read(&response3));
398 ASSERT_TRUE(StartsWithASCII(response3, "HTTP/1.1 200 OK", true)); 408 ASSERT_TRUE(StartsWithASCII(response3, "HTTP/1.1 200 OK", true));
399 ASSERT_TRUE(EndsWith(response3, "Content for /test3", true)); 409 ASSERT_TRUE(EndsWith(response3, "Content for /test3", true));
400 } 410 }
401 411
402 } // namespace net 412 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698