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

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

Issue 9760002: Revert 127717 - Revert 118788 - Revert 113405 - Revert 113305 - Revert 113300 - Revert 112134 - Rev… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | net/spdy/spdy_session_spdy3_unittest.cc » ('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) 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 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 net::NetLog::TYPE_SPDY_SESSION_CLOSE, 1069 net::NetLog::TYPE_SPDY_SESSION_CLOSE,
1070 net::NetLog::PHASE_NONE); 1070 net::NetLog::PHASE_NONE);
1071 1071
1072 CapturingNetLog::Entry entry = entries[pos]; 1072 CapturingNetLog::Entry entry = entries[pos];
1073 NetLogSpdySessionCloseParameter* request_params = 1073 NetLogSpdySessionCloseParameter* request_params =
1074 static_cast<NetLogSpdySessionCloseParameter*>( 1074 static_cast<NetLogSpdySessionCloseParameter*>(
1075 entry.extra_parameters.get()); 1075 entry.extra_parameters.get());
1076 EXPECT_EQ(ERR_CONNECTION_CLOSED, request_params->status()); 1076 EXPECT_EQ(ERR_CONNECTION_CLOSED, request_params->status());
1077 } 1077 }
1078 1078
1079 TEST_F(SpdySessionSpdy2Test, CloseOneIdleConnection) {
1080 MockHostResolver host_resolver;
1081 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1082 ClientSocketPoolHistograms tcp_histograms("");
1083 MockClientSocketFactory socket_factory;
1084 MockConnect connect_data(SYNCHRONOUS, OK);
1085 MockRead reads[] = {
1086 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever.
1087 };
1088 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
1089 data.set_connect_data(connect_data);
1090 socket_factory.AddSocketDataProvider(&data);
1091 socket_factory.AddSocketDataProvider(&data);
1092 socket_factory.AddSocketDataProvider(&data);
1093 socket_factory.AddSocketDataProvider(&data);
1094 socket_factory.AddSocketDataProvider(&data);
1095 socket_factory.AddSocketDataProvider(&data);
1096 TransportClientSocketPool pool(
1097 3, 2,
1098 &tcp_histograms,
1099 &host_resolver,
1100 &socket_factory, NULL);
1101 // Now if I check out 1 socket from 3 different groups, the next request
1102 // will leave us stalled.
1103
1104 TestCompletionCallback callback1;
1105 HostPortPair host_port1("1.com", 80);
1106 scoped_refptr<TransportSocketParams> params1(
1107 new TransportSocketParams(host_port1, MEDIUM, false, false));
1108 scoped_ptr<ClientSocketHandle> connection1(new ClientSocketHandle);
1109 EXPECT_EQ(ERR_IO_PENDING,
1110 connection1->Init(host_port1.ToString(), params1, MEDIUM,
1111 callback1.callback(), &pool, log.bound()));
1112 EXPECT_EQ(OK, callback1.WaitForResult());
1113 EXPECT_FALSE(pool.IsStalled());
1114 EXPECT_TRUE(connection1->is_initialized());
1115 EXPECT_TRUE(connection1->socket());
1116
1117 TestCompletionCallback callback2;
1118 HostPortPair host_port2("2.com", 80);
1119 scoped_refptr<TransportSocketParams> params2(
1120 new TransportSocketParams(host_port2, MEDIUM, false, false));
1121 scoped_ptr<ClientSocketHandle> connection2(new ClientSocketHandle);
1122 EXPECT_EQ(ERR_IO_PENDING,
1123 connection2->Init(host_port2.ToString(), params2, MEDIUM,
1124 callback2.callback(), &pool, log.bound()));
1125 EXPECT_EQ(OK, callback2.WaitForResult());
1126 EXPECT_FALSE(pool.IsStalled());
1127
1128 TestCompletionCallback callback3;
1129 HostPortPair host_port3("3.com", 80);
1130 scoped_refptr<TransportSocketParams> params3(
1131 new TransportSocketParams(host_port3, MEDIUM, false, false));
1132 scoped_ptr<ClientSocketHandle> connection3(new ClientSocketHandle);
1133 EXPECT_EQ(ERR_IO_PENDING,
1134 connection3->Init(host_port3.ToString(), params3, MEDIUM,
1135 callback3.callback(), &pool, log.bound()));
1136 EXPECT_EQ(OK, callback3.WaitForResult());
1137 EXPECT_FALSE(pool.IsStalled());
1138
1139 TestCompletionCallback callback4;
1140 HostPortPair host_port4("4.com", 80);
1141 scoped_refptr<TransportSocketParams> params4(
1142 new TransportSocketParams(host_port4, MEDIUM, false, false));
1143 scoped_ptr<ClientSocketHandle> connection4(new ClientSocketHandle);
1144 EXPECT_EQ(ERR_IO_PENDING,
1145 connection4->Init(host_port4.ToString(), params4, MEDIUM,
1146 callback4.callback(), &pool, log.bound()));
1147 EXPECT_TRUE(pool.IsStalled());
1148
1149 // Return 1 socket to the pool so that we are no longer stalled
1150 connection3->socket()->Disconnect();
1151 connection3->Reset();
1152 EXPECT_EQ(OK, callback4.WaitForResult());
1153 EXPECT_FALSE(pool.IsStalled());
1154
1155 // Now, wrap one of the sockets in a SpdySession
1156 HttpServerPropertiesImpl props;
1157 SpdySessionPool spdy_session_pool(&host_resolver, NULL, &props);
1158 HostPortProxyPair pair1(host_port1, ProxyServer::Direct());
1159 EXPECT_FALSE(spdy_session_pool.HasSession(pair1));
1160 scoped_refptr<SpdySession> session1 =
1161 spdy_session_pool.Get(pair1, log.bound());
1162 EXPECT_TRUE(spdy_session_pool.HasSession(pair1));
1163 EXPECT_EQ(OK,
1164 session1->InitializeWithSocket(connection1.release(), false, OK));
1165 session1 = NULL;
1166 EXPECT_TRUE(spdy_session_pool.HasSession(pair1));
1167
1168 // The SpdySession is now idle. When we request the next socket from the
1169 // transport pool, the session will be closed via CloseOneIdleConnection().
1170 TestCompletionCallback callback5;
1171 HostPortPair host_port5("5.com", 80);
1172 scoped_refptr<TransportSocketParams> params5(
1173 new TransportSocketParams(host_port5, MEDIUM, false, false));
1174 scoped_ptr<ClientSocketHandle> connection5(new ClientSocketHandle);
1175 EXPECT_EQ(ERR_IO_PENDING,
1176 connection5->Init(host_port5.ToString(), params5, MEDIUM,
1177 callback5.callback(), &pool, log.bound()));
1178 EXPECT_FALSE(pool.IsStalled());
1179 EXPECT_EQ(OK, callback5.WaitForResult());
1180 EXPECT_FALSE(spdy_session_pool.HasSession(pair1));
1181 EXPECT_FALSE(pool.IsStalled());
1182
1183 // Now, wrap one of the sockets in a SpdySession
1184 HostPortProxyPair pair2(host_port2, ProxyServer::Direct());
1185 EXPECT_FALSE(spdy_session_pool.HasSession(pair2));
1186 scoped_refptr<SpdySession> session2 =
1187 spdy_session_pool.Get(pair2, log.bound());
1188 EXPECT_TRUE(spdy_session_pool.HasSession(pair2));
1189 EXPECT_EQ(OK,
1190 session2->InitializeWithSocket(connection2.release(), false, OK));
1191
1192 // Manually remove the socket from the pool. This does *not* return the
1193 // transport socket. It will be returned only when the SpdySession is
1194 // destructed.
1195 session2->RemoveFromPool();
1196 EXPECT_FALSE(spdy_session_pool.HasSession(pair2));
1197
1198 // Although there are no active streams on the session, the pool does not
1199 // hold a reference. This means that CloseOneIdleConnection should not
1200 // return true, and this request should stall.
1201 TestCompletionCallback callback6;
1202 HostPortPair host_port6("6.com", 80);
1203 scoped_refptr<TransportSocketParams> params6(
1204 new TransportSocketParams(host_port5, MEDIUM, false, false));
1205 scoped_ptr<ClientSocketHandle> connection6(new ClientSocketHandle);
1206 EXPECT_EQ(ERR_IO_PENDING,
1207 connection6->Init(host_port6.ToString(), params6, MEDIUM,
1208 callback6.callback(), &pool, log.bound()));
1209 EXPECT_TRUE(pool.IsStalled());
1210
1211 // But now if we drop our reference to the session, it will be destructed
1212 // and the transport socket will return to the pool, unblocking this
1213 // request.
1214 session2 = NULL;
1215 EXPECT_EQ(OK, callback6.WaitForResult());
1216 EXPECT_FALSE(pool.IsStalled());
1217 }
1218
1219 } // namespace net 1079 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | net/spdy/spdy_session_spdy3_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698