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

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

Issue 2739183005: Correctly log IP pooling in SpdySessionPool. (Closed)
Patch Set: Add link to bug in comment. Created 3 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
« no previous file with comments | « net/spdy/spdy_session_pool.cc ('k') | no next file » | 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/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/test/histogram_tester.h"
15 #include "base/trace_event/memory_allocator_dump.h" 16 #include "base/trace_event/memory_allocator_dump.h"
16 #include "base/trace_event/process_memory_dump.h" 17 #include "base/trace_event/process_memory_dump.h"
17 #include "base/trace_event/trace_event_argument.h" 18 #include "base/trace_event/trace_event_argument.h"
18 #include "net/dns/host_cache.h" 19 #include "net/dns/host_cache.h"
19 #include "net/http/http_network_session.h" 20 #include "net/http/http_network_session.h"
20 #include "net/log/net_log_with_source.h" 21 #include "net/log/net_log_with_source.h"
22 #include "net/log/test_net_log.h"
23 #include "net/log/test_net_log_entry.h"
21 #include "net/socket/client_socket_handle.h" 24 #include "net/socket/client_socket_handle.h"
22 #include "net/socket/transport_client_socket_pool.h" 25 #include "net/socket/transport_client_socket_pool.h"
23 #include "net/spdy/spdy_session.h" 26 #include "net/spdy/spdy_session.h"
24 #include "net/spdy/spdy_stream_test_util.h" 27 #include "net/spdy/spdy_stream_test_util.h"
25 #include "net/spdy/spdy_test_util_common.h" 28 #include "net/spdy/spdy_test_util_common.h"
26 #include "net/test/cert_test_util.h" 29 #include "net/test/cert_test_util.h"
27 #include "net/test/gtest_util.h" 30 #include "net/test/gtest_util.h"
28 #include "net/test/test_data_directory.h" 31 #include "net/test/test_data_directory.h"
29 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
30 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 505 }
503 506
504 TEST_F(SpdySessionPoolTest, IPPoolingCloseCurrentSessions) { 507 TEST_F(SpdySessionPoolTest, IPPoolingCloseCurrentSessions) {
505 RunIPPoolingTest(SPDY_POOL_CLOSE_CURRENT_SESSIONS); 508 RunIPPoolingTest(SPDY_POOL_CLOSE_CURRENT_SESSIONS);
506 } 509 }
507 510
508 TEST_F(SpdySessionPoolTest, IPPoolingCloseIdleSessions) { 511 TEST_F(SpdySessionPoolTest, IPPoolingCloseIdleSessions) {
509 RunIPPoolingTest(SPDY_POOL_CLOSE_IDLE_SESSIONS); 512 RunIPPoolingTest(SPDY_POOL_CLOSE_IDLE_SESSIONS);
510 } 513 }
511 514
515 // Regression test for https://crbug.com/643025.
516 TEST_F(SpdySessionPoolTest, IPPoolingNetLog) {
517 // Define two hosts with identical IP address.
518 const int kTestPort = 443;
519 struct TestHosts {
520 std::string name;
521 std::string iplist;
522 SpdySessionKey key;
523 AddressList addresses;
524 std::unique_ptr<HostResolver::Request> request;
525 } test_hosts[] = {
526 {"www.example.org", "192.168.0.1"}, {"mail.example.org", "192.168.0.1"},
527 };
528
529 // Populate the HostResolver cache.
530 session_deps_.host_resolver->set_synchronous_mode(true);
531 for (size_t i = 0; i < arraysize(test_hosts); i++) {
532 session_deps_.host_resolver->rules()->AddIPLiteralRule(
533 test_hosts[i].name, test_hosts[i].iplist, std::string());
534
535 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort));
536 session_deps_.host_resolver->Resolve(
537 info, DEFAULT_PRIORITY, &test_hosts[i].addresses, CompletionCallback(),
538 &test_hosts[i].request, NetLogWithSource());
539
540 test_hosts[i].key =
541 SpdySessionKey(HostPortPair(test_hosts[i].name, kTestPort),
542 ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
543 }
544
545 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING)};
546 StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0);
547 MockConnect connect_data(SYNCHRONOUS, OK);
548 data.set_connect_data(connect_data);
549
550 session_deps_.socket_factory->AddSocketDataProvider(&data);
551 AddSSLSocketData();
552
553 CreateNetworkSession();
554
555 // Open SpdySession to the first host.
556 base::WeakPtr<SpdySession> session0 = CreateSecureSpdySession(
557 http_session_.get(), test_hosts[0].key, NetLogWithSource());
558
559 // A request to the second host should pool to the existing connection.
560 BoundTestNetLog net_log;
561 base::HistogramTester histogram_tester;
562 base::WeakPtr<SpdySession> session1 =
563 spdy_session_pool_->FindAvailableSession(test_hosts[1].key, GURL(),
564 net_log.bound());
565 EXPECT_EQ(session0.get(), session1.get());
566
567 ASSERT_EQ(1u, net_log.GetSize());
568 histogram_tester.ExpectTotalCount("Net.SpdySessionGet", 1);
569
570 // A request to the second host should still pool to the existing connection.
571 session1 = spdy_session_pool_->FindAvailableSession(test_hosts[1].key, GURL(),
572 net_log.bound());
573 EXPECT_EQ(session0.get(), session1.get());
574
575 ASSERT_EQ(2u, net_log.GetSize());
576 histogram_tester.ExpectTotalCount("Net.SpdySessionGet", 2);
577
578 // Both FindAvailableSession() calls should log netlog events
579 // indicating IP pooling.
580 TestNetLogEntry::List entry_list;
581 net_log.GetEntries(&entry_list);
582 EXPECT_EQ(
583 NetLogEventType::HTTP2_SESSION_POOL_FOUND_EXISTING_SESSION_FROM_IP_POOL,
584 entry_list[0].type);
585 EXPECT_EQ(
586 NetLogEventType::HTTP2_SESSION_POOL_FOUND_EXISTING_SESSION_FROM_IP_POOL,
587 entry_list[1].type);
588
589 // Both FindAvailableSession() calls should log histogram entries
590 // indicating IP pooling.
591 histogram_tester.ExpectUniqueSample("Net.SpdySessionGet", 2, 2);
592 }
593
512 // Construct a Pool with SpdySessions in various availability states. Simulate 594 // Construct a Pool with SpdySessions in various availability states. Simulate
513 // an IP address change. Ensure sessions gracefully shut down. Regression test 595 // an IP address change. Ensure sessions gracefully shut down. Regression test
514 // for crbug.com/379469. 596 // for crbug.com/379469.
515 TEST_F(SpdySessionPoolTest, IPAddressChanged) { 597 TEST_F(SpdySessionPoolTest, IPAddressChanged) {
516 MockConnect connect_data(SYNCHRONOUS, OK); 598 MockConnect connect_data(SYNCHRONOUS, OK);
517 session_deps_.host_resolver->set_synchronous_mode(true); 599 session_deps_.host_resolver->set_synchronous_mode(true);
518 600
519 // This isn't testing anything having to do with SPDY frames; we 601 // This isn't testing anything having to do with SPDY frames; we
520 // can ignore issues of how dependencies are set. We default to 602 // can ignore issues of how dependencies are set. We default to
521 // setting them (when doing the appropriate protocol) since that's 603 // setting them (when doing the appropriate protocol) since that's
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 active_session_count_attr->GetString("value", &active_session_count)); 814 active_session_count_attr->GetString("value", &active_session_count));
733 // No created stream so the session should be idle. 815 // No created stream so the session should be idle.
734 ASSERT_EQ("0", active_session_count); 816 ASSERT_EQ("0", active_session_count);
735 did_dump = true; 817 did_dump = true;
736 } 818 }
737 EXPECT_TRUE(did_dump); 819 EXPECT_TRUE(did_dump);
738 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); 820 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED);
739 } 821 }
740 822
741 } // namespace net 823 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session_pool.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698