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

Side by Side Diff: trunk/src/net/spdy/spdy_session_pool_unittest.cc

Issue 310563002: Revert 273680 "Defer SpdySession destruction to support closing ..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 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 | « trunk/src/net/spdy/spdy_session_pool.cc ('k') | trunk/src/net/spdy/spdy_session_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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_pool.h" 5 #include "net/spdy/spdy_session_pool.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 131
132 // Close the current session. 132 // Close the current session.
133 spdy_session_pool_->CloseCurrentSessions(net::ERR_ABORTED); 133 spdy_session_pool_->CloseCurrentSessions(net::ERR_ABORTED);
134 134
135 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); 135 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key));
136 } 136 }
137 137
138 TEST_P(SpdySessionPoolTest, CloseCurrentIdleSessions) { 138 TEST_P(SpdySessionPoolTest, CloseCurrentIdleSessions) {
139 MockConnect connect_data(SYNCHRONOUS, OK); 139 MockConnect connect_data(SYNCHRONOUS, OK);
140 MockRead reads[] = { 140 MockRead reads[] = {
141 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. 141 MockRead(ASYNC, 0, 0) // EOF
142 }; 142 };
143 143
144 session_deps_.host_resolver->set_synchronous_mode(true); 144 session_deps_.host_resolver->set_synchronous_mode(true);
145 145
146 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); 146 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
147 data.set_connect_data(connect_data); 147 data.set_connect_data(connect_data);
148 session_deps_.socket_factory->AddSocketDataProvider(&data); 148 session_deps_.socket_factory->AddSocketDataProvider(&data);
149 149
150 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 150 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
151 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 151 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 base::WeakPtr<SpdySession> session3 = 188 base::WeakPtr<SpdySession> session3 =
189 CreateInsecureSpdySession(http_session_, key3, BoundNetLog()); 189 CreateInsecureSpdySession(http_session_, key3, BoundNetLog());
190 GURL url3(kTestHost3); 190 GURL url3(kTestHost3);
191 base::WeakPtr<SpdyStream> spdy_stream3 = 191 base::WeakPtr<SpdyStream> spdy_stream3 =
192 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 192 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
193 session3, url3, MEDIUM, BoundNetLog()); 193 session3, url3, MEDIUM, BoundNetLog());
194 ASSERT_TRUE(spdy_stream3.get() != NULL); 194 ASSERT_TRUE(spdy_stream3.get() != NULL);
195 195
196 // All sessions are active and not closed 196 // All sessions are active and not closed
197 EXPECT_TRUE(session1->is_active()); 197 EXPECT_TRUE(session1->is_active());
198 EXPECT_TRUE(session1->IsAvailable()); 198 EXPECT_FALSE(session1->IsClosed());
199 EXPECT_TRUE(session2->is_active()); 199 EXPECT_TRUE(session2->is_active());
200 EXPECT_TRUE(session2->IsAvailable()); 200 EXPECT_FALSE(session2->IsClosed());
201 EXPECT_TRUE(session3->is_active()); 201 EXPECT_TRUE(session3->is_active());
202 EXPECT_TRUE(session3->IsAvailable()); 202 EXPECT_FALSE(session3->IsClosed());
203 203
204 // Should not do anything, all are active 204 // Should not do anything, all are active
205 spdy_session_pool_->CloseCurrentIdleSessions(); 205 spdy_session_pool_->CloseCurrentIdleSessions();
206 EXPECT_TRUE(session1->is_active()); 206 EXPECT_TRUE(session1->is_active());
207 EXPECT_TRUE(session1->IsAvailable()); 207 EXPECT_FALSE(session1->IsClosed());
208 EXPECT_TRUE(session2->is_active()); 208 EXPECT_TRUE(session2->is_active());
209 EXPECT_TRUE(session2->IsAvailable()); 209 EXPECT_FALSE(session2->IsClosed());
210 EXPECT_TRUE(session3->is_active()); 210 EXPECT_TRUE(session3->is_active());
211 EXPECT_TRUE(session3->IsAvailable()); 211 EXPECT_FALSE(session3->IsClosed());
212 212
213 // Make sessions 1 and 3 inactive, but keep them open. 213 // Make sessions 1 and 3 inactive, but keep them open.
214 // Session 2 still open and active 214 // Session 2 still open and active
215 session1->CloseCreatedStream(spdy_stream1, OK); 215 session1->CloseCreatedStream(spdy_stream1, OK);
216 EXPECT_EQ(NULL, spdy_stream1.get()); 216 EXPECT_EQ(NULL, spdy_stream1.get());
217 session3->CloseCreatedStream(spdy_stream3, OK); 217 session3->CloseCreatedStream(spdy_stream3, OK);
218 EXPECT_EQ(NULL, spdy_stream3.get()); 218 EXPECT_EQ(NULL, spdy_stream3.get());
219 EXPECT_FALSE(session1->is_active()); 219 EXPECT_FALSE(session1->is_active());
220 EXPECT_TRUE(session1->IsAvailable()); 220 EXPECT_FALSE(session1->IsClosed());
221 EXPECT_TRUE(session2->is_active()); 221 EXPECT_TRUE(session2->is_active());
222 EXPECT_TRUE(session2->IsAvailable()); 222 EXPECT_FALSE(session2->IsClosed());
223 EXPECT_FALSE(session3->is_active()); 223 EXPECT_FALSE(session3->is_active());
224 EXPECT_TRUE(session3->IsAvailable()); 224 EXPECT_FALSE(session3->IsClosed());
225 225
226 // Should close session 1 and 3, 2 should be left open 226 // Should close session 1 and 3, 2 should be left open
227 spdy_session_pool_->CloseCurrentIdleSessions(); 227 spdy_session_pool_->CloseCurrentIdleSessions();
228 base::MessageLoop::current()->RunUntilIdle();
229
230 EXPECT_TRUE(session1 == NULL); 228 EXPECT_TRUE(session1 == NULL);
231 EXPECT_TRUE(session2->is_active()); 229 EXPECT_TRUE(session2->is_active());
232 EXPECT_TRUE(session2->IsAvailable()); 230 EXPECT_FALSE(session2->IsClosed());
233 EXPECT_TRUE(session3 == NULL); 231 EXPECT_TRUE(session3 == NULL);
234 232
235 // Should not do anything 233 // Should not do anything
236 spdy_session_pool_->CloseCurrentIdleSessions(); 234 spdy_session_pool_->CloseCurrentIdleSessions();
237 base::MessageLoop::current()->RunUntilIdle();
238
239 EXPECT_TRUE(session2->is_active()); 235 EXPECT_TRUE(session2->is_active());
240 EXPECT_TRUE(session2->IsAvailable()); 236 EXPECT_FALSE(session2->IsClosed());
241 237
242 // Make 2 not active 238 // Make 2 not active
243 session2->CloseCreatedStream(spdy_stream2, OK); 239 session2->CloseCreatedStream(spdy_stream2, OK);
244 base::MessageLoop::current()->RunUntilIdle();
245
246 EXPECT_EQ(NULL, spdy_stream2.get()); 240 EXPECT_EQ(NULL, spdy_stream2.get());
247 EXPECT_FALSE(session2->is_active()); 241 EXPECT_FALSE(session2->is_active());
248 EXPECT_TRUE(session2->IsAvailable()); 242 EXPECT_FALSE(session2->IsClosed());
249 243
250 // This should close session 2 244 // This should close session 2
251 spdy_session_pool_->CloseCurrentIdleSessions(); 245 spdy_session_pool_->CloseCurrentIdleSessions();
252 base::MessageLoop::current()->RunUntilIdle();
253
254 EXPECT_TRUE(session2 == NULL); 246 EXPECT_TRUE(session2 == NULL);
255 } 247 }
256 248
257 // Set up a SpdyStream to create a new session when it is closed. 249 // Set up a SpdyStream to create a new session when it is closed.
258 // CloseAllSessions should close the newly-created session. 250 // CloseAllSessions should close the newly-created session.
259 TEST_P(SpdySessionPoolTest, CloseAllSessions) { 251 TEST_P(SpdySessionPoolTest, CloseAllSessions) {
260 const char kTestHost[] = "www.foo.com"; 252 const char kTestHost[] = "www.foo.com";
261 const int kTestPort = 80; 253 const int kTestPort = 80;
262 254
263 session_deps_.host_resolver->set_synchronous_mode(true); 255 session_deps_.host_resolver->set_synchronous_mode(true);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); 413 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key));
422 414
423 // Expire the host cache 415 // Expire the host cache
424 session_deps_.host_resolver->GetHostCache()->clear(); 416 session_deps_.host_resolver->GetHostCache()->clear();
425 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); 417 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key));
426 418
427 // Cleanup the sessions. 419 // Cleanup the sessions.
428 switch (close_sessions_type) { 420 switch (close_sessions_type) {
429 case SPDY_POOL_CLOSE_SESSIONS_MANUALLY: 421 case SPDY_POOL_CLOSE_SESSIONS_MANUALLY:
430 session->CloseSessionOnError(ERR_ABORTED, std::string()); 422 session->CloseSessionOnError(ERR_ABORTED, std::string());
423 EXPECT_TRUE(session == NULL);
431 session2->CloseSessionOnError(ERR_ABORTED, std::string()); 424 session2->CloseSessionOnError(ERR_ABORTED, std::string());
432 base::MessageLoop::current()->RunUntilIdle();
433 EXPECT_TRUE(session == NULL);
434 EXPECT_TRUE(session2 == NULL); 425 EXPECT_TRUE(session2 == NULL);
435 break; 426 break;
436 case SPDY_POOL_CLOSE_CURRENT_SESSIONS: 427 case SPDY_POOL_CLOSE_CURRENT_SESSIONS:
437 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); 428 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED);
438 break; 429 break;
439 case SPDY_POOL_CLOSE_IDLE_SESSIONS: 430 case SPDY_POOL_CLOSE_IDLE_SESSIONS:
440 GURL url(test_hosts[0].url); 431 GURL url(test_hosts[0].url);
441 base::WeakPtr<SpdyStream> spdy_stream = 432 base::WeakPtr<SpdyStream> spdy_stream =
442 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 433 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
443 session, url, MEDIUM, BoundNetLog()); 434 session, url, MEDIUM, BoundNetLog());
444 GURL url1(test_hosts[1].url); 435 GURL url1(test_hosts[1].url);
445 base::WeakPtr<SpdyStream> spdy_stream1 = 436 base::WeakPtr<SpdyStream> spdy_stream1 =
446 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 437 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
447 session1, url1, MEDIUM, BoundNetLog()); 438 session1, url1, MEDIUM, BoundNetLog());
448 GURL url2(test_hosts[2].url); 439 GURL url2(test_hosts[2].url);
449 base::WeakPtr<SpdyStream> spdy_stream2 = 440 base::WeakPtr<SpdyStream> spdy_stream2 =
450 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 441 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
451 session2, url2, MEDIUM, BoundNetLog()); 442 session2, url2, MEDIUM, BoundNetLog());
452 443
453 // Close streams to make spdy_session and spdy_session1 inactive. 444 // Close streams to make spdy_session and spdy_session1 inactive.
454 session->CloseCreatedStream(spdy_stream, OK); 445 session->CloseCreatedStream(spdy_stream, OK);
455 EXPECT_EQ(NULL, spdy_stream.get()); 446 EXPECT_EQ(NULL, spdy_stream.get());
456 session1->CloseCreatedStream(spdy_stream1, OK); 447 session1->CloseCreatedStream(spdy_stream1, OK);
457 EXPECT_EQ(NULL, spdy_stream1.get()); 448 EXPECT_EQ(NULL, spdy_stream1.get());
458 449
459 // Check spdy_session and spdy_session1 are not closed. 450 // Check spdy_session and spdy_session1 are not closed.
460 EXPECT_FALSE(session->is_active()); 451 EXPECT_FALSE(session->is_active());
461 EXPECT_TRUE(session->IsAvailable()); 452 EXPECT_FALSE(session->IsClosed());
462 EXPECT_FALSE(session1->is_active()); 453 EXPECT_FALSE(session1->is_active());
463 EXPECT_TRUE(session1->IsAvailable()); 454 EXPECT_FALSE(session1->IsClosed());
464 EXPECT_TRUE(session2->is_active()); 455 EXPECT_TRUE(session2->is_active());
465 EXPECT_TRUE(session2->IsAvailable()); 456 EXPECT_FALSE(session2->IsClosed());
466 457
467 // Test that calling CloseIdleSessions, does not cause a crash. 458 // Test that calling CloseIdleSessions, does not cause a crash.
468 // http://crbug.com/181400 459 // http://crbug.com/181400
469 spdy_session_pool_->CloseCurrentIdleSessions(); 460 spdy_session_pool_->CloseCurrentIdleSessions();
470 base::MessageLoop::current()->RunUntilIdle();
471 461
472 // Verify spdy_session and spdy_session1 are closed. 462 // Verify spdy_session and spdy_session1 are closed.
473 EXPECT_TRUE(session == NULL); 463 EXPECT_TRUE(session == NULL);
474 EXPECT_TRUE(session1 == NULL); 464 EXPECT_TRUE(session1 == NULL);
475 EXPECT_TRUE(session2->is_active()); 465 EXPECT_TRUE(session2->is_active());
476 EXPECT_TRUE(session2->IsAvailable()); 466 EXPECT_FALSE(session2->IsClosed());
477 467
478 spdy_stream2->Cancel(); 468 spdy_stream2->Cancel();
479 EXPECT_EQ(NULL, spdy_stream.get()); 469 EXPECT_EQ(NULL, spdy_stream.get());
480 EXPECT_EQ(NULL, spdy_stream1.get()); 470 EXPECT_EQ(NULL, spdy_stream1.get());
481 EXPECT_EQ(NULL, spdy_stream2.get()); 471 EXPECT_EQ(NULL, spdy_stream2.get());
482
483 session2->CloseSessionOnError(ERR_ABORTED, std::string()); 472 session2->CloseSessionOnError(ERR_ABORTED, std::string());
484 base::MessageLoop::current()->RunUntilIdle();
485 EXPECT_TRUE(session2 == NULL); 473 EXPECT_TRUE(session2 == NULL);
486 break; 474 break;
487 } 475 }
488 476
489 // Verify that the map is all cleaned up. 477 // Verify that the map is all cleaned up.
490 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[0].key)); 478 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[0].key));
491 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); 479 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[1].key));
492 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); 480 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key));
493 } 481 }
494 482
495 TEST_P(SpdySessionPoolTest, IPPooling) { 483 TEST_P(SpdySessionPoolTest, IPPooling) {
496 RunIPPoolingTest(SPDY_POOL_CLOSE_SESSIONS_MANUALLY); 484 RunIPPoolingTest(SPDY_POOL_CLOSE_SESSIONS_MANUALLY);
497 } 485 }
498 486
499 TEST_P(SpdySessionPoolTest, IPPoolingCloseCurrentSessions) { 487 TEST_P(SpdySessionPoolTest, IPPoolingCloseCurrentSessions) {
500 RunIPPoolingTest(SPDY_POOL_CLOSE_CURRENT_SESSIONS); 488 RunIPPoolingTest(SPDY_POOL_CLOSE_CURRENT_SESSIONS);
501 } 489 }
502 490
503 TEST_P(SpdySessionPoolTest, IPPoolingCloseIdleSessions) { 491 TEST_P(SpdySessionPoolTest, IPPoolingCloseIdleSessions) {
504 RunIPPoolingTest(SPDY_POOL_CLOSE_IDLE_SESSIONS); 492 RunIPPoolingTest(SPDY_POOL_CLOSE_IDLE_SESSIONS);
505 } 493 }
506 494
507 } // namespace 495 } // namespace
508 496
509 } // namespace net 497 } // namespace net
OLDNEW
« no previous file with comments | « trunk/src/net/spdy/spdy_session_pool.cc ('k') | trunk/src/net/spdy/spdy_session_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698