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

Side by Side Diff: net/spdy/spdy_session_unittest.cc

Issue 7349023: Changed SPDY's ip connection pooling logic to only add the used IP, (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' 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/spdy/spdy_session.h" 5 #include "net/spdy/spdy_session.h"
6 6
7 #include "net/base/sys_addrinfo.h"
7 #include "net/spdy/spdy_io_buffer.h" 8 #include "net/spdy/spdy_io_buffer.h"
8 #include "net/spdy/spdy_session_pool.h" 9 #include "net/spdy/spdy_session_pool.h"
9 #include "net/spdy/spdy_stream.h" 10 #include "net/spdy/spdy_stream.h"
10 #include "net/spdy/spdy_test_util.h" 11 #include "net/spdy/spdy_test_util.h"
11 #include "testing/platform_test.h" 12 #include "testing/platform_test.h"
12 13
13 namespace net { 14 namespace net {
14 15
15 // TODO(cbentzel): Expose compression setter/getter in public SpdySession 16 // TODO(cbentzel): Expose compression setter/getter in public SpdySession
16 // interface rather than going through all these contortions. 17 // interface rather than going through all these contortions.
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 // This test has two variants, one for each style of closing the connection. 410 // This test has two variants, one for each style of closing the connection.
410 // If |clean_via_close_current_sessions| is false, the sessions are closed 411 // If |clean_via_close_current_sessions| is false, the sessions are closed
411 // manually, calling SpdySessionPool::Remove() directly. If it is true, 412 // manually, calling SpdySessionPool::Remove() directly. If it is true,
412 // sessions are closed with SpdySessionPool::CloseCurrentSessions(). 413 // sessions are closed with SpdySessionPool::CloseCurrentSessions().
413 void IPPoolingTest(bool clean_via_close_current_sessions) { 414 void IPPoolingTest(bool clean_via_close_current_sessions) {
414 const int kTestPort = 80; 415 const int kTestPort = 80;
415 struct TestHosts { 416 struct TestHosts {
416 std::string name; 417 std::string name;
417 std::string iplist; 418 std::string iplist;
418 HostPortProxyPair pair; 419 HostPortProxyPair pair;
420 AddressList addresses;
419 } test_hosts[] = { 421 } test_hosts[] = {
420 { "www.foo.com", "192.168.0.1,192.168.0.5" }, 422 { "www.foo.com", "192.0.2.33,192.168.0.1,192.168.0.5" },
421 { "images.foo.com", "192.168.0.2,192.168.0.3,192.168.0.5" }, 423 { "images.foo.com", "192.168.0.2,192.168.0.3,192.168.0.5,192.0.2.33" },
422 { "js.foo.com", "192.168.0.4,192.168.0.3" }, 424 { "js.foo.com", "192.168.0.4,192.168.0.3" },
423 }; 425 };
424 426
425 SpdySessionDependencies session_deps; 427 SpdySessionDependencies session_deps;
426 session_deps.host_resolver->set_synchronous_mode(true); 428 session_deps.host_resolver->set_synchronous_mode(true);
427 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) { 429 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) {
428 session_deps.host_resolver->rules()->AddIPLiteralRule(test_hosts[i].name, 430 session_deps.host_resolver->rules()->AddIPLiteralRule(test_hosts[i].name,
429 test_hosts[i].iplist, ""); 431 test_hosts[i].iplist, "");
430 432
431 // This test requires that the HostResolver cache be populated. Normal 433 // This test requires that the HostResolver cache be populated. Normal
432 // code would have done this already, but we do it manually. 434 // code would have done this already, but we do it manually.
433 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); 435 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort));
434 AddressList result;
435 session_deps.host_resolver->Resolve( 436 session_deps.host_resolver->Resolve(
436 info, &result, NULL, NULL, BoundNetLog()); 437 info, &test_hosts[i].addresses, NULL, NULL, BoundNetLog());
437 438
438 // Setup a HostPortProxyPair 439 // Setup a HostPortProxyPair
439 test_hosts[i].pair = HostPortProxyPair( 440 test_hosts[i].pair = HostPortProxyPair(
440 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct()); 441 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct());
441 } 442 }
442 443
443 MockConnect connect_data(false, OK); 444 MockConnect connect_data(false, OK);
444 MockRead reads[] = { 445 MockRead reads[] = {
445 MockRead(false, ERR_IO_PENDING) // Stall forever. 446 MockRead(false, ERR_IO_PENDING) // Stall forever.
446 }; 447 };
(...skipping 23 matching lines...) Expand all
470 false, 471 false,
471 false)); 472 false));
472 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); 473 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
473 EXPECT_EQ(OK, 474 EXPECT_EQ(OK,
474 connection->Init(test_host_port_pair.ToString(), 475 connection->Init(test_host_port_pair.ToString(),
475 transport_params, MEDIUM, 476 transport_params, MEDIUM,
476 NULL, http_session->transport_socket_pool(), 477 NULL, http_session->transport_socket_pool(),
477 BoundNetLog())); 478 BoundNetLog()));
478 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); 479 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK));
479 480
481 // TODO(rtenneti): MockClientSocket::GetPeerAddress return's 0 as the port
482 // number. Fix it to return port 80 and then use GetPeerAddress to AddAlias.
483 const addrinfo* address = test_hosts[0].addresses.head();
484 DCHECK(address);
485 IPEndPoint endpoint;
486 endpoint.FromSockAddr(address->ai_addr, address->ai_addrlen);
487 SpdySessionPoolPeer pool_peer(spdy_session_pool);
488 pool_peer.AddAlias(endpoint, test_hosts[0].pair);
489
480 // Flush the SpdySession::OnReadComplete() task. 490 // Flush the SpdySession::OnReadComplete() task.
481 MessageLoop::current()->RunAllPending(); 491 MessageLoop::current()->RunAllPending();
482 492
483 // The third host has no overlap with the first, so it can't pool IPs. 493 // The third host has no overlap with the first, so it can't pool IPs.
484 EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].pair)); 494 EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].pair));
485 495
486 // The second host overlaps with the first, and should IP pool. 496 // The second host overlaps with the first, and should IP pool.
487 EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair)); 497 EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair));
488 498
489 // Verify that the second host, through a proxy, won't share the IP. 499 // Verify that the second host, through a proxy, won't share the IP.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 576
567 test_settings_storage->Set(test_host_port_pair, test_settings); 577 test_settings_storage->Set(test_host_port_pair, test_settings);
568 EXPECT_NE(0u, test_settings_storage->Get(test_host_port_pair).size()); 578 EXPECT_NE(0u, test_settings_storage->Get(test_host_port_pair).size());
569 spdy_session_pool->OnIPAddressChanged(); 579 spdy_session_pool->OnIPAddressChanged();
570 EXPECT_EQ(0u, test_settings_storage->Get(test_host_port_pair).size()); 580 EXPECT_EQ(0u, test_settings_storage->Get(test_host_port_pair).size());
571 } 581 }
572 582
573 } // namespace 583 } // namespace
574 584
575 } // namespace net 585 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698