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

Unified Diff: net/http/http_network_transaction_unittest.cc

Issue 18796003: When an idle socket is added back to a socket pool, check for stalled jobs in lower pools (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Response to comments Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/http/http_proxy_client_socket_pool.h » ('j') | net/spdy/spdy_session.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_network_transaction_unittest.cc
===================================================================
--- net/http/http_network_transaction_unittest.cc (revision 218769)
+++ net/http/http_network_transaction_unittest.cc (working copy)
@@ -95,6 +95,11 @@
net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount();
}
+bool IsTransportSocketPoolStalled(net::HttpNetworkSession* session) {
+ return session->GetTransportSocketPool(
+ net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IsStalled();
+}
+
// Takes in a Value created from a NetLogHttpResponseParameter, and returns
// a JSONified list of headers as a single string. Uses single quotes instead
// of double quotes for easier comparison. Returns false on failure.
@@ -12003,4 +12008,168 @@
EXPECT_EQ(LOWEST, fake_stream->priority());
}
+// Tests that when a used socket is returned to the SSL socket pool, it's closed
+// if the transport socket pool is stalled on the global socket limit.
+TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) {
+ ClientSocketPoolManager::set_max_sockets_per_group(
+ HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
+ ClientSocketPoolManager::set_max_sockets_per_pool(
+ HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
+
+ // Set up SSL request.
+
+ HttpRequestInfo ssl_request;
+ ssl_request.method = "GET";
+ ssl_request.url = GURL("https://www.google.com/");
+
+ MockWrite ssl_writes[] = {
+ MockWrite("GET / HTTP/1.1\r\n"
+ "Host: www.google.com\r\n"
+ "Connection: keep-alive\r\n\r\n"),
+ };
+ MockRead ssl_reads[] = {
+ MockRead("HTTP/1.1 200 OK\r\n"),
+ MockRead("Content-Length: 11\r\n\r\n"),
+ MockRead("hello world"),
+ MockRead(SYNCHRONOUS, OK),
+ };
+ StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads),
+ ssl_writes, arraysize(ssl_writes));
+ session_deps_.socket_factory->AddSocketDataProvider(&ssl_data);
+
+ SSLSocketDataProvider ssl(ASYNC, OK);
+ session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
+
+ // Set up HTTP request.
+
+ HttpRequestInfo http_request;
+ http_request.method = "GET";
+ http_request.url = GURL("http://www.google.com/");
+
+ MockWrite http_writes[] = {
+ MockWrite("GET / HTTP/1.1\r\n"
+ "Host: www.google.com\r\n"
+ "Connection: keep-alive\r\n\r\n"),
+ };
+ MockRead http_reads[] = {
+ MockRead("HTTP/1.1 200 OK\r\n"),
+ MockRead("Content-Length: 7\r\n\r\n"),
+ MockRead("falafel"),
+ MockRead(SYNCHRONOUS, OK),
+ };
+ StaticSocketDataProvider http_data(http_reads, arraysize(http_reads),
+ http_writes, arraysize(http_writes));
+ session_deps_.socket_factory->AddSocketDataProvider(&http_data);
+
+ scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
+
+ // Start the SSL request.
+ TestCompletionCallback ssl_callback;
+ scoped_ptr<HttpTransaction> ssl_trans(
+ new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
+ ASSERT_EQ(ERR_IO_PENDING,
+ ssl_trans->Start(&ssl_request, ssl_callback.callback(),
+ BoundNetLog()));
+
+ // Start the HTTP request. Pool should stall.
+ TestCompletionCallback http_callback;
+ scoped_ptr<HttpTransaction> http_trans(
+ new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
+ ASSERT_EQ(ERR_IO_PENDING,
+ http_trans->Start(&http_request, http_callback.callback(),
+ BoundNetLog()));
+ EXPECT_TRUE(IsTransportSocketPoolStalled(session));
+
+ // Wait for response from SSL request.
+ ASSERT_EQ(OK, ssl_callback.WaitForResult());
+ std::string response_data;
+ ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data));
+ EXPECT_EQ("hello world", response_data);
+
+ // The SSL socket should automatically be closed, so the HTTP request can
+ // start.
+ EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session));
+ ASSERT_FALSE(IsTransportSocketPoolStalled(session));
+
+ // The HTTP request can now complete.
+ ASSERT_EQ(OK, http_callback.WaitForResult());
+ ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data));
+ EXPECT_EQ("falafel", response_data);
+
+ EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session));
+}
+
+// Tests that when a SSL connection is established but there's no corresponding
+// request that needs it, the new socket is closed if the transport socket pool
+// is stalled on the global socket limit.
+TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) {
+ ClientSocketPoolManager::set_max_sockets_per_group(
+ HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
+ ClientSocketPoolManager::set_max_sockets_per_pool(
+ HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
+
+ // Set up an ssl request.
+
+ HttpRequestInfo ssl_request;
+ ssl_request.method = "GET";
+ ssl_request.url = GURL("https://www.foopy.com/");
+
+ // No data will be sent on the SSL socket.
+ StaticSocketDataProvider ssl_data;
+ session_deps_.socket_factory->AddSocketDataProvider(&ssl_data);
+
+ SSLSocketDataProvider ssl(ASYNC, OK);
+ session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
+
+ // Set up HTTP request.
+
+ HttpRequestInfo http_request;
+ http_request.method = "GET";
+ http_request.url = GURL("http://www.google.com/");
+
+ MockWrite http_writes[] = {
+ MockWrite("GET / HTTP/1.1\r\n"
+ "Host: www.google.com\r\n"
+ "Connection: keep-alive\r\n\r\n"),
+ };
+ MockRead http_reads[] = {
+ MockRead("HTTP/1.1 200 OK\r\n"),
+ MockRead("Content-Length: 7\r\n\r\n"),
+ MockRead("falafel"),
+ MockRead(SYNCHRONOUS, OK),
+ };
+ StaticSocketDataProvider http_data(http_reads, arraysize(http_reads),
+ http_writes, arraysize(http_writes));
+ session_deps_.socket_factory->AddSocketDataProvider(&http_data);
+
+ scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
+
+ // Preconnect an SSL socket. A preconnect is needed because connect jobs are
+ // cancelled when a normal transaction is cancelled.
+ net::HttpStreamFactory* http_stream_factory = session->http_stream_factory();
+ net::SSLConfig ssl_config;
+ session->ssl_config_service()->GetSSLConfig(&ssl_config);
+ http_stream_factory->PreconnectStreams(1, ssl_request, DEFAULT_PRIORITY,
+ ssl_config, ssl_config);
+ EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session));
+
+ // Start the HTTP request. Pool should stall.
+ TestCompletionCallback http_callback;
+ scoped_ptr<HttpTransaction> http_trans(
+ new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
+ ASSERT_EQ(ERR_IO_PENDING,
+ http_trans->Start(&http_request, http_callback.callback(),
+ BoundNetLog()));
+ EXPECT_TRUE(IsTransportSocketPoolStalled(session));
+
+ // The SSL connection will automatically be closed once the connection is
+ // established, to let the HTTP request start.
+ ASSERT_EQ(OK, http_callback.WaitForResult());
+ std::string response_data;
+ ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data));
+ EXPECT_EQ("falafel", response_data);
+
+ EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session));
+}
+
} // namespace net
« no previous file with comments | « no previous file | net/http/http_proxy_client_socket_pool.h » ('j') | net/spdy/spdy_session.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698