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

Side by Side Diff: net/socket/transport_client_socket_unittest.cc

Issue 7251004: Deciding best connection to schedule requests on based on cwnd and idle time (Reopened after revert) (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Syncing to head Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/socket/tcp_client_socket.h" 5 #include "net/socket/tcp_client_socket.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "net/base/address_list.h" 8 #include "net/base/address_list.h"
9 #include "net/base/host_resolver.h" 9 #include "net/base/host_resolver.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); 270 scoped_refptr<IOBuffer> buf(new IOBuffer(4096));
271 uint32 bytes_read = DrainClientSocket(buf, 4096, arraysize(kServerReply) - 1, 271 uint32 bytes_read = DrainClientSocket(buf, 4096, arraysize(kServerReply) - 1,
272 &callback); 272 &callback);
273 ASSERT_EQ(bytes_read, arraysize(kServerReply) - 1); 273 ASSERT_EQ(bytes_read, arraysize(kServerReply) - 1);
274 274
275 // All data has been read now. Read once more to force an ERR_IO_PENDING, and 275 // All data has been read now. Read once more to force an ERR_IO_PENDING, and
276 // then close the server socket, and note the close. 276 // then close the server socket, and note the close.
277 277
278 rv = sock_->Read(buf, 4096, &callback); 278 rv = sock_->Read(buf, 4096, &callback);
279 ASSERT_EQ(ERR_IO_PENDING, rv); 279 ASSERT_EQ(ERR_IO_PENDING, rv);
280 EXPECT_EQ(static_cast<int64>(std::string(kServerReply).size()),
281 sock_->NumBytesRead());
280 CloseServerSocket(); 282 CloseServerSocket();
281 EXPECT_EQ(0, callback.WaitForResult()); 283 EXPECT_EQ(0, callback.WaitForResult());
282 } 284 }
283 285
284 TEST_P(TransportClientSocketTest, Read_SmallChunks) { 286 TEST_P(TransportClientSocketTest, Read_SmallChunks) {
285 TestCompletionCallback callback; 287 TestCompletionCallback callback;
286 int rv = sock_->Connect(&callback); 288 int rv = sock_->Connect(&callback);
287 if (rv != OK) { 289 if (rv != OK) {
288 ASSERT_EQ(rv, ERR_IO_PENDING); 290 ASSERT_EQ(rv, ERR_IO_PENDING);
289 291
(...skipping 12 matching lines...) Expand all
302 rv = callback.WaitForResult(); 304 rv = callback.WaitForResult();
303 305
304 ASSERT_EQ(1, rv); 306 ASSERT_EQ(1, rv);
305 bytes_read += rv; 307 bytes_read += rv;
306 } 308 }
307 309
308 // All data has been read now. Read once more to force an ERR_IO_PENDING, and 310 // All data has been read now. Read once more to force an ERR_IO_PENDING, and
309 // then close the server socket, and note the close. 311 // then close the server socket, and note the close.
310 312
311 rv = sock_->Read(buf, 1, &callback); 313 rv = sock_->Read(buf, 1, &callback);
314 EXPECT_EQ(static_cast<int64>(std::string(kServerReply).size()),
315 sock_->NumBytesRead());
312 ASSERT_EQ(ERR_IO_PENDING, rv); 316 ASSERT_EQ(ERR_IO_PENDING, rv);
313 CloseServerSocket(); 317 CloseServerSocket();
314 EXPECT_EQ(0, callback.WaitForResult()); 318 EXPECT_EQ(0, callback.WaitForResult());
315 } 319 }
316 320
317 TEST_P(TransportClientSocketTest, Read_Interrupted) { 321 TEST_P(TransportClientSocketTest, Read_Interrupted) {
318 TestCompletionCallback callback; 322 TestCompletionCallback callback;
319 int rv = sock_->Connect(&callback); 323 int rv = sock_->Connect(&callback);
320 if (rv != OK) { 324 if (rv != OK) {
321 ASSERT_EQ(ERR_IO_PENDING, rv); 325 ASSERT_EQ(ERR_IO_PENDING, rv);
322 326
323 rv = callback.WaitForResult(); 327 rv = callback.WaitForResult();
324 EXPECT_EQ(rv, OK); 328 EXPECT_EQ(rv, OK);
325 } 329 }
326 SendClientRequest(); 330 SendClientRequest();
327 331
328 // Do a partial read and then exit. This test should not crash! 332 // Do a partial read and then exit. This test should not crash!
329 scoped_refptr<IOBuffer> buf(new IOBuffer(16)); 333 scoped_refptr<IOBuffer> buf(new IOBuffer(16));
330 rv = sock_->Read(buf, 16, &callback); 334 rv = sock_->Read(buf, 16, &callback);
331 EXPECT_TRUE(rv >= 0 || rv == ERR_IO_PENDING); 335 EXPECT_TRUE(rv >= 0 || rv == ERR_IO_PENDING);
336 EXPECT_EQ(0, sock_->NumBytesRead());
332 337
333 if (rv == ERR_IO_PENDING) 338 if (rv == ERR_IO_PENDING) {
334 rv = callback.WaitForResult(); 339 rv = callback.WaitForResult();
340 EXPECT_EQ(16, sock_->NumBytesRead());
341 }
335 342
336 EXPECT_NE(0, rv); 343 EXPECT_NE(0, rv);
337 } 344 }
338 345
339 TEST_P(TransportClientSocketTest, DISABLED_FullDuplex_ReadFirst) { 346 TEST_P(TransportClientSocketTest, DISABLED_FullDuplex_ReadFirst) {
340 TestCompletionCallback callback; 347 TestCompletionCallback callback;
341 int rv = sock_->Connect(&callback); 348 int rv = sock_->Connect(&callback);
342 if (rv != OK) { 349 if (rv != OK) {
343 ASSERT_EQ(rv, ERR_IO_PENDING); 350 ASSERT_EQ(rv, ERR_IO_PENDING);
344 351
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 // Close the server socket, so there will at least be a 0-byte read. 434 // Close the server socket, so there will at least be a 0-byte read.
428 CloseServerSocket(); 435 CloseServerSocket();
429 436
430 rv = callback.WaitForResult(); 437 rv = callback.WaitForResult();
431 EXPECT_GE(rv, 0); 438 EXPECT_GE(rv, 0);
432 } 439 }
433 440
434 } // namespace 441 } // namespace
435 442
436 } // namespace net 443 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698