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

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel_unittest.cc

Issue 2009763002: Ping connections with the fast rate until each connection is pinged at least three times. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Address comments 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 | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/port.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 19 matching lines...) Expand all
30 #include "webrtc/base/socketaddress.h" 30 #include "webrtc/base/socketaddress.h"
31 #include "webrtc/base/ssladapter.h" 31 #include "webrtc/base/ssladapter.h"
32 #include "webrtc/base/thread.h" 32 #include "webrtc/base/thread.h"
33 #include "webrtc/base/virtualsocketserver.h" 33 #include "webrtc/base/virtualsocketserver.h"
34 34
35 using cricket::kDefaultPortAllocatorFlags; 35 using cricket::kDefaultPortAllocatorFlags;
36 using cricket::kMinimumStepDelay; 36 using cricket::kMinimumStepDelay;
37 using cricket::kDefaultStepDelay; 37 using cricket::kDefaultStepDelay;
38 using cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET; 38 using cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET;
39 using cricket::ServerAddresses; 39 using cricket::ServerAddresses;
40 using cricket::MIN_PINGS_AT_WEAK_PING_INTERVAL;
40 using rtc::SocketAddress; 41 using rtc::SocketAddress;
41 42
42 static const int kDefaultTimeout = 1000; 43 static const int kDefaultTimeout = 1000;
43 static const int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN | 44 static const int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN |
44 cricket::PORTALLOCATOR_DISABLE_RELAY | 45 cricket::PORTALLOCATOR_DISABLE_RELAY |
45 cricket::PORTALLOCATOR_DISABLE_TCP; 46 cricket::PORTALLOCATOR_DISABLE_TCP;
46 // Addresses on the public internet. 47 // Addresses on the public internet.
47 static const SocketAddress kPublicAddrs[2] = 48 static const SocketAddress kPublicAddrs[2] =
48 { SocketAddress("11.11.11.11", 0), SocketAddress("22.22.22.22", 0) }; 49 { SocketAddress("11.11.11.11", 0), SocketAddress("22.22.22.22", 0) };
49 // IPv6 Addresses on the public internet. 50 // IPv6 Addresses on the public internet.
(...skipping 2069 matching lines...) Expand 10 before | Expand all | Expand 10 after
2119 // highest priority one. 2120 // highest priority one.
2120 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 2121 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
2121 2122
2122 // Receiving a ping causes a triggered check which should make conn1 2123 // Receiving a ping causes a triggered check which should make conn1
2123 // be pinged first instead of conn2, even though conn2 has a higher 2124 // be pinged first instead of conn2, even though conn2 has a higher
2124 // priority. 2125 // priority.
2125 conn1->ReceivedPing(); 2126 conn1->ReceivedPing();
2126 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); 2127 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch));
2127 } 2128 }
2128 2129
2130 TEST_F(P2PTransportChannelPingTest, TestAllConnectionsPingedSufficiently) {
2131 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2132 cricket::P2PTransportChannel ch("ping sufficiently", 1, &pa);
2133 PrepareChannel(&ch);
2134 ch.Connect();
2135 ch.MaybeStartGathering();
2136 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2137 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
2138
2139 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2140 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2141 ASSERT_TRUE(conn1 != nullptr);
2142 ASSERT_TRUE(conn2 != nullptr);
2143
2144 // Low-priority connection becomes writable so that the other connection
2145 // is not pruned.
2146 conn1->ReceivedPingResponse();
2147 EXPECT_TRUE_WAIT(
2148 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL &&
2149 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL,
2150 kDefaultTimeout);
2151 }
2152
2129 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { 2153 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
2130 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2154 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2131 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); 2155 cricket::P2PTransportChannel ch("trigger checks", 1, &pa);
2132 PrepareChannel(&ch); 2156 PrepareChannel(&ch);
2133 ch.Connect(); 2157 ch.Connect();
2134 ch.MaybeStartGathering(); 2158 ch.MaybeStartGathering();
2135 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); 2159 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2136 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); 2160 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
2137 2161
2138 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2162 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
2797 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 2821 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
2798 2822
2799 // Make conn3 the best connection. 2823 // Make conn3 the best connection.
2800 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2824 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2801 EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE); 2825 EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE);
2802 EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE); 2826 EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE);
2803 conn3->ReceivedPingResponse(); 2827 conn3->ReceivedPingResponse();
2804 ASSERT_TRUE(conn3->writable()); 2828 ASSERT_TRUE(conn3->writable());
2805 conn3->ReceivedPing(); 2829 conn3->ReceivedPing();
2806 2830
2831 /*
2832
2833 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix
2834 the flakiness. The following test becomes flaky because we now ping the
2835 connections with fast rates until every connection is pinged at least three
2836 times. The best connection may have been pinged before |max_strong_interval|,
2837 so it may not be the next connection to be pinged as expected in the test.
2838
2807 // Verify that conn3 will be the "best connection" since it is readable and 2839 // Verify that conn3 will be the "best connection" since it is readable and
2808 // writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next 2840 // writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next
2809 // pingable connection. 2841 // pingable connection.
2810 EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000); 2842 EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000);
2811 WAIT(false, max_strong_interval + 100); 2843 WAIT(false, max_strong_interval + 100);
2812 conn3->ReceivedPingResponse(); 2844 conn3->ReceivedPingResponse();
2813 ASSERT_TRUE(conn3->writable()); 2845 ASSERT_TRUE(conn3->writable());
2814 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); 2846 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch));
2847
2848 */
2815 } 2849 }
2816 2850
2817 // Test that Relay/Relay connections will be pinged first when everything has 2851 // Test that Relay/Relay connections will be pinged first when everything has
2818 // been pinged even if the Relay/Relay connection wasn't the first to be pinged 2852 // been pinged even if the Relay/Relay connection wasn't the first to be pinged
2819 // in the first round. 2853 // in the first round.
2820 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, 2854 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
2821 TestRelayRelayFirstWhenEverythingPinged) { 2855 TestRelayRelayFirstWhenEverythingPinged) {
2822 cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100); 2856 cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100);
2823 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); 2857 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
2824 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); 2858 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
2916 2950
2917 // TCP Relay/Relay is the next. 2951 // TCP Relay/Relay is the next.
2918 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, 2952 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
2919 cricket::RELAY_PORT_TYPE, 2953 cricket::RELAY_PORT_TYPE,
2920 cricket::TCP_PROTOCOL_NAME); 2954 cricket::TCP_PROTOCOL_NAME);
2921 2955
2922 // Finally, Local/Relay will be pinged. 2956 // Finally, Local/Relay will be pinged.
2923 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, 2957 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
2924 cricket::RELAY_PORT_TYPE); 2958 cricket::RELAY_PORT_TYPE);
2925 } 2959 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/port.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698