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

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: Created 4 years, 7 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
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::kMinNumPingsSent;
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(conn1->num_pings_sent() >= kMinNumPingsSent &&
2148 conn2->num_pings_sent() >= kMinNumPingsSent,
2149 kDefaultTimeout);
2150 }
2151
2129 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { 2152 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
2130 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2153 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2131 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); 2154 cricket::P2PTransportChannel ch("trigger checks", 1, &pa);
2132 PrepareChannel(&ch); 2155 PrepareChannel(&ch);
2133 ch.Connect(); 2156 ch.Connect();
2134 ch.MaybeStartGathering(); 2157 ch.MaybeStartGathering();
2135 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); 2158 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2136 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); 2159 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
2137 2160
2138 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2161 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
2800 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2823 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2801 EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE); 2824 EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE);
2802 EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE); 2825 EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE);
2803 conn3->ReceivedPingResponse(); 2826 conn3->ReceivedPingResponse();
2804 ASSERT_TRUE(conn3->writable()); 2827 ASSERT_TRUE(conn3->writable());
2805 conn3->ReceivedPing(); 2828 conn3->ReceivedPing();
2806 2829
2807 // Verify that conn3 will be the "best connection" since it is readable and 2830 // 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 2831 // writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next
2809 // pingable connection. 2832 // pingable connection.
2833 /*
2834 * We now ping the connection with fast rates until all connections
2835 * are pinged three times. The following test becomes flaky because the
2836 * best connection may have been pinged before |max_strong_interval|.
2837 * Temporarily disable this until we use fake clock for the test.
pthatcher1 2016/05/25 17:29:13 We should have a TODO to re-enable it. And coul
honghaiz3 2016/05/25 18:40:02 Done for both.
2810 EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000); 2838 EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000);
2811 WAIT(false, max_strong_interval + 100); 2839 WAIT(false, max_strong_interval + 100);
2812 conn3->ReceivedPingResponse(); 2840 conn3->ReceivedPingResponse();
2813 ASSERT_TRUE(conn3->writable()); 2841 ASSERT_TRUE(conn3->writable());
2814 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); 2842 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch));
2843 */
2815 } 2844 }
2816 2845
2817 // Test that Relay/Relay connections will be pinged first when everything has 2846 // 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 2847 // been pinged even if the Relay/Relay connection wasn't the first to be pinged
2819 // in the first round. 2848 // in the first round.
2820 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, 2849 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
2821 TestRelayRelayFirstWhenEverythingPinged) { 2850 TestRelayRelayFirstWhenEverythingPinged) {
2822 cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100); 2851 cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100);
2823 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); 2852 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
2824 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); 2853 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
2916 2945
2917 // TCP Relay/Relay is the next. 2946 // TCP Relay/Relay is the next.
2918 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, 2947 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
2919 cricket::RELAY_PORT_TYPE, 2948 cricket::RELAY_PORT_TYPE,
2920 cricket::TCP_PROTOCOL_NAME); 2949 cricket::TCP_PROTOCOL_NAME);
2921 2950
2922 // Finally, Local/Relay will be pinged. 2951 // Finally, Local/Relay will be pinged.
2923 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, 2952 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
2924 cricket::RELAY_PORT_TYPE); 2953 cricket::RELAY_PORT_TYPE);
2925 } 2954 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698