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

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

Issue 2212683002: Do not switch a connection if the new connection is not ready to send packets. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Updated tests Created 4 years, 4 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') | 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 /* 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 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 } 850 }
851 851
852 void ConnectSignalNominated(Connection* conn) { 852 void ConnectSignalNominated(Connection* conn) {
853 conn->SignalNominated.connect(this, 853 conn->SignalNominated.connect(this,
854 &P2PTransportChannelTestBase::OnNominated); 854 &P2PTransportChannelTestBase::OnNominated);
855 } 855 }
856 856
857 void OnNominated(Connection* conn) { nominated_ = true; } 857 void OnNominated(Connection* conn) { nominated_ = true; }
858 bool nominated() { return nominated_; } 858 bool nominated() { return nominated_; }
859 859
860 Connection* GetTopConnection(P2PTransportChannel* channel) {
861 if (channel->connections().empty()) {
862 return nullptr;
863 }
864 return channel->connections().front();
865 }
Taylor Brandstetter 2016/08/08 23:01:05 I think these unit tests should move away from acc
honghaiz3 2016/08/11 22:45:53 Done.
866
860 private: 867 private:
861 rtc::Thread* main_; 868 rtc::Thread* main_;
862 std::unique_ptr<rtc::PhysicalSocketServer> pss_; 869 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
863 std::unique_ptr<rtc::VirtualSocketServer> vss_; 870 std::unique_ptr<rtc::VirtualSocketServer> vss_;
864 std::unique_ptr<rtc::NATSocketServer> nss_; 871 std::unique_ptr<rtc::NATSocketServer> nss_;
865 std::unique_ptr<rtc::FirewallSocketServer> ss_; 872 std::unique_ptr<rtc::FirewallSocketServer> ss_;
866 rtc::SocketServerScope ss_scope_; 873 rtc::SocketServerScope ss_scope_;
867 std::unique_ptr<TestStunServer> stun_server_; 874 std::unique_ptr<TestStunServer> stun_server_;
868 TestTurnServer turn_server_; 875 TestTurnServer turn_server_;
869 TestRelayServer relay_server_; 876 TestRelayServer relay_server_;
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 // Emulate no remote credentials coming in. 1172 // Emulate no remote credentials coming in.
1166 set_remote_ice_credential_source(FROM_CANDIDATE); 1173 set_remote_ice_credential_source(FROM_CANDIDATE);
1167 CreateChannels(1); 1174 CreateChannels(1);
1168 // Only have remote credentials come in for ep2, not ep1. 1175 // Only have remote credentials come in for ep2, not ep1.
1169 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); 1176 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]);
1170 1177
1171 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive 1178 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive
1172 // candidate. 1179 // candidate.
1173 PauseCandidates(1); 1180 PauseCandidates(1);
1174 1181
1175 // The caller should have the selected connection connected to the peer 1182 // The caller should have the top connection connected to the peer
1176 // reflexive candidate. 1183 // reflexive candidate. Note that the top connection is not selected yet as
1177 const Connection* selected_connection = NULL; 1184 // it is not ready to send.
1178 WAIT((selected_connection = ep1_ch1()->selected_connection()) != NULL, 2000); 1185 const Connection* top_connection = NULL;
1179 EXPECT_EQ("prflx", 1186 ASSERT_TRUE_WAIT((top_connection = GetTopConnection(ep1_ch1())) != NULL,
Taylor Brandstetter 2016/08/08 23:01:05 For example, in this test I think we can do the EX
honghaiz3 2016/08/11 22:45:53 Done.
1180 ep1_ch1()->selected_connection()->remote_candidate().type()); 1187 2000);
1188 EXPECT_EQ("prflx", top_connection->remote_candidate().type());
1181 1189
1182 // Because we don't have a remote pwd, we don't ping yet. 1190 // Because we don't have a remote pwd, we don't ping yet.
1183 EXPECT_EQ(kIceUfrag[1], 1191 EXPECT_EQ(kIceUfrag[1], top_connection->remote_candidate().username());
1184 ep1_ch1()->selected_connection()->remote_candidate().username()); 1192 EXPECT_TRUE(top_connection->remote_candidate().password().empty());
1185 EXPECT_EQ("",
1186 ep1_ch1()->selected_connection()->remote_candidate().password());
1187 // Because we don't have ICE credentials yet, we don't know the generation. 1193 // Because we don't have ICE credentials yet, we don't know the generation.
1188 EXPECT_EQ(0u, 1194 EXPECT_EQ(0u, top_connection->remote_candidate().generation());
1189 ep1_ch1()->selected_connection()->remote_candidate().generation());
1190 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); 1195 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection());
1191 1196
1192 // Add two sets of remote ICE credentials, so that the ones used by the 1197 // Add two sets of remote ICE credentials, so that the ones used by the
1193 // candidate will be generation 1 instead of 0. 1198 // candidate will be generation 1 instead of 0.
1194 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 1199 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]);
1195 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 1200 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]);
1196 // After setting the remote ICE credentials, the password and generation 1201 // After setting the remote ICE credentials, the password and generation
1197 // of the peer reflexive candidate should be updated. 1202 // of the peer reflexive candidate should be updated.
1198 EXPECT_EQ(kIcePwd[1], 1203 EXPECT_EQ(kIcePwd[1], top_connection->remote_candidate().password());
1199 ep1_ch1()->selected_connection()->remote_candidate().password()); 1204 EXPECT_EQ(1u, top_connection->remote_candidate().generation());
Taylor Brandstetter 2016/08/15 17:55:49 Previously this tested that a prflx candidate's ge
honghaiz3 2016/08/16 17:29:15 It is more natural to test all these (ufrag, pwd,
Taylor Brandstetter 2016/08/16 18:48:31 I don't think we need to peek at the internal stat
honghaiz3 2016/08/16 21:11:36 Done. True if we only need to check the ICE genera
1200 EXPECT_EQ(1u,
1201 ep1_ch1()->selected_connection()->remote_candidate().generation());
1202 EXPECT_TRUE(nullptr != ep1_ch1()->FindNextPingableConnection()); 1205 EXPECT_TRUE(nullptr != ep1_ch1()->FindNextPingableConnection());
1203 1206
1204 ResumeCandidates(1); 1207 ResumeCandidates(1);
1205 1208
1206 WAIT(ep2_ch1()->selected_connection() != NULL, 2000); 1209 EXPECT_TRUE_WAIT(ep2_ch1()->selected_connection() != NULL, 2000);
1207 // Verify ep1's selected connection is updated to use the 'local' candidate. 1210 // Verify ep1's top connection is updated to use the 'local' candidate.
1208 EXPECT_EQ_WAIT("local", 1211 EXPECT_EQ_WAIT("local",
1209 ep1_ch1()->selected_connection()->remote_candidate().type(), 1212 GetTopConnection(ep1_ch1())->remote_candidate().type(), 2000);
1210 2000); 1213 EXPECT_EQ(top_connection, GetTopConnection(ep1_ch1()));
1211 EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection());
1212 DestroyChannels(); 1214 DestroyChannels();
1213 } 1215 }
1214 1216
1215 // Test that we properly create a connection on a STUN ping from unknown address 1217 // Test that we properly create a connection on a STUN ping from unknown address
1216 // when the signaling is slow and the end points are behind NAT. 1218 // when the signaling is slow and the end points are behind NAT.
1217 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { 1219 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) {
1218 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, 1220 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags,
1219 kDefaultPortAllocatorFlags); 1221 kDefaultPortAllocatorFlags);
1220 // Emulate no remote credentials coming in. 1222 // Emulate no remote credentials coming in.
1221 set_remote_ice_credential_source(FROM_CANDIDATE); 1223 set_remote_ice_credential_source(FROM_CANDIDATE);
1222 CreateChannels(1); 1224 CreateChannels(1);
1223 // Only have remote credentials come in for ep2, not ep1. 1225 // Only have remote credentials come in for ep2, not ep1.
1224 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); 1226 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]);
1225 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive 1227 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive
1226 // candidate. 1228 // candidate.
1227 PauseCandidates(1); 1229 PauseCandidates(1);
1228 1230
1229 // The caller should have the selected connection connected to the peer 1231 // The caller's top connection should be connected to the peer reflexive
1230 // reflexive candidate. 1232 // candidate.
1231 WAIT(ep1_ch1()->selected_connection() != NULL, 2000); 1233 Connection* top_connection = nullptr;
1232 EXPECT_EQ("prflx", 1234 ASSERT_TRUE_WAIT((top_connection = GetTopConnection(ep1_ch1())) != nullptr,
1233 ep1_ch1()->selected_connection()->remote_candidate().type()); 1235 2000);
1236 EXPECT_EQ("prflx", top_connection->remote_candidate().type());
1234 1237
1235 // Because we don't have a remote pwd, we don't ping yet. 1238 // Because we don't have a remote pwd, we don't ping yet.
1236 EXPECT_EQ(kIceUfrag[1], 1239 EXPECT_EQ(kIceUfrag[1], top_connection->remote_candidate().username());
1237 ep1_ch1()->selected_connection()->remote_candidate().username()); 1240 EXPECT_EQ("", top_connection->remote_candidate().password());
1238 EXPECT_EQ("",
1239 ep1_ch1()->selected_connection()->remote_candidate().password());
1240 // Because we don't have ICE credentials yet, we don't know the generation. 1241 // Because we don't have ICE credentials yet, we don't know the generation.
1241 EXPECT_EQ(0u, 1242 EXPECT_EQ(0u, top_connection->remote_candidate().generation());
1242 ep1_ch1()->selected_connection()->remote_candidate().generation());
1243 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); 1243 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection());
1244 1244
1245 // Add two sets of remote ICE credentials, so that the ones used by the 1245 // Add two sets of remote ICE credentials, so that the ones used by the
1246 // candidate will be generation 1 instead of 0. 1246 // candidate will be generation 1 instead of 0.
1247 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 1247 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]);
1248 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 1248 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]);
1249 // After setting the remote ICE credentials, the password and generation 1249 // After setting the remote ICE credentials, the password and generation
1250 // of the peer reflexive candidate should be updated. 1250 // of the peer reflexive candidate should be updated.
1251 EXPECT_EQ(kIcePwd[1], 1251 EXPECT_EQ(kIcePwd[1], top_connection->remote_candidate().password());
1252 ep1_ch1()->selected_connection()->remote_candidate().password()); 1252 EXPECT_EQ(1u, top_connection->remote_candidate().generation());
1253 EXPECT_EQ(1u,
1254 ep1_ch1()->selected_connection()->remote_candidate().generation());
1255 1253
1256 ResumeCandidates(1); 1254 ResumeCandidates(1);
1257 1255
1258 const Connection* selected_connection = NULL; 1256 const Connection* selected_connection = NULL;
1259 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 2000); 1257 EXPECT_TRUE_WAIT(
1258 (selected_connection = ep2_ch1()->selected_connection()) != NULL, 2000);
1260 1259
1261 // Wait to verify the connection is not culled. 1260 // Wait to verify the connection is not culled.
1262 WAIT(ep1_ch1()->writable(), 2000); 1261 EXPECT_TRUE_WAIT(ep1_ch1()->writable(), 2000);
1263 EXPECT_EQ(ep2_ch1()->selected_connection(), selected_connection);
1264 EXPECT_EQ("prflx", 1262 EXPECT_EQ("prflx",
1265 ep1_ch1()->selected_connection()->remote_candidate().type()); 1263 ep1_ch1()->selected_connection()->remote_candidate().type());
1264 EXPECT_EQ(selected_connection, ep2_ch1()->selected_connection());
1266 DestroyChannels(); 1265 DestroyChannels();
1267 } 1266 }
1268 1267
1269 // Test that we properly create a connection on a STUN ping from unknown address 1268 // Test that we properly create a connection on a STUN ping from unknown address
1270 // when the signaling is slow, even if the new candidate is created due to the 1269 // when the signaling is slow, even if the new candidate is created due to the
1271 // remote peer doing an ICE restart, pairing this candidate across generations. 1270 // remote peer doing an ICE restart, pairing this candidate across generations.
1272 // 1271 //
1273 // Previously this wasn't working due to a bug where the peer reflexive 1272 // Previously this wasn't working due to a bug where the peer reflexive
1274 // candidate was only updated for the newest generation candidate pairs, and 1273 // candidate was only updated for the newest generation candidate pairs, and
1275 // not older-generation candidate pairs created by pairing candidates across 1274 // not older-generation candidate pairs created by pairing candidates across
(...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after
2550 ch->SignalSelectedCandidatePairChanged.connect( 2549 ch->SignalSelectedCandidatePairChanged.connect(
2551 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged); 2550 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged);
2552 ch->SignalReadyToSend.connect(this, 2551 ch->SignalReadyToSend.connect(this,
2553 &P2PTransportChannelPingTest::OnReadyToSend); 2552 &P2PTransportChannelPingTest::OnReadyToSend);
2554 ch->SignalStateChanged.connect( 2553 ch->SignalStateChanged.connect(
2555 this, &P2PTransportChannelPingTest::OnChannelStateChanged); 2554 this, &P2PTransportChannelPingTest::OnChannelStateChanged);
2556 } 2555 }
2557 2556
2558 Connection* WaitForConnectionTo(P2PTransportChannel* ch, 2557 Connection* WaitForConnectionTo(P2PTransportChannel* ch,
2559 const std::string& ip, 2558 const std::string& ip,
2560 int port_num) { 2559 int port_num,
2561 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); 2560 rtc::FakeClock* clock = nullptr) {
2561 if (clock == nullptr) {
2562 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000);
2563 } else {
2564 EXPECT_TRUE_SIMULATED_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr,
2565 3000, *clock);
2566 }
2562 return GetConnectionTo(ch, ip, port_num); 2567 return GetConnectionTo(ch, ip, port_num);
2563 } 2568 }
2564 2569
2565 Port* GetPort(P2PTransportChannel* ch) { 2570 Port* GetPort(P2PTransportChannel* ch) {
2566 if (ch->ports().empty()) { 2571 if (ch->ports().empty()) {
2567 return nullptr; 2572 return nullptr;
2568 } 2573 }
2569 return static_cast<Port*>(ch->ports()[0]); 2574 return static_cast<Port*>(ch->ports()[0]);
2570 } 2575 }
2571 2576
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
3036 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); 3041 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE));
3037 EXPECT_EQ(500, ch.receiving_timeout()); 3042 EXPECT_EQ(500, ch.receiving_timeout());
3038 EXPECT_EQ(50, ch.check_receiving_interval()); 3043 EXPECT_EQ(50, ch.check_receiving_interval());
3039 ch.MaybeStartGathering(); 3044 ch.MaybeStartGathering();
3040 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3045 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3041 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3046 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3042 ASSERT_TRUE(conn1 != nullptr); 3047 ASSERT_TRUE(conn1 != nullptr);
3043 3048
3044 conn1->ReceivedPing(); 3049 conn1->ReceivedPing();
3045 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); 3050 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
3046 EXPECT_TRUE_WAIT(ch.selected_connection() != nullptr, 1000);
3047 EXPECT_TRUE_WAIT(ch.receiving(), 1000); 3051 EXPECT_TRUE_WAIT(ch.receiving(), 1000);
3048 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); 3052 EXPECT_TRUE_WAIT(!ch.receiving(), 1000);
3049 } 3053 }
3050 3054
3051 // The controlled side will select a connection as the "selected connection" 3055 // The controlled side will select a connection as the "selected connection"
3052 // based on priority until the controlling side nominates a connection, at which 3056 // based on priority until the controlling side nominates a connection, at which
3053 // point the controlled side will select that connection as the 3057 // point the controlled side will select that connection as the
3054 // "selected connection". Plus, SignalSelectedCandidatePair will be fired if the 3058 // "selected connection". Plus, SignalSelectedCandidatePair will be fired if the
3055 // selected connection changes and SignalReadyToSend will be fired if the new 3059 // selected connection changes and SignalReadyToSend will be fired if the new
3056 // selected connection is writable. 3060 // selected connection is writable.
3057 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { 3061 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
3058 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3062 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3059 P2PTransportChannel ch("receiving state change", 1, &pa); 3063 P2PTransportChannel ch("receiving state change", 1, &pa);
3060 PrepareChannel(&ch); 3064 PrepareChannel(&ch);
3061 ch.SetIceRole(ICEROLE_CONTROLLED); 3065 ch.SetIceRole(ICEROLE_CONTROLLED);
3062 ch.MaybeStartGathering(); 3066 ch.MaybeStartGathering();
3063 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3067 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3064 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3068 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3065 ASSERT_TRUE(conn1 != nullptr); 3069 ASSERT_TRUE(conn1 != nullptr);
3066 EXPECT_EQ(conn1, ch.selected_connection());
3067 EXPECT_EQ(conn1, last_selected_candidate_pair());
3068 EXPECT_EQ(-1, last_sent_packet_id());
3069 // Channel is not ready to send because it is not writable. 3070 // Channel is not ready to send because it is not writable.
3070 EXPECT_FALSE(channel_ready_to_send()); 3071 EXPECT_FALSE(channel_ready_to_send());
3071
3072 int last_packet_id = 0; 3072 int last_packet_id = 0;
3073 const char* data = "ABCDEFGH"; 3073 const char* data = "ABCDEFGH";
3074 int len = static_cast<int>(strlen(data)); 3074 int len = static_cast<int>(strlen(data));
3075 EXPECT_EQ(-1, SendData(ch, data, len, ++last_packet_id)); 3075 EXPECT_EQ(-1, SendData(ch, data, len, ++last_packet_id));
3076 EXPECT_EQ(-1, last_sent_packet_id());
3077
3078 // A connection need to be writable before it is selected for transmission.
Taylor Brandstetter 2016/08/08 23:01:05 nit: "needs"
honghaiz3 2016/08/11 22:45:53 Done.
3079 conn1->ReceivedPingResponse(LOW_RTT, "id");
3080 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout);
3081 EXPECT_EQ(conn1, last_selected_candidate_pair());
3082 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id));
3083
3076 // When a higher priority candidate comes in, the new connection is chosen 3084 // When a higher priority candidate comes in, the new connection is chosen
3077 // as the selected connection. 3085 // as the selected connection.
3078 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); 3086 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
3079 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3087 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3080 ASSERT_TRUE(conn2 != nullptr); 3088 ASSERT_TRUE(conn2 != nullptr);
3081 EXPECT_EQ(conn2, ch.selected_connection()); 3089 conn2->ReceivedPingResponse(LOW_RTT, "id");
3090 EXPECT_EQ_WAIT(conn2, ch.selected_connection(), kDefaultTimeout);
3082 EXPECT_EQ(conn2, last_selected_candidate_pair()); 3091 EXPECT_EQ(conn2, last_selected_candidate_pair());
3083 EXPECT_EQ(-1, last_sent_packet_id()); 3092 EXPECT_TRUE(channel_ready_to_send());
3084 EXPECT_FALSE(channel_ready_to_send()); 3093 EXPECT_EQ(last_packet_id, last_sent_packet_id());
3085 3094
3086 // If a stun request with use-candidate attribute arrives, the receiving 3095 // If a stun request with use-candidate attribute arrives, the receiving
3087 // connection will be set as the selected connection, even though 3096 // connection will be set as the selected connection, even though
3088 // its priority is lower. 3097 // its priority is lower.
3089 EXPECT_EQ(-1, SendData(ch, data, len, ++last_packet_id)); 3098 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id));
3090 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); 3099 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
3091 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3100 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3092 ASSERT_TRUE(conn3 != nullptr); 3101 ASSERT_TRUE(conn3 != nullptr);
3093 // Because it has a lower priority, the selected connection is still conn2. 3102 // Because it has a lower priority, the selected connection is still conn2.
3094 EXPECT_EQ(conn2, ch.selected_connection()); 3103 EXPECT_EQ(conn2, ch.selected_connection());
3095 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. 3104 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3096 // But if it is nominated via use_candidate, it is chosen as the selected 3105 // But if it is nominated via use_candidate, it is chosen as the selected
3097 // connection. 3106 // connection.
3098 NominateConnection(conn3); 3107 NominateConnection(conn3);
3099 EXPECT_EQ(conn3, ch.selected_connection()); 3108 EXPECT_EQ(conn3, ch.selected_connection());
3100 EXPECT_EQ(conn3, last_selected_candidate_pair()); 3109 EXPECT_EQ(conn3, last_selected_candidate_pair());
3101 EXPECT_EQ(-1, last_sent_packet_id()); 3110 EXPECT_EQ(last_packet_id, last_sent_packet_id());
3102 EXPECT_TRUE(channel_ready_to_send()); 3111 EXPECT_TRUE(channel_ready_to_send());
3103 3112
3104 // Even if another higher priority candidate arrives, it will not be set as 3113 // Even if another higher priority candidate arrives, it will not be set as
3105 // the selected connection because the selected connection is nominated by 3114 // the selected connection because the selected connection is nominated by
3106 // the controlling side. 3115 // the controlling side.
3107 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id)); 3116 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id));
3108 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100)); 3117 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100));
3109 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); 3118 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
3110 ASSERT_TRUE(conn4 != nullptr); 3119 ASSERT_TRUE(conn4 != nullptr);
3111 EXPECT_EQ(conn3, ch.selected_connection()); 3120 EXPECT_EQ(conn3, ch.selected_connection());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3143 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3152 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
3144 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3153 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3145 request.AddAttribute( 3154 request.AddAttribute(
3146 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3155 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
3147 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch)); 3156 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch));
3148 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 3157 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
3149 &request, kIceUfrag[1], false); 3158 &request, kIceUfrag[1], false);
3150 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3159 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3151 ASSERT_TRUE(conn1 != nullptr); 3160 ASSERT_TRUE(conn1 != nullptr);
3152 EXPECT_TRUE(port->sent_binding_response()); 3161 EXPECT_TRUE(port->sent_binding_response());
3153 EXPECT_EQ(conn1, ch.selected_connection()); 3162 EXPECT_NE(conn1, ch.selected_connection());
3154 conn1->ReceivedPingResponse(LOW_RTT, "id"); 3163 conn1->ReceivedPingResponse(LOW_RTT, "id");
3155 EXPECT_EQ(conn1, ch.selected_connection()); 3164 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout);
3156 port->set_sent_binding_response(false); 3165 port->set_sent_binding_response(false);
3157 3166
3158 // Another connection is nominated via use_candidate. 3167 // Another connection is nominated via use_candidate.
3159 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3168 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3160 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3169 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3161 ASSERT_TRUE(conn2 != nullptr); 3170 ASSERT_TRUE(conn2 != nullptr);
3162 // Because it has a lower priority, the selected connection is still conn1. 3171 // Because it has a lower priority, the selected connection is still conn1.
3163 EXPECT_EQ(conn1, ch.selected_connection()); 3172 EXPECT_EQ(conn1, ch.selected_connection());
3164 // When it is nominated via use_candidate and writable, it is chosen as the 3173 // When it is nominated via use_candidate and writable, it is chosen as the
3165 // selected connection. 3174 // selected connection.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3211 // the "selected connection". 3220 // the "selected connection".
3212 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { 3221 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
3213 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3222 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3214 P2PTransportChannel ch("receiving state change", 1, &pa); 3223 P2PTransportChannel ch("receiving state change", 1, &pa);
3215 PrepareChannel(&ch); 3224 PrepareChannel(&ch);
3216 ch.SetIceRole(ICEROLE_CONTROLLED); 3225 ch.SetIceRole(ICEROLE_CONTROLLED);
3217 ch.MaybeStartGathering(); 3226 ch.MaybeStartGathering();
3218 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 10)); 3227 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 10));
3219 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3228 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3220 ASSERT_TRUE(conn1 != nullptr); 3229 ASSERT_TRUE(conn1 != nullptr);
3221 EXPECT_EQ(conn1, ch.selected_connection()); 3230 conn1->ReceivedPingResponse(LOW_RTT, "id");
3231 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout);
3222 3232
3223 // If a data packet is received on conn2, the selected connection should 3233 // If a data packet is received on conn2, the selected connection should
3224 // switch to conn2 because the controlled side must mirror the media path 3234 // switch to conn2 because the controlled side must mirror the media path
3225 // chosen by the controlling side. 3235 // chosen by the controlling side.
3226 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3236 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3227 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3237 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3228 ASSERT_TRUE(conn2 != nullptr); 3238 ASSERT_TRUE(conn2 != nullptr);
3229 conn2->ReceivedPing(); // Start receiving. 3239 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable and receiving.
3230 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); 3240 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
3231 EXPECT_EQ(conn2, ch.selected_connection()); 3241 EXPECT_EQ(conn2, ch.selected_connection());
3232 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. 3242 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3233 3243
3234 // Now another STUN message with an unknown address and use_candidate will 3244 // Now another STUN message with an unknown address and use_candidate will
3235 // nominate the selected connection. 3245 // nominate the selected connection.
3236 IceMessage request; 3246 IceMessage request;
3237 request.SetType(STUN_BINDING_REQUEST); 3247 request.SetType(STUN_BINDING_REQUEST);
3238 request.AddAttribute( 3248 request.AddAttribute(
3239 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3249 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3301 TestControlledAgentNominationTakesHigherPrecedenceThanDataReceiving) { 3311 TestControlledAgentNominationTakesHigherPrecedenceThanDataReceiving) {
3302 rtc::ScopedFakeClock clock; 3312 rtc::ScopedFakeClock clock;
3303 3313
3304 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3314 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3305 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); 3315 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
3306 PrepareChannel(&ch); 3316 PrepareChannel(&ch);
3307 ch.SetIceRole(ICEROLE_CONTROLLED); 3317 ch.SetIceRole(ICEROLE_CONTROLLED);
3308 ch.MaybeStartGathering(); 3318 ch.MaybeStartGathering();
3309 // The connections have decreasing priority. 3319 // The connections have decreasing priority.
3310 Connection* conn1 = 3320 Connection* conn1 =
3311 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); 3321 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true);
3312 ASSERT_TRUE(conn1 != nullptr); 3322 ASSERT_TRUE(conn1 != nullptr);
3313 Connection* conn2 = 3323 Connection* conn2 =
3314 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); 3324 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, true);
3315 ASSERT_TRUE(conn2 != nullptr); 3325 ASSERT_TRUE(conn2 != nullptr);
3316 3326
3317 // conn1 received data; it is the selected connection. 3327 // conn1 received data; it is the selected connection.
3318 // Advance the clock to have a non-zero last-data-receiving time. 3328 // Advance the clock to have a non-zero last-data-receiving time.
3319 SIMULATED_WAIT(false, 1, clock); 3329 SIMULATED_WAIT(false, 1, clock);
3320 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); 3330 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
3321 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); 3331 EXPECT_EQ(1, reset_selected_candidate_pair_switches());
3322 EXPECT_EQ(conn1, last_selected_candidate_pair()); 3332 EXPECT_EQ(conn1, last_selected_candidate_pair());
3323 3333
3324 // conn2 is nominated; it becomes the selected connection. 3334 // conn2 is nominated; it becomes the selected connection.
3325 NominateConnection(conn2); 3335 NominateConnection(conn2);
3326 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); 3336 EXPECT_EQ(1, reset_selected_candidate_pair_switches());
3327 EXPECT_EQ(conn2, last_selected_candidate_pair()); 3337 EXPECT_EQ(conn2, last_selected_candidate_pair());
3328 3338
3339 // conn1 is selected because it has higher priority and also nominated.
3329 NominateConnection(conn1); 3340 NominateConnection(conn1);
3330 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); 3341 EXPECT_EQ(1, reset_selected_candidate_pair_switches());
3331 EXPECT_EQ(conn1, last_selected_candidate_pair()); 3342 EXPECT_EQ(conn1, last_selected_candidate_pair());
3332 3343
3333 // conn2 received data more recently; it is selected now because it
3334 // received data more recently.
3335 SIMULATED_WAIT(false, 1, clock);
3336 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
3337 EXPECT_EQ(1, reset_selected_candidate_pair_switches());
3338 EXPECT_EQ(conn2, last_selected_candidate_pair());
Taylor Brandstetter 2016/08/08 23:01:05 Why were these expectations removed?
honghaiz3 2016/08/11 22:45:53 I thought it is kind of redundant with the previou
3339
3340 // Make sure sorting won't reselect candidate pair. 3344 // Make sure sorting won't reselect candidate pair.
3341 SIMULATED_WAIT(false, 10, clock); 3345 SIMULATED_WAIT(false, 10, clock);
3342 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); 3346 EXPECT_EQ(0, reset_selected_candidate_pair_switches());
3343 } 3347 }
3344 3348
3345 TEST_F(P2PTransportChannelPingTest, 3349 TEST_F(P2PTransportChannelPingTest,
3346 TestControlledAgentSelectsConnectionWithHigherNomination) { 3350 TestControlledAgentSelectsConnectionWithHigherNomination) {
3347 rtc::ScopedFakeClock clock; 3351 rtc::ScopedFakeClock clock;
3348 3352
3349 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3353 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3350 P2PTransportChannel ch("test", 1, &pa); 3354 P2PTransportChannel ch("test", 1, &pa);
3351 PrepareChannel(&ch); 3355 PrepareChannel(&ch);
3352 ch.SetIceRole(ICEROLE_CONTROLLED); 3356 ch.SetIceRole(ICEROLE_CONTROLLED);
3353 ch.MaybeStartGathering(); 3357 ch.MaybeStartGathering();
3354 // The connections have decreasing priority. 3358 // The connections have decreasing priority.
3355 Connection* conn1 = 3359 Connection* conn1 =
3356 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); 3360 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true);
3357 ASSERT_TRUE(conn1 != nullptr); 3361 ASSERT_TRUE(conn1 != nullptr);
3358 Connection* conn2 = 3362 Connection* conn2 =
3359 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); 3363 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, true);
3360 ASSERT_TRUE(conn2 != nullptr); 3364 ASSERT_TRUE(conn2 != nullptr);
3361 3365
3362 // conn1 is the selected connection because it has a higher priority, 3366 // conn1 is the selected connection because it has a higher priority,
3363 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(), 3367 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(),
3364 kDefaultTimeout, clock); 3368 kDefaultTimeout, clock);
3365 reset_selected_candidate_pair_switches(); 3369 reset_selected_candidate_pair_switches();
3366 3370
3367 // conn2 is nominated; it becomes selected. 3371 // conn2 is nominated; it becomes selected.
3368 NominateConnection(conn2); 3372 NominateConnection(conn2);
3369 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); 3373 EXPECT_EQ(1, reset_selected_candidate_pair_switches());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3412 ch.MaybeStartGathering(); 3416 ch.MaybeStartGathering();
3413 // The connections have decreasing priority. 3417 // The connections have decreasing priority.
3414 Connection* conn1 = 3418 Connection* conn1 =
3415 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); 3419 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false);
3416 ASSERT_TRUE(conn1 != nullptr); 3420 ASSERT_TRUE(conn1 != nullptr);
3417 Connection* conn2 = 3421 Connection* conn2 =
3418 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); 3422 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false);
3419 ASSERT_TRUE(conn2 != nullptr); 3423 ASSERT_TRUE(conn2 != nullptr);
3420 3424
3421 NominateConnection(conn1); 3425 NominateConnection(conn1);
3422 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); 3426 // There is no selected connection because no connection is writable.
3427 EXPECT_EQ(0, reset_selected_candidate_pair_switches());
3423 3428
3424 // conn2 becomes writable; it is selected even though it is not nominated. 3429 // conn2 becomes writable; it is selected even though it is not nominated.
3425 conn2->ReceivedPingResponse(LOW_RTT, "id"); 3430 conn2->ReceivedPingResponse(LOW_RTT, "id");
3426
3427 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), 3431 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(),
3428 kDefaultTimeout, clock); 3432 kDefaultTimeout, clock);
3429 EXPECT_EQ_SIMULATED_WAIT(conn2, last_selected_candidate_pair(), 3433 EXPECT_EQ_SIMULATED_WAIT(conn2, last_selected_candidate_pair(),
3430 kDefaultTimeout, clock); 3434 kDefaultTimeout, clock);
3431 3435
3432 // If conn1 is also writable, it will become selected. 3436 // If conn1 is also writable, it will become selected.
3433 conn1->ReceivedPingResponse(LOW_RTT, "id"); 3437 conn1->ReceivedPingResponse(LOW_RTT, "id");
3434 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), 3438 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(),
3435 kDefaultTimeout, clock); 3439 kDefaultTimeout, clock);
3436 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(), 3440 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3475 // Verify that a ping with the new ufrag can be received on the new 3479 // Verify that a ping with the new ufrag can be received on the new
3476 // connection. 3480 // connection.
3477 EXPECT_EQ(0, conn2->last_ping_received()); 3481 EXPECT_EQ(0, conn2->last_ping_received());
3478 ReceivePingOnConnection(conn2, kIceUfrag[2], 1 /* priority */); 3482 ReceivePingOnConnection(conn2, kIceUfrag[2], 1 /* priority */);
3479 EXPECT_TRUE(conn2->last_ping_received() > 0); 3483 EXPECT_TRUE(conn2->last_ping_received() > 0);
3480 } 3484 }
3481 3485
3482 // When the current selected connection is strong, lower-priority connections 3486 // When the current selected connection is strong, lower-priority connections
3483 // will be pruned. Otherwise, lower-priority connections are kept. 3487 // will be pruned. Otherwise, lower-priority connections are kept.
3484 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { 3488 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
3489 rtc::ScopedFakeClock clock;
3485 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3490 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3486 P2PTransportChannel ch("test channel", 1, &pa); 3491 P2PTransportChannel ch("test channel", 1, &pa);
3487 PrepareChannel(&ch); 3492 PrepareChannel(&ch);
3488 ch.SetIceRole(ICEROLE_CONTROLLED); 3493 ch.SetIceRole(ICEROLE_CONTROLLED);
3489 ch.MaybeStartGathering(); 3494 ch.MaybeStartGathering();
3490 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3495 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3491 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3496 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3492 ASSERT_TRUE(conn1 != nullptr); 3497 ASSERT_TRUE(conn1 != nullptr);
3493 EXPECT_EQ(conn1, ch.selected_connection()); 3498 EXPECT_EQ(nullptr, ch.selected_connection());
3494 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving 3499 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3495 3500
3496 // When a higher-priority, nominated candidate comes in, the connections with 3501 // When a higher-priority, nominated candidate comes in, the connections with
3497 // lower-priority are pruned. 3502 // lower-priority are pruned.
3498 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); 3503 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
3499 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3504 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock);
3500 ASSERT_TRUE(conn2 != nullptr); 3505 ASSERT_TRUE(conn2 != nullptr);
3501 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving 3506 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3502 NominateConnection(conn2); 3507 NominateConnection(conn2);
3503 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); 3508 EXPECT_TRUE_SIMULATED_WAIT(conn1->pruned(), 3000, clock);
3504 3509
3505 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); 3510 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE));
3506 // Wait until conn2 becomes not receiving. 3511 // Wait until conn2 becomes not receiving.
3507 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); 3512 EXPECT_TRUE_SIMULATED_WAIT(!conn2->receiving(), 3000, clock);
3508 3513
3509 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); 3514 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
3510 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3515 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3, &clock);
3511 ASSERT_TRUE(conn3 != nullptr); 3516 ASSERT_TRUE(conn3 != nullptr);
3512 // The selected connection should still be conn2. Even through conn3 has lower 3517 // The selected connection should still be conn2. Even through conn3 has lower
3513 // priority and is not receiving/writable, it is not pruned because the 3518 // priority and is not receiving/writable, it is not pruned because the
3514 // selected connection is not receiving. 3519 // selected connection is not receiving.
3515 WAIT(conn3->pruned(), 1000); 3520 SIMULATED_WAIT(conn3->pruned(), 1000, clock);
3516 EXPECT_FALSE(conn3->pruned()); 3521 EXPECT_FALSE(conn3->pruned());
3517 } 3522 }
3518 3523
3519 TEST_F(P2PTransportChannelPingTest, TestDontPruneHighPriorityConnections) { 3524 TEST_F(P2PTransportChannelPingTest, TestDontPruneHighPriorityConnections) {
3520 rtc::ScopedFakeClock clock; 3525 rtc::ScopedFakeClock clock;
3521 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3526 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3522 P2PTransportChannel ch("test channel", 1, &pa); 3527 P2PTransportChannel ch("test channel", 1, &pa);
3523 PrepareChannel(&ch); 3528 PrepareChannel(&ch);
3524 ch.SetIceRole(ICEROLE_CONTROLLED); 3529 ch.SetIceRole(ICEROLE_CONTROLLED);
3525 ch.MaybeStartGathering(); 3530 ch.MaybeStartGathering();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3558 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); 3563 EXPECT_TRUE_WAIT(conn2->pruned(), 1000);
3559 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3564 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3560 conn1->Prune(); // All connections are pruned. 3565 conn1->Prune(); // All connections are pruned.
3561 // Need to wait until the channel state is updated. 3566 // Need to wait until the channel state is updated.
3562 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); 3567 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000);
3563 } 3568 }
3564 3569
3565 // Test that when a low-priority connection is pruned, it is not deleted 3570 // Test that when a low-priority connection is pruned, it is not deleted
3566 // right away, and it can become active and be pruned again. 3571 // right away, and it can become active and be pruned again.
3567 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { 3572 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
3573 rtc::ScopedFakeClock clock;
3568 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3574 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3569 P2PTransportChannel ch("test channel", 1, &pa); 3575 P2PTransportChannel ch("test channel", 1, &pa);
3570 PrepareChannel(&ch); 3576 PrepareChannel(&ch);
3571 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); 3577 IceConfig config = CreateIceConfig(1000, GATHER_ONCE);
3572 config.receiving_switching_delay = rtc::Optional<int>(800); 3578 config.receiving_switching_delay = rtc::Optional<int>(800);
3573 ch.SetIceConfig(config); 3579 ch.SetIceConfig(config);
3574 ch.MaybeStartGathering(); 3580 ch.MaybeStartGathering();
3575 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3581 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3576 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3582 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
3577 ASSERT_TRUE(conn1 != nullptr); 3583 ASSERT_TRUE(conn1 != nullptr);
3578 EXPECT_EQ(conn1, ch.selected_connection()); 3584 EXPECT_EQ(nullptr, ch.selected_connection());
3579 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving 3585 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3586 EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout,
3587 clock);
3580 3588
3581 // Add a low-priority connection |conn2|, which will be pruned, but it will 3589 // Add a low-priority connection |conn2|, which will be pruned, but it will
3582 // not be deleted right away. Once the current selected connection becomes not 3590 // not be deleted right away. Once the current selected connection becomes not
3583 // receiving, |conn2| will start to ping and upon receiving the ping response, 3591 // receiving, |conn2| will start to ping and upon receiving the ping response,
3584 // it will become the selected connection. 3592 // it will become the selected connection.
3585 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3593 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3586 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3594 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock);
3587 ASSERT_TRUE(conn2 != nullptr); 3595 ASSERT_TRUE(conn2 != nullptr);
3588 EXPECT_TRUE_WAIT(!conn2->active(), 1000); 3596 EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock);
3589 // |conn2| should not send a ping yet. 3597 // |conn2| should not send a ping yet.
3590 EXPECT_EQ(Connection::STATE_WAITING, conn2->state()); 3598 EXPECT_EQ(Connection::STATE_WAITING, conn2->state());
3591 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3599 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3592 // Wait for |conn1| becoming not receiving. 3600 // Wait for |conn1| becoming not receiving.
3593 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); 3601 EXPECT_TRUE_SIMULATED_WAIT(!conn1->receiving(), 3000, clock);
3594 // Make sure conn2 is not deleted. 3602 // Make sure conn2 is not deleted.
3595 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3603 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock);
3596 ASSERT_TRUE(conn2 != nullptr); 3604 ASSERT_TRUE(conn2 != nullptr);
3597 EXPECT_EQ_WAIT(Connection::STATE_INPROGRESS, conn2->state(), 1000); 3605 EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_INPROGRESS, conn2->state(),
3606 kDefaultTimeout, clock);
3598 conn2->ReceivedPingResponse(LOW_RTT, "id"); 3607 conn2->ReceivedPingResponse(LOW_RTT, "id");
3599 EXPECT_EQ_WAIT(conn2, ch.selected_connection(), 1000); 3608 EXPECT_EQ_SIMULATED_WAIT(conn2, ch.selected_connection(), kDefaultTimeout,
3609 clock);
3600 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); 3610 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
3601 3611
3602 // When |conn1| comes back again, |conn2| will be pruned again. 3612 // When |conn1| comes back again, |conn2| will be pruned again.
3603 conn1->ReceivedPingResponse(LOW_RTT, "id"); 3613 conn1->ReceivedPingResponse(LOW_RTT, "id");
3604 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), 1000); 3614 EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout,
3605 EXPECT_TRUE_WAIT(!conn2->active(), 1000); 3615 clock);
3616 EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock);
3606 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3617 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3607 } 3618 }
3608 3619
3609 // Test that if all connections in a channel has timed out on writing, they 3620 // Test that if all connections in a channel has timed out on writing, they
3610 // will all be deleted. We use Prune to simulate write_time_out. 3621 // will all be deleted. We use Prune to simulate write_time_out.
3611 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { 3622 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
3612 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3623 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3613 P2PTransportChannel ch("test channel", 1, &pa); 3624 P2PTransportChannel ch("test channel", 1, &pa);
3614 PrepareChannel(&ch); 3625 PrepareChannel(&ch);
3615 ch.MaybeStartGathering(); 3626 ch.MaybeStartGathering();
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
3954 3965
3955 // TCP Relay/Relay is the next. 3966 // TCP Relay/Relay is the next.
3956 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 3967 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
3957 TCP_PROTOCOL_NAME); 3968 TCP_PROTOCOL_NAME);
3958 3969
3959 // Finally, Local/Relay will be pinged. 3970 // Finally, Local/Relay will be pinged.
3960 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 3971 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
3961 } 3972 }
3962 3973
3963 } // namespace cricket { 3974 } // namespace cricket {
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698