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

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

Issue 9667016: Close idle connections / SPDY sessions when needed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename test to CloseIdleSpdySessionToOpenNewOne Created 8 years, 9 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/host_cache.h" 7 #include "net/base/host_cache.h"
8 #include "net/base/ip_endpoint.h" 8 #include "net/base/ip_endpoint.h"
9 #include "net/base/net_log_unittest.h" 9 #include "net/base/net_log_unittest.h"
10 #include "net/spdy/spdy_io_buffer.h" 10 #include "net/spdy/spdy_io_buffer.h"
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 net::NetLog::TYPE_SPDY_SESSION_CLOSE, 1135 net::NetLog::TYPE_SPDY_SESSION_CLOSE,
1136 net::NetLog::PHASE_NONE); 1136 net::NetLog::PHASE_NONE);
1137 1137
1138 CapturingNetLog::Entry entry = entries[pos]; 1138 CapturingNetLog::Entry entry = entries[pos];
1139 NetLogSpdySessionCloseParameter* request_params = 1139 NetLogSpdySessionCloseParameter* request_params =
1140 static_cast<NetLogSpdySessionCloseParameter*>( 1140 static_cast<NetLogSpdySessionCloseParameter*>(
1141 entry.extra_parameters.get()); 1141 entry.extra_parameters.get());
1142 EXPECT_EQ(ERR_CONNECTION_CLOSED, request_params->status()); 1142 EXPECT_EQ(ERR_CONNECTION_CLOSED, request_params->status());
1143 } 1143 }
1144 1144
1145 TEST_F(SpdySessionSpdy3Test, CloseOneIdleConnection) {
1146 MockHostResolver host_resolver;
1147 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1148 ClientSocketPoolHistograms tcp_histograms("");
1149 MockClientSocketFactory socket_factory;
1150 MockConnect connect_data(SYNCHRONOUS, OK);
1151 MockRead reads[] = {
1152 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever.
1153 };
1154 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
1155 data.set_connect_data(connect_data);
1156 socket_factory.AddSocketDataProvider(&data);
1157 socket_factory.AddSocketDataProvider(&data);
1158 socket_factory.AddSocketDataProvider(&data);
1159 socket_factory.AddSocketDataProvider(&data);
1160 socket_factory.AddSocketDataProvider(&data);
1161 socket_factory.AddSocketDataProvider(&data);
1162 TransportClientSocketPool pool(
1163 3, 2,
1164 &tcp_histograms,
1165 &host_resolver,
1166 &socket_factory, NULL);
1167 // Now if I check out 1 socket from 3 different groups, the next request
1168 // will leave us stalled.
1169
1170 TestCompletionCallback callback1;
1171 HostPortPair host_port1("1.com", 80);
1172 scoped_refptr<TransportSocketParams> params1(
1173 new TransportSocketParams(host_port1, MEDIUM, false, false));
1174 scoped_ptr<ClientSocketHandle> connection1(new ClientSocketHandle);
1175 EXPECT_EQ(ERR_IO_PENDING,
1176 connection1->Init(host_port1.ToString(), params1, MEDIUM,
1177 callback1.callback(), &pool, log.bound()));
1178 EXPECT_EQ(OK, callback1.WaitForResult());
1179 EXPECT_FALSE(pool.IsStalled());
1180 EXPECT_TRUE(connection1->is_initialized());
1181 EXPECT_TRUE(connection1->socket());
1182
1183 TestCompletionCallback callback2;
1184 HostPortPair host_port2("2.com", 80);
1185 scoped_refptr<TransportSocketParams> params2(
1186 new TransportSocketParams(host_port2, MEDIUM, false, false));
1187 scoped_ptr<ClientSocketHandle> connection2(new ClientSocketHandle);
1188 EXPECT_EQ(ERR_IO_PENDING,
1189 connection2->Init(host_port2.ToString(), params2, MEDIUM,
1190 callback2.callback(), &pool, log.bound()));
1191 EXPECT_EQ(OK, callback2.WaitForResult());
1192 EXPECT_FALSE(pool.IsStalled());
1193
1194 TestCompletionCallback callback3;
1195 HostPortPair host_port3("3.com", 80);
1196 scoped_refptr<TransportSocketParams> params3(
1197 new TransportSocketParams(host_port3, MEDIUM, false, false));
1198 scoped_ptr<ClientSocketHandle> connection3(new ClientSocketHandle);
1199 EXPECT_EQ(ERR_IO_PENDING,
1200 connection3->Init(host_port3.ToString(), params3, MEDIUM,
1201 callback3.callback(), &pool, log.bound()));
1202 EXPECT_EQ(OK, callback3.WaitForResult());
1203 EXPECT_FALSE(pool.IsStalled());
1204
1205 TestCompletionCallback callback4;
1206 HostPortPair host_port4("4.com", 80);
1207 scoped_refptr<TransportSocketParams> params4(
1208 new TransportSocketParams(host_port4, MEDIUM, false, false));
1209 scoped_ptr<ClientSocketHandle> connection4(new ClientSocketHandle);
1210 EXPECT_EQ(ERR_IO_PENDING,
1211 connection4->Init(host_port4.ToString(), params4, MEDIUM,
1212 callback4.callback(), &pool, log.bound()));
1213 EXPECT_TRUE(pool.IsStalled());
1214
1215 // Return 1 socket to the pool so that we are no longer stalled
1216 connection3->socket()->Disconnect();
1217 connection3->Reset();
1218 EXPECT_EQ(OK, callback4.WaitForResult());
1219 EXPECT_FALSE(pool.IsStalled());
1220
1221 // Now, wrap one of the sockets in a SpdySession
1222 HttpServerPropertiesImpl props;
1223 SpdySessionPool spdy_session_pool(&host_resolver, NULL, &props);
1224 HostPortProxyPair pair1(host_port1, ProxyServer::Direct());
1225 EXPECT_FALSE(spdy_session_pool.HasSession(pair1));
1226 scoped_refptr<SpdySession> session1 =
1227 spdy_session_pool.Get(pair1, log.bound());
1228 EXPECT_TRUE(spdy_session_pool.HasSession(pair1));
1229 EXPECT_EQ(OK,
1230 session1->InitializeWithSocket(connection1.release(), false, OK));
1231 session1 = NULL;
1232 EXPECT_TRUE(spdy_session_pool.HasSession(pair1));
1233
1234 // The SpdySession is now idle. When we request the next socket from the
1235 // transport pool, the session will be closed via CloseOneIdleConnection().
1236 TestCompletionCallback callback5;
1237 HostPortPair host_port5("5.com", 80);
1238 scoped_refptr<TransportSocketParams> params5(
1239 new TransportSocketParams(host_port5, MEDIUM, false, false));
1240 scoped_ptr<ClientSocketHandle> connection5(new ClientSocketHandle);
1241 EXPECT_EQ(ERR_IO_PENDING,
1242 connection5->Init(host_port5.ToString(), params5, MEDIUM,
1243 callback5.callback(), &pool, log.bound()));
1244 EXPECT_FALSE(pool.IsStalled());
1245 EXPECT_EQ(OK, callback5.WaitForResult());
1246 EXPECT_FALSE(spdy_session_pool.HasSession(pair1));
1247 EXPECT_FALSE(pool.IsStalled());
1248
1249 // Now, wrap one of the sockets in a SpdySession
1250 HostPortProxyPair pair2(host_port2, ProxyServer::Direct());
1251 EXPECT_FALSE(spdy_session_pool.HasSession(pair2));
1252 scoped_refptr<SpdySession> session2 =
1253 spdy_session_pool.Get(pair2, log.bound());
1254 EXPECT_TRUE(spdy_session_pool.HasSession(pair2));
1255 EXPECT_EQ(OK,
1256 session2->InitializeWithSocket(connection2.release(), false, OK));
1257
1258 // Manually remove the socket from the pool. This does *not* return the
1259 // transport socket. It will be returned only when the SpdySession is
1260 // destructed.
1261 session2->RemoveFromPool();
1262 EXPECT_FALSE(spdy_session_pool.HasSession(pair2));
1263
1264 // Although there are no active streams on the session, the pool does not
1265 // hold a reference. This means that CloseOneIdleConnection should not
1266 // return true, and this request should stall.
1267 TestCompletionCallback callback6;
1268 HostPortPair host_port6("6.com", 80);
1269 scoped_refptr<TransportSocketParams> params6(
1270 new TransportSocketParams(host_port5, MEDIUM, false, false));
1271 scoped_ptr<ClientSocketHandle> connection6(new ClientSocketHandle);
1272 EXPECT_EQ(ERR_IO_PENDING,
1273 connection6->Init(host_port6.ToString(), params6, MEDIUM,
1274 callback6.callback(), &pool, log.bound()));
1275 EXPECT_TRUE(pool.IsStalled());
1276
1277 // But now if we drop our reference to the session, it will be destructed
1278 // and the transport socket will return to the pool, unblocking this
1279 // request.
1280 session2 = NULL;
1281 EXPECT_EQ(OK, callback6.WaitForResult());
1282 EXPECT_FALSE(pool.IsStalled());
1283 }
1284
1145 } // namespace net 1285 } // namespace net
OLDNEW
« net/socket/client_socket_pool_base_unittest.cc ('K') | « net/spdy/spdy_session_spdy2_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698