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

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 8745007: Revert 112130 - Close idle connections / SPDY sessions when needed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years 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 | « no previous file | net/http/http_proxy_client_socket_pool.h » ('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) 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/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <stdarg.h> 8 #include <stdarg.h>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 9624 matching lines...) Expand 10 before | Expand all | Expand 10 after
9635 data_writes2, arraysize(data_writes2)); 9635 data_writes2, arraysize(data_writes2));
9636 StaticSocketDataProvider* data[] = { &data1, &data2 }; 9636 StaticSocketDataProvider* data[] = { &data1, &data2 };
9637 9637
9638 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); 9638 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data));
9639 9639
9640 EXPECT_EQ(OK, out.rv); 9640 EXPECT_EQ(OK, out.rv);
9641 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); 9641 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line);
9642 EXPECT_EQ("hello world", out.response_data); 9642 EXPECT_EQ("hello world", out.response_data);
9643 } 9643 }
9644 9644
9645 TEST_F(HttpNetworkTransactionTest, CloseOldSpdySessionToOpenNewOne) {
9646 HttpStreamFactory::set_next_protos(SpdyNextProtos());
9647 int old_max_sockets_per_group =
9648 ClientSocketPoolManager::max_sockets_per_group();
9649 int old_max_sockets_per_proxy_server =
9650 ClientSocketPoolManager::max_sockets_per_proxy_server();
9651 int old_max_sockets_per_pool =
9652 ClientSocketPoolManager::max_sockets_per_pool();
9653 ClientSocketPoolManager::set_max_sockets_per_group(1);
9654 ClientSocketPoolManager::set_max_sockets_per_proxy_server(1);
9655 ClientSocketPoolManager::set_max_sockets_per_pool(1);
9656
9657 // Use two different hosts with different IPs so they don't get pooled.
9658 SessionDependencies session_deps;
9659 session_deps.host_resolver->rules()->AddRule("a.com", "10.0.0.1");
9660 session_deps.host_resolver->rules()->AddRule("b.com", "10.0.0.2");
9661 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
9662
9663 SSLSocketDataProvider ssl1(true, OK);
9664 ssl1.next_proto_status = SSLClientSocket::kNextProtoNegotiated;
9665 ssl1.next_proto = "spdy/2";
9666 ssl1.was_npn_negotiated = true;
9667 SSLSocketDataProvider ssl2(true, OK);
9668 ssl2.next_proto_status = SSLClientSocket::kNextProtoNegotiated;
9669 ssl2.next_proto = "spdy/2";
9670 ssl2.was_npn_negotiated = true;
9671 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl1);
9672 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl2);
9673
9674 scoped_ptr<spdy::SpdyFrame> host1_req(ConstructSpdyGet(
9675 "https://www.a.com", false, 1, LOWEST));
9676 MockWrite spdy1_writes[] = {
9677 CreateMockWrite(*host1_req, 1),
9678 };
9679 scoped_ptr<spdy::SpdyFrame> host1_resp(ConstructSpdyGetSynReply(NULL, 0, 1));
9680 scoped_ptr<spdy::SpdyFrame> host1_resp_body(ConstructSpdyBodyFrame(1, true));
9681 MockRead spdy1_reads[] = {
9682 CreateMockRead(*host1_resp, 2),
9683 CreateMockRead(*host1_resp_body, 3),
9684 MockRead(true, ERR_IO_PENDING, 4),
9685 };
9686
9687 scoped_refptr<OrderedSocketData> spdy1_data(
9688 new OrderedSocketData(
9689 spdy1_reads, arraysize(spdy1_reads),
9690 spdy1_writes, arraysize(spdy1_writes)));
9691 session_deps.socket_factory.AddSocketDataProvider(spdy1_data);
9692
9693 scoped_ptr<spdy::SpdyFrame> host2_req(ConstructSpdyGet(
9694 "https://www.b.com", false, 1, LOWEST));
9695 MockWrite spdy2_writes[] = {
9696 CreateMockWrite(*host2_req, 1),
9697 };
9698 scoped_ptr<spdy::SpdyFrame> host2_resp(ConstructSpdyGetSynReply(NULL, 0, 1));
9699 scoped_ptr<spdy::SpdyFrame> host2_resp_body(ConstructSpdyBodyFrame(1, true));
9700 MockRead spdy2_reads[] = {
9701 CreateMockRead(*host2_resp, 2),
9702 CreateMockRead(*host2_resp_body, 3),
9703 MockRead(true, ERR_IO_PENDING, 4),
9704 };
9705
9706 scoped_refptr<OrderedSocketData> spdy2_data(
9707 new OrderedSocketData(
9708 spdy2_reads, arraysize(spdy2_reads),
9709 spdy2_writes, arraysize(spdy2_writes)));
9710 session_deps.socket_factory.AddSocketDataProvider(spdy2_data);
9711
9712 MockWrite http_write[] = {
9713 MockWrite("GET / HTTP/1.1\r\n"
9714 "Host: www.a.com\r\n"
9715 "Connection: keep-alive\r\n\r\n"),
9716 };
9717
9718 MockRead http_read[] = {
9719 MockRead("HTTP/1.1 200 OK\r\n"),
9720 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
9721 MockRead("Content-Length: 6\r\n\r\n"),
9722 MockRead("hello!"),
9723 };
9724
9725 StaticSocketDataProvider http_data(http_read, arraysize(http_read),
9726 http_write, arraysize(http_write));
9727 session_deps.socket_factory.AddSocketDataProvider(&http_data);
9728
9729 HostPortPair host_port_pair_a("www.a.com", 443);
9730 HostPortProxyPair host_port_proxy_pair_a(
9731 host_port_pair_a, ProxyServer::Direct());
9732 EXPECT_FALSE(
9733 session->spdy_session_pool()->HasSession(host_port_proxy_pair_a));
9734
9735 TestOldCompletionCallback callback;
9736 HttpRequestInfo request1;
9737 request1.method = "GET";
9738 request1.url = GURL("https://www.a.com/");
9739 request1.load_flags = 0;
9740 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
9741
9742 int rv = trans->Start(&request1, &callback, BoundNetLog());
9743 EXPECT_EQ(ERR_IO_PENDING, rv);
9744 EXPECT_EQ(OK, callback.WaitForResult());
9745
9746 const HttpResponseInfo* response = trans->GetResponseInfo();
9747 ASSERT_TRUE(response != NULL);
9748 ASSERT_TRUE(response->headers != NULL);
9749 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9750 EXPECT_TRUE(response->was_fetched_via_spdy);
9751 EXPECT_TRUE(response->was_npn_negotiated);
9752
9753 std::string response_data;
9754 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9755 EXPECT_EQ("hello!", response_data);
9756 trans.reset();
9757 EXPECT_TRUE(
9758 session->spdy_session_pool()->HasSession(host_port_proxy_pair_a));
9759
9760 HostPortPair host_port_pair_b("www.b.com", 443);
9761 HostPortProxyPair host_port_proxy_pair_b(
9762 host_port_pair_b, ProxyServer::Direct());
9763 EXPECT_FALSE(
9764 session->spdy_session_pool()->HasSession(host_port_proxy_pair_b));
9765 HttpRequestInfo request2;
9766 request2.method = "GET";
9767 request2.url = GURL("https://www.b.com/");
9768 request2.load_flags = 0;
9769 trans.reset(new HttpNetworkTransaction(session));
9770
9771 rv = trans->Start(&request2, &callback, BoundNetLog());
9772 EXPECT_EQ(ERR_IO_PENDING, rv);
9773 EXPECT_EQ(OK, callback.WaitForResult());
9774
9775 response = trans->GetResponseInfo();
9776 ASSERT_TRUE(response != NULL);
9777 ASSERT_TRUE(response->headers != NULL);
9778 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9779 EXPECT_TRUE(response->was_fetched_via_spdy);
9780 EXPECT_TRUE(response->was_npn_negotiated);
9781 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9782 EXPECT_EQ("hello!", response_data);
9783 EXPECT_FALSE(
9784 session->spdy_session_pool()->HasSession(host_port_proxy_pair_a));
9785 EXPECT_TRUE(
9786 session->spdy_session_pool()->HasSession(host_port_proxy_pair_b));
9787
9788 HostPortPair host_port_pair_a1("www.a.com", 80);
9789 HostPortProxyPair host_port_proxy_pair_a1(
9790 host_port_pair_a1, ProxyServer::Direct());
9791 EXPECT_FALSE(
9792 session->spdy_session_pool()->HasSession(host_port_proxy_pair_a1));
9793 HttpRequestInfo request3;
9794 request3.method = "GET";
9795 request3.url = GURL("http://www.a.com/");
9796 request3.load_flags = 0;
9797 trans.reset(new HttpNetworkTransaction(session));
9798
9799 rv = trans->Start(&request3, &callback, BoundNetLog());
9800 EXPECT_EQ(ERR_IO_PENDING, rv);
9801 EXPECT_EQ(OK, callback.WaitForResult());
9802
9803 response = trans->GetResponseInfo();
9804 ASSERT_TRUE(response != NULL);
9805 ASSERT_TRUE(response->headers != NULL);
9806 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9807 EXPECT_FALSE(response->was_fetched_via_spdy);
9808 EXPECT_FALSE(response->was_npn_negotiated);
9809 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9810 EXPECT_EQ("hello!", response_data);
9811 EXPECT_FALSE(
9812 session->spdy_session_pool()->HasSession(host_port_proxy_pair_a));
9813 EXPECT_FALSE(
9814 session->spdy_session_pool()->HasSession(host_port_proxy_pair_b));
9815
9816 HttpStreamFactory::set_next_protos(std::vector<std::string>());
9817 ClientSocketPoolManager::set_max_sockets_per_pool(old_max_sockets_per_pool);
9818 ClientSocketPoolManager::set_max_sockets_per_proxy_server(
9819 old_max_sockets_per_proxy_server);
9820 ClientSocketPoolManager::set_max_sockets_per_group(old_max_sockets_per_group);
9821 }
9822
9823 } // namespace net 9645 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_proxy_client_socket_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698