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

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

Issue 2053133002: Remove MessageLoop::current()->RunUntilIdle() in net. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « net/spdy/spdy_proxy_client_socket_unittest.cc ('k') | net/spdy/spdy_stream_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 <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/run_loop.h"
13 #include "net/dns/host_cache.h" 14 #include "net/dns/host_cache.h"
14 #include "net/http/http_network_session.h" 15 #include "net/http/http_network_session.h"
15 #include "net/socket/client_socket_handle.h" 16 #include "net/socket/client_socket_handle.h"
16 #include "net/socket/transport_client_socket_pool.h" 17 #include "net/socket/transport_client_socket_pool.h"
17 #include "net/spdy/spdy_session.h" 18 #include "net/spdy/spdy_session.h"
18 #include "net/spdy/spdy_stream_test_util.h" 19 #include "net/spdy/spdy_stream_test_util.h"
19 #include "net/spdy/spdy_test_util_common.h" 20 #include "net/spdy/spdy_test_util_common.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 namespace net { 23 namespace net {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 111 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
111 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 112 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
112 113
113 CreateNetworkSession(); 114 CreateNetworkSession();
114 115
115 // Setup the first session to the first host. 116 // Setup the first session to the first host.
116 base::WeakPtr<SpdySession> session = 117 base::WeakPtr<SpdySession> session =
117 CreateInsecureSpdySession(http_session_.get(), test_key, BoundNetLog()); 118 CreateInsecureSpdySession(http_session_.get(), test_key, BoundNetLog());
118 119
119 // Flush the SpdySession::OnReadComplete() task. 120 // Flush the SpdySession::OnReadComplete() task.
120 base::MessageLoop::current()->RunUntilIdle(); 121 base::RunLoop().RunUntilIdle();
121 122
122 // Verify that we have sessions for everything. 123 // Verify that we have sessions for everything.
123 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); 124 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key));
124 125
125 // Set the stream to create a new session when it is closed. 126 // Set the stream to create a new session when it is closed.
126 base::WeakPtr<SpdyStream> spdy_stream = 127 base::WeakPtr<SpdyStream> spdy_stream =
127 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 128 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
128 session, GURL("http://www.foo.com"), 129 session, GURL("http://www.foo.com"),
129 MEDIUM, BoundNetLog()); 130 MEDIUM, BoundNetLog());
130 SessionOpeningDelegate delegate(spdy_session_pool_, test_key); 131 SessionOpeningDelegate delegate(spdy_session_pool_, test_key);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 EXPECT_FALSE(spdy_stream3); 224 EXPECT_FALSE(spdy_stream3);
224 EXPECT_FALSE(session1->is_active()); 225 EXPECT_FALSE(session1->is_active());
225 EXPECT_TRUE(session1->IsAvailable()); 226 EXPECT_TRUE(session1->IsAvailable());
226 EXPECT_TRUE(session2->is_active()); 227 EXPECT_TRUE(session2->is_active());
227 EXPECT_TRUE(session2->IsAvailable()); 228 EXPECT_TRUE(session2->IsAvailable());
228 EXPECT_FALSE(session3->is_active()); 229 EXPECT_FALSE(session3->is_active());
229 EXPECT_TRUE(session3->IsAvailable()); 230 EXPECT_TRUE(session3->IsAvailable());
230 231
231 // Should close session 1 and 3, 2 should be left open 232 // Should close session 1 and 3, 2 should be left open
232 spdy_session_pool_->CloseCurrentIdleSessions(); 233 spdy_session_pool_->CloseCurrentIdleSessions();
233 base::MessageLoop::current()->RunUntilIdle(); 234 base::RunLoop().RunUntilIdle();
234 235
235 EXPECT_FALSE(session1); 236 EXPECT_FALSE(session1);
236 EXPECT_TRUE(session2->is_active()); 237 EXPECT_TRUE(session2->is_active());
237 EXPECT_TRUE(session2->IsAvailable()); 238 EXPECT_TRUE(session2->IsAvailable());
238 EXPECT_FALSE(session3); 239 EXPECT_FALSE(session3);
239 240
240 // Should not do anything 241 // Should not do anything
241 spdy_session_pool_->CloseCurrentIdleSessions(); 242 spdy_session_pool_->CloseCurrentIdleSessions();
242 base::MessageLoop::current()->RunUntilIdle(); 243 base::RunLoop().RunUntilIdle();
243 244
244 EXPECT_TRUE(session2->is_active()); 245 EXPECT_TRUE(session2->is_active());
245 EXPECT_TRUE(session2->IsAvailable()); 246 EXPECT_TRUE(session2->IsAvailable());
246 247
247 // Make 2 not active 248 // Make 2 not active
248 session2->CloseCreatedStream(spdy_stream2, OK); 249 session2->CloseCreatedStream(spdy_stream2, OK);
249 base::MessageLoop::current()->RunUntilIdle(); 250 base::RunLoop().RunUntilIdle();
250 251
251 EXPECT_FALSE(spdy_stream2); 252 EXPECT_FALSE(spdy_stream2);
252 EXPECT_FALSE(session2->is_active()); 253 EXPECT_FALSE(session2->is_active());
253 EXPECT_TRUE(session2->IsAvailable()); 254 EXPECT_TRUE(session2->IsAvailable());
254 255
255 // This should close session 2 256 // This should close session 2
256 spdy_session_pool_->CloseCurrentIdleSessions(); 257 spdy_session_pool_->CloseCurrentIdleSessions();
257 base::MessageLoop::current()->RunUntilIdle(); 258 base::RunLoop().RunUntilIdle();
258 259
259 EXPECT_FALSE(session2); 260 EXPECT_FALSE(session2);
260 } 261 }
261 262
262 // Set up a SpdyStream to create a new session when it is closed. 263 // Set up a SpdyStream to create a new session when it is closed.
263 // CloseAllSessions should close the newly-created session. 264 // CloseAllSessions should close the newly-created session.
264 TEST_P(SpdySessionPoolTest, CloseAllSessions) { 265 TEST_P(SpdySessionPoolTest, CloseAllSessions) {
265 const char kTestHost[] = "www.foo.com"; 266 const char kTestHost[] = "www.foo.com";
266 const int kTestPort = 80; 267 const int kTestPort = 80;
267 268
(...skipping 17 matching lines...) Expand all
285 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 286 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
286 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 287 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
287 288
288 CreateNetworkSession(); 289 CreateNetworkSession();
289 290
290 // Setup the first session to the first host. 291 // Setup the first session to the first host.
291 base::WeakPtr<SpdySession> session = 292 base::WeakPtr<SpdySession> session =
292 CreateInsecureSpdySession(http_session_.get(), test_key, BoundNetLog()); 293 CreateInsecureSpdySession(http_session_.get(), test_key, BoundNetLog());
293 294
294 // Flush the SpdySession::OnReadComplete() task. 295 // Flush the SpdySession::OnReadComplete() task.
295 base::MessageLoop::current()->RunUntilIdle(); 296 base::RunLoop().RunUntilIdle();
296 297
297 // Verify that we have sessions for everything. 298 // Verify that we have sessions for everything.
298 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); 299 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key));
299 300
300 // Set the stream to create a new session when it is closed. 301 // Set the stream to create a new session when it is closed.
301 base::WeakPtr<SpdyStream> spdy_stream = 302 base::WeakPtr<SpdyStream> spdy_stream =
302 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 303 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
303 session, GURL("http://www.foo.com"), 304 session, GURL("http://www.foo.com"),
304 MEDIUM, BoundNetLog()); 305 MEDIUM, BoundNetLog());
305 SessionOpeningDelegate delegate(spdy_session_pool_, test_key); 306 SessionOpeningDelegate delegate(spdy_session_pool_, test_key);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 376 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
376 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 377 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
377 378
378 CreateNetworkSession(); 379 CreateNetworkSession();
379 380
380 // Setup the first session to the first host. 381 // Setup the first session to the first host.
381 base::WeakPtr<SpdySession> session = CreateInsecureSpdySession( 382 base::WeakPtr<SpdySession> session = CreateInsecureSpdySession(
382 http_session_.get(), test_hosts[0].key, BoundNetLog()); 383 http_session_.get(), test_hosts[0].key, BoundNetLog());
383 384
384 // Flush the SpdySession::OnReadComplete() task. 385 // Flush the SpdySession::OnReadComplete() task.
385 base::MessageLoop::current()->RunUntilIdle(); 386 base::RunLoop().RunUntilIdle();
386 387
387 // The third host has no overlap with the first, so it can't pool IPs. 388 // The third host has no overlap with the first, so it can't pool IPs.
388 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); 389 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key));
389 390
390 // The second host overlaps with the first, and should IP pool. 391 // The second host overlaps with the first, and should IP pool.
391 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); 392 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key));
392 393
393 // Verify that the second host, through a proxy, won't share the IP. 394 // Verify that the second host, through a proxy, won't share the IP.
394 SpdySessionKey proxy_key(test_hosts[1].key.host_port_pair(), 395 SpdySessionKey proxy_key(test_hosts[1].key.host_port_pair(),
395 ProxyServer::FromPacString("HTTP http://proxy.foo.com/"), 396 ProxyServer::FromPacString("HTTP http://proxy.foo.com/"),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 428
428 // Expire the host cache 429 // Expire the host cache
429 session_deps_.host_resolver->GetHostCache()->clear(); 430 session_deps_.host_resolver->GetHostCache()->clear();
430 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); 431 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key));
431 432
432 // Cleanup the sessions. 433 // Cleanup the sessions.
433 switch (close_sessions_type) { 434 switch (close_sessions_type) {
434 case SPDY_POOL_CLOSE_SESSIONS_MANUALLY: 435 case SPDY_POOL_CLOSE_SESSIONS_MANUALLY:
435 session->CloseSessionOnError(ERR_ABORTED, std::string()); 436 session->CloseSessionOnError(ERR_ABORTED, std::string());
436 session2->CloseSessionOnError(ERR_ABORTED, std::string()); 437 session2->CloseSessionOnError(ERR_ABORTED, std::string());
437 base::MessageLoop::current()->RunUntilIdle(); 438 base::RunLoop().RunUntilIdle();
438 EXPECT_FALSE(session); 439 EXPECT_FALSE(session);
439 EXPECT_FALSE(session2); 440 EXPECT_FALSE(session2);
440 break; 441 break;
441 case SPDY_POOL_CLOSE_CURRENT_SESSIONS: 442 case SPDY_POOL_CLOSE_CURRENT_SESSIONS:
442 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); 443 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED);
443 break; 444 break;
444 case SPDY_POOL_CLOSE_IDLE_SESSIONS: 445 case SPDY_POOL_CLOSE_IDLE_SESSIONS:
445 GURL url(test_hosts[0].url); 446 GURL url(test_hosts[0].url);
446 base::WeakPtr<SpdyStream> spdy_stream = 447 base::WeakPtr<SpdyStream> spdy_stream =
447 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 448 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
(...skipping 17 matching lines...) Expand all
465 EXPECT_FALSE(session->is_active()); 466 EXPECT_FALSE(session->is_active());
466 EXPECT_TRUE(session->IsAvailable()); 467 EXPECT_TRUE(session->IsAvailable());
467 EXPECT_FALSE(session1->is_active()); 468 EXPECT_FALSE(session1->is_active());
468 EXPECT_TRUE(session1->IsAvailable()); 469 EXPECT_TRUE(session1->IsAvailable());
469 EXPECT_TRUE(session2->is_active()); 470 EXPECT_TRUE(session2->is_active());
470 EXPECT_TRUE(session2->IsAvailable()); 471 EXPECT_TRUE(session2->IsAvailable());
471 472
472 // Test that calling CloseIdleSessions, does not cause a crash. 473 // Test that calling CloseIdleSessions, does not cause a crash.
473 // http://crbug.com/181400 474 // http://crbug.com/181400
474 spdy_session_pool_->CloseCurrentIdleSessions(); 475 spdy_session_pool_->CloseCurrentIdleSessions();
475 base::MessageLoop::current()->RunUntilIdle(); 476 base::RunLoop().RunUntilIdle();
476 477
477 // Verify spdy_session and spdy_session1 are closed. 478 // Verify spdy_session and spdy_session1 are closed.
478 EXPECT_FALSE(session); 479 EXPECT_FALSE(session);
479 EXPECT_FALSE(session1); 480 EXPECT_FALSE(session1);
480 EXPECT_TRUE(session2->is_active()); 481 EXPECT_TRUE(session2->is_active());
481 EXPECT_TRUE(session2->IsAvailable()); 482 EXPECT_TRUE(session2->IsAvailable());
482 483
483 spdy_stream2->Cancel(); 484 spdy_stream2->Cancel();
484 EXPECT_FALSE(spdy_stream); 485 EXPECT_FALSE(spdy_stream);
485 EXPECT_FALSE(spdy_stream1); 486 EXPECT_FALSE(spdy_stream1);
486 EXPECT_FALSE(spdy_stream2); 487 EXPECT_FALSE(spdy_stream2);
487 488
488 session2->CloseSessionOnError(ERR_ABORTED, std::string()); 489 session2->CloseSessionOnError(ERR_ABORTED, std::string());
489 base::MessageLoop::current()->RunUntilIdle(); 490 base::RunLoop().RunUntilIdle();
490 EXPECT_FALSE(session2); 491 EXPECT_FALSE(session2);
491 break; 492 break;
492 } 493 }
493 494
494 // Verify that the map is all cleaned up. 495 // Verify that the map is all cleaned up.
495 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[0].key)); 496 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[0].key));
496 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); 497 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[1].key));
497 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); 498 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key));
498 } 499 }
499 500
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 base::WeakPtr<SpdyStream> spdy_streamA = CreateStreamSynchronously( 553 base::WeakPtr<SpdyStream> spdy_streamA = CreateStreamSynchronously(
553 SPDY_BIDIRECTIONAL_STREAM, sessionA, urlA, MEDIUM, BoundNetLog()); 554 SPDY_BIDIRECTIONAL_STREAM, sessionA, urlA, MEDIUM, BoundNetLog());
554 test::StreamDelegateDoNothing delegateA(spdy_streamA); 555 test::StreamDelegateDoNothing delegateA(spdy_streamA);
555 spdy_streamA->SetDelegate(&delegateA); 556 spdy_streamA->SetDelegate(&delegateA);
556 557
557 std::unique_ptr<SpdyHeaderBlock> headers( 558 std::unique_ptr<SpdyHeaderBlock> headers(
558 spdy_util.ConstructGetHeaderBlock(urlA.spec())); 559 spdy_util.ConstructGetHeaderBlock(urlA.spec()));
559 spdy_streamA->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); 560 spdy_streamA->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND);
560 EXPECT_TRUE(spdy_streamA->HasUrlFromHeaders()); 561 EXPECT_TRUE(spdy_streamA->HasUrlFromHeaders());
561 562
562 base::MessageLoop::current()->RunUntilIdle(); // Allow headers to write. 563 base::RunLoop().RunUntilIdle(); // Allow headers to write.
563 EXPECT_TRUE(delegateA.send_headers_completed()); 564 EXPECT_TRUE(delegateA.send_headers_completed());
564 565
565 sessionA->MakeUnavailable(); 566 sessionA->MakeUnavailable();
566 EXPECT_TRUE(sessionA->IsGoingAway()); 567 EXPECT_TRUE(sessionA->IsGoingAway());
567 EXPECT_FALSE(delegateA.StreamIsClosed()); 568 EXPECT_FALSE(delegateA.StreamIsClosed());
568 569
569 // Set up session B: Available, with a created stream. 570 // Set up session B: Available, with a created stream.
570 StaticSocketDataProvider dataB(reads, arraysize(reads), writes, 571 StaticSocketDataProvider dataB(reads, arraysize(reads), writes,
571 arraysize(writes)); 572 arraysize(writes));
572 dataB.set_connect_data(connect_data); 573 dataB.set_connect_data(connect_data);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 644
644 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 645 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
645 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 646 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
646 647
647 CreateNetworkSession(); 648 CreateNetworkSession();
648 649
649 base::WeakPtr<SpdySession> session = 650 base::WeakPtr<SpdySession> session =
650 CreateInsecureSpdySession(http_session_.get(), key, BoundNetLog()); 651 CreateInsecureSpdySession(http_session_.get(), key, BoundNetLog());
651 652
652 // Flush the SpdySession::OnReadComplete() task. 653 // Flush the SpdySession::OnReadComplete() task.
653 base::MessageLoop::current()->RunUntilIdle(); 654 base::RunLoop().RunUntilIdle();
654 655
655 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key)); 656 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key));
656 657
657 // FindAvailableSession should return |session| if called with empty |url|. 658 // FindAvailableSession should return |session| if called with empty |url|.
658 base::WeakPtr<SpdySession> session1 = 659 base::WeakPtr<SpdySession> session1 =
659 spdy_session_pool_->FindAvailableSession(key, GURL(), BoundNetLog()); 660 spdy_session_pool_->FindAvailableSession(key, GURL(), BoundNetLog());
660 EXPECT_EQ(session.get(), session1.get()); 661 EXPECT_EQ(session.get(), session1.get());
661 662
662 // FindAvailableSession should return |session| if called with |url| for which 663 // FindAvailableSession should return |session| if called with |url| for which
663 // there is no pushed stream on any sessions owned by |spdy_session_pool_|. 664 // there is no pushed stream on any sessions owned by |spdy_session_pool_|.
664 base::WeakPtr<SpdySession> session2 = 665 base::WeakPtr<SpdySession> session2 =
665 spdy_session_pool_->FindAvailableSession( 666 spdy_session_pool_->FindAvailableSession(
666 key, GURL("http://news.example.org/foo.html"), BoundNetLog()); 667 key, GURL("http://news.example.org/foo.html"), BoundNetLog());
667 EXPECT_EQ(session.get(), session2.get()); 668 EXPECT_EQ(session.get(), session2.get());
668 669
669 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); 670 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED);
670 } 671 }
671 672
672 } // namespace net 673 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_proxy_client_socket_unittest.cc ('k') | net/spdy/spdy_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698