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

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

Issue 2431473004: Fix some flaky tests by using longer timeout and/or fake clock. (Closed)
Patch Set: . Created 4 years, 2 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 | « no previous file | webrtc/p2p/base/port_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 /* 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 23 matching lines...) Expand all
34 #include "webrtc/base/thread.h" 34 #include "webrtc/base/thread.h"
35 #include "webrtc/base/virtualsocketserver.h" 35 #include "webrtc/base/virtualsocketserver.h"
36 36
37 namespace { 37 namespace {
38 38
39 using rtc::SocketAddress; 39 using rtc::SocketAddress;
40 40
41 // Default timeout for tests in this file. 41 // Default timeout for tests in this file.
42 // Should be large enough for slow buildbots to run the tests reliably. 42 // Should be large enough for slow buildbots to run the tests reliably.
43 static const int kDefaultTimeout = 10000; 43 static const int kDefaultTimeout = 10000;
44 static const int kMediumTimeout = 3000;
45 static const int kShortTimeout = 1000;
44 46
45 static const int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN | 47 static const int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN |
46 cricket::PORTALLOCATOR_DISABLE_RELAY | 48 cricket::PORTALLOCATOR_DISABLE_RELAY |
47 cricket::PORTALLOCATOR_DISABLE_TCP; 49 cricket::PORTALLOCATOR_DISABLE_TCP;
48 static const int LOW_RTT = 20; 50 static const int LOW_RTT = 20;
49 // Addresses on the public internet. 51 // Addresses on the public internet.
50 static const SocketAddress kPublicAddrs[2] = 52 static const SocketAddress kPublicAddrs[2] =
51 { SocketAddress("11.11.11.11", 0), SocketAddress("22.22.22.22", 0) }; 53 { SocketAddress("11.11.11.11", 0), SocketAddress("22.22.22.22", 0) };
52 // IPv6 Addresses on the public internet. 54 // IPv6 Addresses on the public internet.
53 static const SocketAddress kIPv6PublicAddrs[2] = { 55 static const SocketAddress kIPv6PublicAddrs[2] = {
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 EXPECT_EQ(expected.controlled_protocol, local_protocol); 538 EXPECT_EQ(expected.controlled_protocol, local_protocol);
537 EXPECT_EQ(expected.controlling_protocol, remote_protocol); 539 EXPECT_EQ(expected.controlling_protocol, remote_protocol);
538 } 540 }
539 541
540 void Test(const Result& expected) { 542 void Test(const Result& expected) {
541 int64_t connect_start = rtc::TimeMillis(); 543 int64_t connect_start = rtc::TimeMillis();
542 int64_t connect_time; 544 int64_t connect_time;
543 545
544 // Create the channels and wait for them to connect. 546 // Create the channels and wait for them to connect.
545 CreateChannels(); 547 CreateChannels();
546 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && 548 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL &&
547 ep2_ch1() != NULL && 549 ep1_ch1()->receiving() &&
548 ep1_ch1()->receiving() && 550 ep1_ch1()->writable() &&
549 ep1_ch1()->writable() && 551 ep2_ch1()->receiving() && ep2_ch1()->writable(),
550 ep2_ch1()->receiving() && 552 expected.connect_wait, kShortTimeout);
551 ep2_ch1()->writable(),
552 expected.connect_wait,
553 1000);
554 connect_time = rtc::TimeMillis() - connect_start; 553 connect_time = rtc::TimeMillis() - connect_start;
555 if (connect_time < expected.connect_wait) { 554 if (connect_time < expected.connect_wait) {
556 LOG(LS_INFO) << "Connect time: " << connect_time << " ms"; 555 LOG(LS_INFO) << "Connect time: " << connect_time << " ms";
557 } else { 556 } else {
558 LOG(LS_INFO) << "Connect time: " << "TIMEOUT (" 557 LOG(LS_INFO) << "Connect time: " << "TIMEOUT ("
559 << expected.connect_wait << " ms)"; 558 << expected.connect_wait << " ms)";
560 } 559 }
561 560
562 // Allow a few turns of the crank for the selected connections to emerge. 561 // Allow a few turns of the crank for the selected connections to emerge.
563 // This may take up to 2 seconds. 562 // This may take up to 2 seconds.
(...skipping 25 matching lines...) Expand all
589 588
590 // Destroy the channels, and wait for them to be fully cleaned up. 589 // Destroy the channels, and wait for them to be fully cleaned up.
591 DestroyChannels(); 590 DestroyChannels();
592 } 591 }
593 592
594 void TestSendRecv() { 593 void TestSendRecv() {
595 for (int i = 0; i < 10; ++i) { 594 for (int i = 0; i < 10; ++i) {
596 const char* data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; 595 const char* data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
597 int len = static_cast<int>(strlen(data)); 596 int len = static_cast<int>(strlen(data));
598 // local_channel1 <==> remote_channel1 597 // local_channel1 <==> remote_channel1
599 EXPECT_EQ_WAIT(len, SendData(ep1_ch1(), data, len), 1000); 598 EXPECT_EQ_WAIT(len, SendData(ep1_ch1(), data, len), kMediumTimeout);
600 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch1(), data, len), 1000); 599 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch1(), data, len),
601 EXPECT_EQ_WAIT(len, SendData(ep2_ch1(), data, len), 1000); 600 kMediumTimeout);
602 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch1(), data, len), 1000); 601 EXPECT_EQ_WAIT(len, SendData(ep2_ch1(), data, len), kMediumTimeout);
602 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch1(), data, len),
603 kMediumTimeout);
603 } 604 }
604 } 605 }
605 606
606 // This test waits for the transport to become receiving and writable on both 607 // This test waits for the transport to become receiving and writable on both
607 // end points. Once they are, the end points set new local ice parameters and 608 // end points. Once they are, the end points set new local ice parameters and
608 // restart the ice gathering. Finally it waits for the transport to select a 609 // restart the ice gathering. Finally it waits for the transport to select a
609 // new connection using the newly generated ice candidates. 610 // new connection using the newly generated ice candidates.
610 // Before calling this function the end points must be configured. 611 // Before calling this function the end points must be configured.
611 void TestHandleIceUfragPasswordChanged() { 612 void TestHandleIceUfragPasswordChanged() {
612 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]); 613 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]);
613 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]); 614 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]);
614 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && 615 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
615 ep2_ch1()->receiving() && ep2_ch1()->writable(), 616 ep2_ch1()->receiving() && ep2_ch1()->writable(),
616 1000, 1000); 617 kShortTimeout, kShortTimeout);
617 618
618 const Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1()); 619 const Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1());
619 const Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1()); 620 const Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1());
620 const Candidate* old_remote_candidate1 = RemoteCandidate(ep1_ch1()); 621 const Candidate* old_remote_candidate1 = RemoteCandidate(ep1_ch1());
621 const Candidate* old_remote_candidate2 = RemoteCandidate(ep2_ch1()); 622 const Candidate* old_remote_candidate2 = RemoteCandidate(ep2_ch1());
622 623
623 ep1_ch1()->SetIceParameters(kIceParams[2]); 624 ep1_ch1()->SetIceParameters(kIceParams[2]);
624 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]); 625 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
625 ep1_ch1()->MaybeStartGathering(); 626 ep1_ch1()->MaybeStartGathering();
626 ep2_ch1()->SetIceParameters(kIceParams[3]); 627 ep2_ch1()->SetIceParameters(kIceParams[3]);
627 628
628 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]); 629 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]);
629 ep2_ch1()->MaybeStartGathering(); 630 ep2_ch1()->MaybeStartGathering();
630 631
631 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() != 632 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() !=
632 old_local_candidate1->generation(), 633 old_local_candidate1->generation(),
633 1000, 1000); 634 kShortTimeout, kShortTimeout);
634 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep2_ch1())->generation() != 635 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep2_ch1())->generation() !=
635 old_local_candidate2->generation(), 636 old_local_candidate2->generation(),
636 1000, 1000); 637 kShortTimeout, kShortTimeout);
637 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep1_ch1())->generation() != 638 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep1_ch1())->generation() !=
638 old_remote_candidate1->generation(), 639 old_remote_candidate1->generation(),
639 1000, 1000); 640 kShortTimeout, kShortTimeout);
640 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep2_ch1())->generation() != 641 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep2_ch1())->generation() !=
641 old_remote_candidate2->generation(), 642 old_remote_candidate2->generation(),
642 1000, 1000); 643 kShortTimeout, kShortTimeout);
643 EXPECT_EQ(1u, RemoteCandidate(ep2_ch1())->generation()); 644 EXPECT_EQ(1u, RemoteCandidate(ep2_ch1())->generation());
644 EXPECT_EQ(1u, RemoteCandidate(ep1_ch1())->generation()); 645 EXPECT_EQ(1u, RemoteCandidate(ep1_ch1())->generation());
645 } 646 }
646 647
647 void TestSignalRoleConflict() { 648 void TestSignalRoleConflict() {
648 SetIceTiebreaker(0, 649 SetIceTiebreaker(0,
649 kLowTiebreaker); // Default EP1 is in controlling state. 650 kLowTiebreaker); // Default EP1 is in controlling state.
650 651
651 SetIceRole(1, ICEROLE_CONTROLLING); 652 SetIceRole(1, ICEROLE_CONTROLLING);
652 SetIceTiebreaker(1, kHighTiebreaker); 653 SetIceTiebreaker(1, kHighTiebreaker);
653 654
654 // Creating channels with both channels role set to CONTROLLING. 655 // Creating channels with both channels role set to CONTROLLING.
655 CreateChannels(); 656 CreateChannels();
656 // Since both the channels initiated with controlling state and channel2 657 // Since both the channels initiated with controlling state and channel2
657 // has higher tiebreaker value, channel1 should receive SignalRoleConflict. 658 // has higher tiebreaker value, channel1 should receive SignalRoleConflict.
658 EXPECT_TRUE_WAIT(GetRoleConflict(0), 1000); 659 EXPECT_TRUE_WAIT(GetRoleConflict(0), kShortTimeout);
659 EXPECT_FALSE(GetRoleConflict(1)); 660 EXPECT_FALSE(GetRoleConflict(1));
660 661
661 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && 662 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
662 ep1_ch1()->writable() && 663 ep2_ch1()->receiving() && ep2_ch1()->writable(),
663 ep2_ch1()->receiving() && 664 kShortTimeout);
664 ep2_ch1()->writable(),
665 1000);
666 665
667 EXPECT_TRUE(ep1_ch1()->selected_connection() && 666 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
668 ep2_ch1()->selected_connection()); 667 ep2_ch1()->selected_connection());
669 668
670 TestSendRecv(); 669 TestSendRecv();
671 } 670 }
672 671
673 void OnReadyToSend(TransportChannel* ch) { 672 void OnReadyToSend(TransportChannel* ch) {
674 GetEndpoint(ch)->ready_to_send_ = true; 673 GetEndpoint(ch)->ready_to_send_ = true;
675 } 674 }
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 TestHandleIceUfragPasswordChanged(); 1152 TestHandleIceUfragPasswordChanged();
1154 DestroyChannels(); 1153 DestroyChannels();
1155 } 1154 }
1156 1155
1157 // Test the operation of GetStats. 1156 // Test the operation of GetStats.
1158 TEST_F(P2PTransportChannelTest, GetStats) { 1157 TEST_F(P2PTransportChannelTest, GetStats) {
1159 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1158 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1160 kDefaultPortAllocatorFlags); 1159 kDefaultPortAllocatorFlags);
1161 CreateChannels(); 1160 CreateChannels();
1162 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1161 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1163 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1162 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1164 1000, 1000); 1163 kShortTimeout, kShortTimeout);
1165 TestSendRecv(); 1164 TestSendRecv();
1166 ConnectionInfos infos; 1165 ConnectionInfos infos;
1167 ASSERT_TRUE(ep1_ch1()->GetStats(&infos)); 1166 ASSERT_TRUE(ep1_ch1()->GetStats(&infos));
1168 ASSERT_TRUE(infos.size() >= 1); 1167 ASSERT_TRUE(infos.size() >= 1);
1169 ConnectionInfo* best_conn_info = nullptr; 1168 ConnectionInfo* best_conn_info = nullptr;
1170 for (ConnectionInfo& info : infos) { 1169 for (ConnectionInfo& info : infos) {
1171 if (info.best_connection) { 1170 if (info.best_connection) {
1172 best_conn_info = &info; 1171 best_conn_info = &info;
1173 break; 1172 break;
1174 } 1173 }
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 CreateChannels(); 1358 CreateChannels();
1360 // Only have remote parameters come in for ep2, not ep1. 1359 // Only have remote parameters come in for ep2, not ep1.
1361 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]); 1360 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]);
1362 1361
1363 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive 1362 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive
1364 // candidate. 1363 // candidate.
1365 PauseCandidates(1); 1364 PauseCandidates(1);
1366 1365
1367 // Wait until the callee becomes writable to make sure that a ping request is 1366 // Wait until the callee becomes writable to make sure that a ping request is
1368 // received by the caller before his remote ICE credentials are set. 1367 // received by the caller before his remote ICE credentials are set.
1369 ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, 3000); 1368 ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, kMediumTimeout);
1370 // Add two sets of remote ICE credentials, so that the ones used by the 1369 // Add two sets of remote ICE credentials, so that the ones used by the
1371 // candidate will be generation 1 instead of 0. 1370 // candidate will be generation 1 instead of 0.
1372 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]); 1371 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
1373 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]); 1372 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]);
1374 // The caller should have the selected connection connected to the peer 1373 // The caller should have the selected connection connected to the peer
1375 // reflexive candidate. 1374 // reflexive candidate.
1376 const Connection* selected_connection = nullptr; 1375 const Connection* selected_connection = nullptr;
1377 ASSERT_TRUE_WAIT( 1376 ASSERT_TRUE_WAIT(
1378 (selected_connection = ep1_ch1()->selected_connection()) != nullptr, 1377 (selected_connection = ep1_ch1()->selected_connection()) != nullptr,
1379 2000); 1378 kMediumTimeout);
1380 EXPECT_EQ("prflx", selected_connection->remote_candidate().type()); 1379 EXPECT_EQ("prflx", selected_connection->remote_candidate().type());
1381 EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username()); 1380 EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username());
1382 EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password()); 1381 EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password());
1383 EXPECT_EQ(1u, selected_connection->remote_candidate().generation()); 1382 EXPECT_EQ(1u, selected_connection->remote_candidate().generation());
1384 1383
1385 ResumeCandidates(1); 1384 ResumeCandidates(1);
1386 // Verify ep1's selected connection is updated to use the 'local' candidate. 1385 // Verify ep1's selected connection is updated to use the 'local' candidate.
1387 EXPECT_EQ_WAIT("local", 1386 EXPECT_EQ_WAIT("local",
1388 ep1_ch1()->selected_connection()->remote_candidate().type(), 1387 ep1_ch1()->selected_connection()->remote_candidate().type(),
1389 2000); 1388 kMediumTimeout);
1390 EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection()); 1389 EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection());
1391 DestroyChannels(); 1390 DestroyChannels();
1392 } 1391 }
1393 1392
1394 // Test that we properly create a connection on a STUN ping from unknown address 1393 // Test that we properly create a connection on a STUN ping from unknown address
1395 // when the signaling is slow and the end points are behind NAT. 1394 // when the signaling is slow and the end points are behind NAT.
1396 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { 1395 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) {
1397 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, 1396 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags,
1398 kDefaultPortAllocatorFlags); 1397 kDefaultPortAllocatorFlags);
1399 // Emulate no remote parameters coming in. 1398 // Emulate no remote parameters coming in.
1400 set_remote_ice_parameter_source(FROM_CANDIDATE); 1399 set_remote_ice_parameter_source(FROM_CANDIDATE);
1401 CreateChannels(); 1400 CreateChannels();
1402 // Only have remote parameters come in for ep2, not ep1. 1401 // Only have remote parameters come in for ep2, not ep1.
1403 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]); 1402 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]);
1404 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive 1403 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive
1405 // candidate. 1404 // candidate.
1406 PauseCandidates(1); 1405 PauseCandidates(1);
1407 1406
1408 // Wait until the callee becomes writable to make sure that a ping request is 1407 // Wait until the callee becomes writable to make sure that a ping request is
1409 // received by the caller before his remote ICE credentials are set. 1408 // received by the caller before his remote ICE credentials are set.
1410 ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, 3000); 1409 ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, kMediumTimeout);
1411 // Add two sets of remote ICE credentials, so that the ones used by the 1410 // Add two sets of remote ICE credentials, so that the ones used by the
1412 // candidate will be generation 1 instead of 0. 1411 // candidate will be generation 1 instead of 0.
1413 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]); 1412 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
1414 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]); 1413 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]);
1415 1414
1416 // The caller's selected connection should be connected to the peer reflexive 1415 // The caller's selected connection should be connected to the peer reflexive
1417 // candidate. 1416 // candidate.
1418 const Connection* selected_connection = nullptr; 1417 const Connection* selected_connection = nullptr;
1419 ASSERT_TRUE_WAIT( 1418 ASSERT_TRUE_WAIT(
1420 (selected_connection = ep1_ch1()->selected_connection()) != nullptr, 1419 (selected_connection = ep1_ch1()->selected_connection()) != nullptr,
1421 2000); 1420 kMediumTimeout);
1422 EXPECT_EQ("prflx", selected_connection->remote_candidate().type()); 1421 EXPECT_EQ("prflx", selected_connection->remote_candidate().type());
1423 EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username()); 1422 EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username());
1424 EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password()); 1423 EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password());
1425 EXPECT_EQ(1u, selected_connection->remote_candidate().generation()); 1424 EXPECT_EQ(1u, selected_connection->remote_candidate().generation());
1426 1425
1427 ResumeCandidates(1); 1426 ResumeCandidates(1);
1428 1427
1429 EXPECT_EQ_WAIT("prflx", 1428 EXPECT_EQ_WAIT("prflx",
1430 ep1_ch1()->selected_connection()->remote_candidate().type(), 1429 ep1_ch1()->selected_connection()->remote_candidate().type(),
1431 2000); 1430 kMediumTimeout);
1432 EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection()); 1431 EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection());
1433 DestroyChannels(); 1432 DestroyChannels();
1434 } 1433 }
1435 1434
1436 // Test that we properly create a connection on a STUN ping from unknown address 1435 // Test that we properly create a connection on a STUN ping from unknown address
1437 // when the signaling is slow, even if the new candidate is created due to the 1436 // when the signaling is slow, even if the new candidate is created due to the
1438 // remote peer doing an ICE restart, pairing this candidate across generations. 1437 // remote peer doing an ICE restart, pairing this candidate across generations.
1439 // 1438 //
1440 // Previously this wasn't working due to a bug where the peer reflexive 1439 // Previously this wasn't working due to a bug where the peer reflexive
1441 // candidate was only updated for the newest generation candidate pairs, and 1440 // candidate was only updated for the newest generation candidate pairs, and
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 1487
1489 EXPECT_EQ_WAIT("relay", 1488 EXPECT_EQ_WAIT("relay",
1490 ep1_ch1()->selected_connection()->remote_candidate().type(), 1489 ep1_ch1()->selected_connection()->remote_candidate().type(),
1491 kDefaultTimeout); 1490 kDefaultTimeout);
1492 EXPECT_EQ(prflx_selected_connection, ep1_ch1()->selected_connection()); 1491 EXPECT_EQ(prflx_selected_connection, ep1_ch1()->selected_connection());
1493 DestroyChannels(); 1492 DestroyChannels();
1494 } 1493 }
1495 1494
1496 // Test that if remote candidates don't have ufrag and pwd, we still work. 1495 // Test that if remote candidates don't have ufrag and pwd, we still work.
1497 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) { 1496 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) {
1497 rtc::ScopedFakeClock clock;
1498 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS); 1498 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS);
1499 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1499 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1500 kDefaultPortAllocatorFlags); 1500 kDefaultPortAllocatorFlags);
1501 CreateChannels(); 1501 CreateChannels();
1502 const Connection* selected_connection = NULL; 1502 const Connection* selected_connection = NULL;
1503 // Wait until the callee's connections are created. 1503 // Wait until the callee's connections are created.
1504 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 1000); 1504 EXPECT_TRUE_SIMULATED_WAIT(
1505 // Wait to see if they get culled; they shouldn't. 1505 (selected_connection = ep2_ch1()->selected_connection()) != NULL,
1506 WAIT(ep2_ch1()->selected_connection() != selected_connection, 1000); 1506 kMediumTimeout, clock);
1507 // Wait to make sure the selected connection is not changed.
1508 SIMULATED_WAIT(ep2_ch1()->selected_connection() != selected_connection,
1509 kShortTimeout, clock);
1507 EXPECT_TRUE(ep2_ch1()->selected_connection() == selected_connection); 1510 EXPECT_TRUE(ep2_ch1()->selected_connection() == selected_connection);
1508 DestroyChannels(); 1511 DestroyChannels();
1509 } 1512 }
1510 1513
1511 // Test that a host behind NAT cannot be reached when incoming_only 1514 // Test that a host behind NAT cannot be reached when incoming_only
1512 // is set to true. 1515 // is set to true.
1513 TEST_F(P2PTransportChannelTest, IncomingOnlyBlocked) { 1516 TEST_F(P2PTransportChannelTest, IncomingOnlyBlocked) {
1514 ConfigureEndpoints(NAT_FULL_CONE, OPEN, kDefaultPortAllocatorFlags, 1517 ConfigureEndpoints(NAT_FULL_CONE, OPEN, kDefaultPortAllocatorFlags,
1515 kDefaultPortAllocatorFlags); 1518 kDefaultPortAllocatorFlags);
1516 1519
1517 SetAllocatorFlags(0, kOnlyLocalPorts); 1520 SetAllocatorFlags(0, kOnlyLocalPorts);
1518 CreateChannels(); 1521 CreateChannels();
1519 ep1_ch1()->set_incoming_only(true); 1522 ep1_ch1()->set_incoming_only(true);
1520 1523
1521 // Pump for 1 second and verify that the channels are not connected. 1524 // Pump for 1 second and verify that the channels are not connected.
1522 rtc::Thread::Current()->ProcessMessages(1000); 1525 rtc::Thread::Current()->ProcessMessages(kShortTimeout);
1523 1526
1524 EXPECT_FALSE(ep1_ch1()->receiving()); 1527 EXPECT_FALSE(ep1_ch1()->receiving());
1525 EXPECT_FALSE(ep1_ch1()->writable()); 1528 EXPECT_FALSE(ep1_ch1()->writable());
1526 EXPECT_FALSE(ep2_ch1()->receiving()); 1529 EXPECT_FALSE(ep2_ch1()->receiving());
1527 EXPECT_FALSE(ep2_ch1()->writable()); 1530 EXPECT_FALSE(ep2_ch1()->writable());
1528 1531
1529 DestroyChannels(); 1532 DestroyChannels();
1530 } 1533 }
1531 1534
1532 // Test that a peer behind NAT can connect to a peer that has 1535 // Test that a peer behind NAT can connect to a peer that has
1533 // incoming_only flag set. 1536 // incoming_only flag set.
1534 TEST_F(P2PTransportChannelTest, IncomingOnlyOpen) { 1537 TEST_F(P2PTransportChannelTest, IncomingOnlyOpen) {
1535 ConfigureEndpoints(OPEN, NAT_FULL_CONE, kDefaultPortAllocatorFlags, 1538 ConfigureEndpoints(OPEN, NAT_FULL_CONE, kDefaultPortAllocatorFlags,
1536 kDefaultPortAllocatorFlags); 1539 kDefaultPortAllocatorFlags);
1537 1540
1538 SetAllocatorFlags(0, kOnlyLocalPorts); 1541 SetAllocatorFlags(0, kOnlyLocalPorts);
1539 CreateChannels(); 1542 CreateChannels();
1540 ep1_ch1()->set_incoming_only(true); 1543 ep1_ch1()->set_incoming_only(true);
1541 1544
1542 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && 1545 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL &&
1543 ep1_ch1()->receiving() && ep1_ch1()->writable() && 1546 ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1544 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1547 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1545 1000, 1000); 1548 kShortTimeout, kShortTimeout);
1546 1549
1547 DestroyChannels(); 1550 DestroyChannels();
1548 } 1551 }
1549 1552
1550 TEST_F(P2PTransportChannelTest, TestTcpConnectionsFromActiveToPassive) { 1553 TEST_F(P2PTransportChannelTest, TestTcpConnectionsFromActiveToPassive) {
1551 AddAddress(0, kPublicAddrs[0]); 1554 AddAddress(0, kPublicAddrs[0]);
1552 AddAddress(1, kPublicAddrs[1]); 1555 AddAddress(1, kPublicAddrs[1]);
1553 1556
1554 SetAllocationStepDelay(0, kMinimumStepDelay); 1557 SetAllocationStepDelay(0, kMinimumStepDelay);
1555 SetAllocationStepDelay(1, kMinimumStepDelay); 1558 SetAllocationStepDelay(1, kMinimumStepDelay);
(...skipping 20 matching lines...) Expand all
1576 1579
1577 // Verify tcp candidates. 1580 // Verify tcp candidates.
1578 VerifySavedTcpCandidates(0, TCPTYPE_PASSIVE_STR); 1581 VerifySavedTcpCandidates(0, TCPTYPE_PASSIVE_STR);
1579 VerifySavedTcpCandidates(1, TCPTYPE_ACTIVE_STR); 1582 VerifySavedTcpCandidates(1, TCPTYPE_ACTIVE_STR);
1580 1583
1581 // Resume candidates. 1584 // Resume candidates.
1582 ResumeCandidates(0); 1585 ResumeCandidates(0);
1583 ResumeCandidates(1); 1586 ResumeCandidates(1);
1584 1587
1585 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1588 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1586 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1589 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1587 1000); 1590 kShortTimeout);
1588 EXPECT_TRUE(ep1_ch1()->selected_connection() && 1591 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
1589 ep2_ch1()->selected_connection() && 1592 ep2_ch1()->selected_connection() &&
1590 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 1593 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
1591 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 1594 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
1592 1595
1593 TestSendRecv(); 1596 TestSendRecv();
1594 DestroyChannels(); 1597 DestroyChannels();
1595 } 1598 }
1596 1599
1597 TEST_F(P2PTransportChannelTest, TestIceRoleConflict) { 1600 TEST_F(P2PTransportChannelTest, TestIceRoleConflict) {
(...skipping 10 matching lines...) Expand all
1608 1611
1609 // Give the first connection the higher tiebreaker so its role won't 1612 // Give the first connection the higher tiebreaker so its role won't
1610 // change unless we tell it to. 1613 // change unless we tell it to.
1611 SetIceRole(0, ICEROLE_CONTROLLING); 1614 SetIceRole(0, ICEROLE_CONTROLLING);
1612 SetIceTiebreaker(0, kHighTiebreaker); 1615 SetIceTiebreaker(0, kHighTiebreaker);
1613 SetIceRole(1, ICEROLE_CONTROLLING); 1616 SetIceRole(1, ICEROLE_CONTROLLING);
1614 SetIceTiebreaker(1, kLowTiebreaker); 1617 SetIceTiebreaker(1, kLowTiebreaker);
1615 1618
1616 CreateChannels(); 1619 CreateChannels();
1617 1620
1618 EXPECT_EQ_WAIT(2u, ep1_ch1()->ports().size(), 1000); 1621 EXPECT_EQ_WAIT(2u, ep1_ch1()->ports().size(), kShortTimeout);
1619 1622
1620 const std::vector<PortInterface*> ports_before = ep1_ch1()->ports(); 1623 const std::vector<PortInterface*> ports_before = ep1_ch1()->ports();
1621 for (size_t i = 0; i < ports_before.size(); ++i) { 1624 for (size_t i = 0; i < ports_before.size(); ++i) {
1622 EXPECT_EQ(ICEROLE_CONTROLLING, ports_before[i]->GetIceRole()); 1625 EXPECT_EQ(ICEROLE_CONTROLLING, ports_before[i]->GetIceRole());
1623 EXPECT_EQ(kHighTiebreaker, ports_before[i]->IceTiebreaker()); 1626 EXPECT_EQ(kHighTiebreaker, ports_before[i]->IceTiebreaker());
1624 } 1627 }
1625 1628
1626 ep1_ch1()->SetIceRole(ICEROLE_CONTROLLED); 1629 ep1_ch1()->SetIceRole(ICEROLE_CONTROLLED);
1627 ep1_ch1()->SetIceTiebreaker(kLowTiebreaker); 1630 ep1_ch1()->SetIceTiebreaker(kLowTiebreaker);
1628 1631
1629 const std::vector<PortInterface*> ports_after = ep1_ch1()->ports(); 1632 const std::vector<PortInterface*> ports_after = ep1_ch1()->ports();
1630 for (size_t i = 0; i < ports_after.size(); ++i) { 1633 for (size_t i = 0; i < ports_after.size(); ++i) {
1631 EXPECT_EQ(ICEROLE_CONTROLLED, ports_before[i]->GetIceRole()); 1634 EXPECT_EQ(ICEROLE_CONTROLLED, ports_before[i]->GetIceRole());
1632 // SetIceTiebreaker after ports have been created will fail. So expect the 1635 // SetIceTiebreaker after ports have been created will fail. So expect the
1633 // original value. 1636 // original value.
1634 EXPECT_EQ(kHighTiebreaker, ports_before[i]->IceTiebreaker()); 1637 EXPECT_EQ(kHighTiebreaker, ports_before[i]->IceTiebreaker());
1635 } 1638 }
1636 1639
1637 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && 1640 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1638 ep1_ch1()->writable() && 1641 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1639 ep2_ch1()->receiving() && 1642 kShortTimeout);
1640 ep2_ch1()->writable(),
1641 1000);
1642 1643
1643 EXPECT_TRUE(ep1_ch1()->selected_connection() && 1644 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
1644 ep2_ch1()->selected_connection()); 1645 ep2_ch1()->selected_connection());
1645 1646
1646 TestSendRecv(); 1647 TestSendRecv();
1647 DestroyChannels(); 1648 DestroyChannels();
1648 } 1649 }
1649 1650
1650 // Verify that we can set DSCP value and retrieve properly from P2PTC. 1651 // Verify that we can set DSCP value and retrieve properly from P2PTC.
1651 TEST_F(P2PTransportChannelTest, TestDefaultDscpValue) { 1652 TEST_F(P2PTransportChannelTest, TestDefaultDscpValue) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 SetAllocationStepDelay(0, kMinimumStepDelay); 1686 SetAllocationStepDelay(0, kMinimumStepDelay);
1686 SetAllocationStepDelay(1, kMinimumStepDelay); 1687 SetAllocationStepDelay(1, kMinimumStepDelay);
1687 1688
1688 // Enable IPv6 1689 // Enable IPv6
1689 SetAllocatorFlags(0, PORTALLOCATOR_ENABLE_IPV6); 1690 SetAllocatorFlags(0, PORTALLOCATOR_ENABLE_IPV6);
1690 SetAllocatorFlags(1, PORTALLOCATOR_ENABLE_IPV6); 1691 SetAllocatorFlags(1, PORTALLOCATOR_ENABLE_IPV6);
1691 1692
1692 CreateChannels(); 1693 CreateChannels();
1693 1694
1694 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1695 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1695 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1696 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1696 1000); 1697 kShortTimeout);
1697 EXPECT_TRUE( 1698 EXPECT_TRUE(
1698 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && 1699 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
1699 LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) && 1700 LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) &&
1700 RemoteCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[1])); 1701 RemoteCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[1]));
1701 1702
1702 TestSendRecv(); 1703 TestSendRecv();
1703 DestroyChannels(); 1704 DestroyChannels();
1704 } 1705 }
1705 1706
1706 // Testing forceful TURN connections. 1707 // Testing forceful TURN connections.
1707 TEST_F(P2PTransportChannelTest, TestForceTurn) { 1708 TEST_F(P2PTransportChannelTest, TestForceTurn) {
1708 ConfigureEndpoints( 1709 ConfigureEndpoints(
1709 NAT_PORT_RESTRICTED, NAT_SYMMETRIC, 1710 NAT_PORT_RESTRICTED, NAT_SYMMETRIC,
1710 kDefaultPortAllocatorFlags | PORTALLOCATOR_ENABLE_SHARED_SOCKET, 1711 kDefaultPortAllocatorFlags | PORTALLOCATOR_ENABLE_SHARED_SOCKET,
1711 kDefaultPortAllocatorFlags | PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1712 kDefaultPortAllocatorFlags | PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1712 set_force_relay(true); 1713 set_force_relay(true);
1713 1714
1714 SetAllocationStepDelay(0, kMinimumStepDelay); 1715 SetAllocationStepDelay(0, kMinimumStepDelay);
1715 SetAllocationStepDelay(1, kMinimumStepDelay); 1716 SetAllocationStepDelay(1, kMinimumStepDelay);
1716 1717
1717 CreateChannels(); 1718 CreateChannels();
1718 1719
1719 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1720 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1720 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1721 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1721 2000); 1722 kMediumTimeout);
1722 1723
1723 EXPECT_TRUE(ep1_ch1()->selected_connection() && 1724 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
1724 ep2_ch1()->selected_connection()); 1725 ep2_ch1()->selected_connection());
1725 1726
1726 EXPECT_EQ("relay", RemoteCandidate(ep1_ch1())->type()); 1727 EXPECT_EQ("relay", RemoteCandidate(ep1_ch1())->type());
1727 EXPECT_EQ("relay", LocalCandidate(ep1_ch1())->type()); 1728 EXPECT_EQ("relay", LocalCandidate(ep1_ch1())->type());
1728 EXPECT_EQ("relay", RemoteCandidate(ep2_ch1())->type()); 1729 EXPECT_EQ("relay", RemoteCandidate(ep2_ch1())->type());
1729 EXPECT_EQ("relay", LocalCandidate(ep2_ch1())->type()); 1730 EXPECT_EQ("relay", LocalCandidate(ep2_ch1())->type());
1730 1731
1731 TestSendRecv(); 1732 TestSendRecv();
1732 DestroyChannels(); 1733 DestroyChannels();
1733 } 1734 }
1734 1735
1735 // Test that if continual gathering is set to true, ICE gathering state will 1736 // Test that if continual gathering is set to true, ICE gathering state will
1736 // not change to "Complete", and vice versa. 1737 // not change to "Complete", and vice versa.
1737 TEST_F(P2PTransportChannelTest, TestContinualGathering) { 1738 TEST_F(P2PTransportChannelTest, TestContinualGathering) {
1739 rtc::ScopedFakeClock clock;
1738 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1740 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1739 kDefaultPortAllocatorFlags); 1741 kDefaultPortAllocatorFlags);
1740 SetAllocationStepDelay(0, kDefaultStepDelay); 1742 SetAllocationStepDelay(0, kDefaultStepDelay);
1741 SetAllocationStepDelay(1, kDefaultStepDelay); 1743 SetAllocationStepDelay(1, kDefaultStepDelay);
1742 IceConfig continual_gathering_config = 1744 IceConfig continual_gathering_config =
1743 CreateIceConfig(1000, GATHER_CONTINUALLY); 1745 CreateIceConfig(1000, GATHER_CONTINUALLY);
1744 // By default, ep2 does not gather continually. 1746 // By default, ep2 does not gather continually.
1745 IceConfig default_config; 1747 IceConfig default_config;
1746 CreateChannels(continual_gathering_config, default_config); 1748 CreateChannels(continual_gathering_config, default_config);
1747 1749
1748 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && 1750 EXPECT_TRUE_SIMULATED_WAIT(
1749 ep1_ch1()->receiving() && ep1_ch1()->writable() && 1751 ep1_ch1() != NULL && ep2_ch1() != NULL && ep1_ch1()->receiving() &&
1750 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1752 ep1_ch1()->writable() && ep2_ch1()->receiving() &&
1751 1000, 1000); 1753 ep2_ch1()->writable(),
1752 WAIT(IceGatheringState::kIceGatheringComplete == ep1_ch1()->gathering_state(), 1754 kMediumTimeout, clock);
1753 1000); 1755 SIMULATED_WAIT(
1756 IceGatheringState::kIceGatheringComplete == ep1_ch1()->gathering_state(),
1757 kShortTimeout, clock);
1754 EXPECT_EQ(IceGatheringState::kIceGatheringGathering, 1758 EXPECT_EQ(IceGatheringState::kIceGatheringGathering,
1755 ep1_ch1()->gathering_state()); 1759 ep1_ch1()->gathering_state());
1756 // By now, ep2 should have completed gathering. 1760 // By now, ep2 should have completed gathering.
1757 EXPECT_EQ(IceGatheringState::kIceGatheringComplete, 1761 EXPECT_EQ(IceGatheringState::kIceGatheringComplete,
1758 ep2_ch1()->gathering_state()); 1762 ep2_ch1()->gathering_state());
1759 1763
1760 DestroyChannels(); 1764 DestroyChannels();
1761 } 1765 }
1762 1766
1763 // Test that a connection succeeds when the P2PTransportChannel uses a pooled 1767 // Test that a connection succeeds when the P2PTransportChannel uses a pooled
1764 // PortAllocatorSession that has not yet finished gathering candidates. 1768 // PortAllocatorSession that has not yet finished gathering candidates.
1765 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionBeforeDoneGathering) { 1769 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionBeforeDoneGathering) {
1770 rtc::ScopedFakeClock clock;
1766 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1771 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1767 kDefaultPortAllocatorFlags); 1772 kDefaultPortAllocatorFlags);
1768 // First create a pooled session for each endpoint. 1773 // First create a pooled session for each endpoint.
1769 auto& allocator_1 = GetEndpoint(0)->allocator_; 1774 auto& allocator_1 = GetEndpoint(0)->allocator_;
1770 auto& allocator_2 = GetEndpoint(1)->allocator_; 1775 auto& allocator_2 = GetEndpoint(1)->allocator_;
1771 int pool_size = 1; 1776 int pool_size = 1;
1772 allocator_1->SetConfiguration(allocator_1->stun_servers(), 1777 allocator_1->SetConfiguration(allocator_1->stun_servers(),
1773 allocator_1->turn_servers(), pool_size, false); 1778 allocator_1->turn_servers(), pool_size, false);
1774 allocator_2->SetConfiguration(allocator_2->stun_servers(), 1779 allocator_2->SetConfiguration(allocator_2->stun_servers(),
1775 allocator_2->turn_servers(), pool_size, false); 1780 allocator_2->turn_servers(), pool_size, false);
1776 const PortAllocatorSession* pooled_session_1 = 1781 const PortAllocatorSession* pooled_session_1 =
1777 allocator_1->GetPooledSession(); 1782 allocator_1->GetPooledSession();
1778 const PortAllocatorSession* pooled_session_2 = 1783 const PortAllocatorSession* pooled_session_2 =
1779 allocator_2->GetPooledSession(); 1784 allocator_2->GetPooledSession();
1780 ASSERT_NE(nullptr, pooled_session_1); 1785 ASSERT_NE(nullptr, pooled_session_1);
1781 ASSERT_NE(nullptr, pooled_session_2); 1786 ASSERT_NE(nullptr, pooled_session_2);
1782 // Sanity check that pooled sessions haven't gathered anything yet. 1787 // Sanity check that pooled sessions haven't gathered anything yet.
1783 EXPECT_TRUE(pooled_session_1->ReadyPorts().empty()); 1788 EXPECT_TRUE(pooled_session_1->ReadyPorts().empty());
1784 EXPECT_TRUE(pooled_session_1->ReadyCandidates().empty()); 1789 EXPECT_TRUE(pooled_session_1->ReadyCandidates().empty());
1785 EXPECT_TRUE(pooled_session_2->ReadyPorts().empty()); 1790 EXPECT_TRUE(pooled_session_2->ReadyPorts().empty());
1786 EXPECT_TRUE(pooled_session_2->ReadyCandidates().empty()); 1791 EXPECT_TRUE(pooled_session_2->ReadyCandidates().empty());
1787 // Now let the endpoints connect and try exchanging some data. 1792 // Now let the endpoints connect and try exchanging some data.
1788 CreateChannels(); 1793 CreateChannels();
1789 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && 1794 EXPECT_TRUE_SIMULATED_WAIT(
1790 ep1_ch1()->receiving() && ep1_ch1()->writable() && 1795 ep1_ch1() != NULL && ep2_ch1() != NULL && ep1_ch1()->receiving() &&
1791 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1796 ep1_ch1()->writable() && ep2_ch1()->receiving() &&
1792 1000, 1000); 1797 ep2_ch1()->writable(),
1798 kMediumTimeout, clock);
1793 TestSendRecv(); 1799 TestSendRecv();
1794 // Make sure the P2PTransportChannels are actually using ports from the 1800 // Make sure the P2PTransportChannels are actually using ports from the
1795 // pooled sessions. 1801 // pooled sessions.
1796 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); 1802 auto pooled_ports_1 = pooled_session_1->ReadyPorts();
1797 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); 1803 auto pooled_ports_2 = pooled_session_2->ReadyPorts();
1798 EXPECT_NE(pooled_ports_1.end(), 1804 EXPECT_NE(pooled_ports_1.end(),
1799 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), 1805 std::find(pooled_ports_1.begin(), pooled_ports_1.end(),
1800 ep1_ch1()->selected_connection()->port())); 1806 ep1_ch1()->selected_connection()->port()));
1801 EXPECT_NE(pooled_ports_2.end(), 1807 EXPECT_NE(pooled_ports_2.end(),
1802 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), 1808 std::find(pooled_ports_2.begin(), pooled_ports_2.end(),
1803 ep2_ch1()->selected_connection()->port())); 1809 ep2_ch1()->selected_connection()->port()));
1804 } 1810 }
1805 1811
1806 // Test that a connection succeeds when the P2PTransportChannel uses a pooled 1812 // Test that a connection succeeds when the P2PTransportChannel uses a pooled
1807 // PortAllocatorSession that already finished gathering candidates. 1813 // PortAllocatorSession that already finished gathering candidates.
1808 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionAfterDoneGathering) { 1814 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionAfterDoneGathering) {
1815 rtc::ScopedFakeClock clock;
1809 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1816 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1810 kDefaultPortAllocatorFlags); 1817 kDefaultPortAllocatorFlags);
1811 // First create a pooled session for each endpoint. 1818 // First create a pooled session for each endpoint.
1812 auto& allocator_1 = GetEndpoint(0)->allocator_; 1819 auto& allocator_1 = GetEndpoint(0)->allocator_;
1813 auto& allocator_2 = GetEndpoint(1)->allocator_; 1820 auto& allocator_2 = GetEndpoint(1)->allocator_;
1814 int pool_size = 1; 1821 int pool_size = 1;
1815 allocator_1->SetConfiguration(allocator_1->stun_servers(), 1822 allocator_1->SetConfiguration(allocator_1->stun_servers(),
1816 allocator_1->turn_servers(), pool_size, false); 1823 allocator_1->turn_servers(), pool_size, false);
1817 allocator_2->SetConfiguration(allocator_2->stun_servers(), 1824 allocator_2->SetConfiguration(allocator_2->stun_servers(),
1818 allocator_2->turn_servers(), pool_size, false); 1825 allocator_2->turn_servers(), pool_size, false);
1819 const PortAllocatorSession* pooled_session_1 = 1826 const PortAllocatorSession* pooled_session_1 =
1820 allocator_1->GetPooledSession(); 1827 allocator_1->GetPooledSession();
1821 const PortAllocatorSession* pooled_session_2 = 1828 const PortAllocatorSession* pooled_session_2 =
1822 allocator_2->GetPooledSession(); 1829 allocator_2->GetPooledSession();
1823 ASSERT_NE(nullptr, pooled_session_1); 1830 ASSERT_NE(nullptr, pooled_session_1);
1824 ASSERT_NE(nullptr, pooled_session_2); 1831 ASSERT_NE(nullptr, pooled_session_2);
1825 // Wait for the pooled sessions to finish gathering before the 1832 // Wait for the pooled sessions to finish gathering before the
1826 // P2PTransportChannels try to use them. 1833 // P2PTransportChannels try to use them.
1827 EXPECT_TRUE_WAIT(pooled_session_1->CandidatesAllocationDone() && 1834 EXPECT_TRUE_SIMULATED_WAIT(pooled_session_1->CandidatesAllocationDone() &&
1828 pooled_session_2->CandidatesAllocationDone(), 1835 pooled_session_2->CandidatesAllocationDone(),
1829 kDefaultTimeout); 1836 kDefaultTimeout, clock);
1830 // Now let the endpoints connect and try exchanging some data. 1837 // Now let the endpoints connect and try exchanging some data.
1831 CreateChannels(); 1838 CreateChannels();
1832 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && 1839 EXPECT_TRUE_SIMULATED_WAIT(
1833 ep1_ch1()->receiving() && ep1_ch1()->writable() && 1840 ep1_ch1() != NULL && ep2_ch1() != NULL && ep1_ch1()->receiving() &&
1834 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1841 ep1_ch1()->writable() && ep2_ch1()->receiving() &&
1835 1000, 1000); 1842 ep2_ch1()->writable(),
1843 kMediumTimeout, clock);
1836 TestSendRecv(); 1844 TestSendRecv();
1837 // Make sure the P2PTransportChannels are actually using ports from the 1845 // Make sure the P2PTransportChannels are actually using ports from the
1838 // pooled sessions. 1846 // pooled sessions.
1839 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); 1847 auto pooled_ports_1 = pooled_session_1->ReadyPorts();
1840 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); 1848 auto pooled_ports_2 = pooled_session_2->ReadyPorts();
1841 EXPECT_NE(pooled_ports_1.end(), 1849 EXPECT_NE(pooled_ports_1.end(),
1842 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), 1850 std::find(pooled_ports_1.begin(), pooled_ports_1.end(),
1843 ep1_ch1()->selected_connection()->port())); 1851 ep1_ch1()->selected_connection()->port()));
1844 EXPECT_NE(pooled_ports_2.end(), 1852 EXPECT_NE(pooled_ports_2.end(),
1845 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), 1853 std::find(pooled_ports_2.begin(), pooled_ports_2.end(),
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1911 ep1_ch1()->SetIceConfig(config); 1919 ep1_ch1()->SetIceConfig(config);
1912 ep2_ch1()->SetIceConfig(config); 1920 ep2_ch1()->SetIceConfig(config);
1913 // Don't signal candidates from channel 2, so that channel 1 sees the TURN 1921 // Don't signal candidates from channel 2, so that channel 1 sees the TURN
1914 // candidate as peer reflexive. 1922 // candidate as peer reflexive.
1915 PauseCandidates(1); 1923 PauseCandidates(1);
1916 ep1_ch1()->MaybeStartGathering(); 1924 ep1_ch1()->MaybeStartGathering();
1917 ep2_ch1()->MaybeStartGathering(); 1925 ep2_ch1()->MaybeStartGathering();
1918 1926
1919 // Wait for the TURN<->prflx connection. 1927 // Wait for the TURN<->prflx connection.
1920 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable(), 1928 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable(),
1921 1000, fake_clock); 1929 kShortTimeout, fake_clock);
1922 ASSERT_NE(nullptr, ep1_ch1()->selected_connection()); 1930 ASSERT_NE(nullptr, ep1_ch1()->selected_connection());
1923 EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type()); 1931 EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type());
1924 EXPECT_EQ(PRFLX_PORT_TYPE, RemoteCandidate(ep1_ch1())->type()); 1932 EXPECT_EQ(PRFLX_PORT_TYPE, RemoteCandidate(ep1_ch1())->type());
1925 // Make sure that at this point the connection is only presumed writable, 1933 // Make sure that at this point the connection is only presumed writable,
1926 // not fully writable. 1934 // not fully writable.
1927 EXPECT_FALSE(ep1_ch1()->selected_connection()->writable()); 1935 EXPECT_FALSE(ep1_ch1()->selected_connection()->writable());
1928 1936
1929 // Now wait for it to actually become writable. 1937 // Now wait for it to actually become writable.
1930 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->writable(), 1000, 1938 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->writable(),
1931 fake_clock); 1939 kShortTimeout, fake_clock);
1932 1940
1933 // Explitly destroy channels, before fake clock is destroyed. 1941 // Explitly destroy channels, before fake clock is destroyed.
1934 DestroyChannels(); 1942 DestroyChannels();
1935 } 1943 }
1936 1944
1937 // Test that a presumed-writable TURN<->TURN connection is preferred above an 1945 // Test that a presumed-writable TURN<->TURN connection is preferred above an
1938 // unreliable connection (one that has failed to be pinged for some time). 1946 // unreliable connection (one that has failed to be pinged for some time).
1939 TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) { 1947 TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) {
1940 rtc::ScopedFakeClock fake_clock; 1948 rtc::ScopedFakeClock fake_clock;
1941 1949
1942 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, 1950 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags,
1943 kDefaultPortAllocatorFlags); 1951 kDefaultPortAllocatorFlags);
1944 IceConfig config; 1952 IceConfig config;
1945 config.presume_writable_when_fully_relayed = true; 1953 config.presume_writable_when_fully_relayed = true;
1946 GetEndpoint(0)->cd1_.ch_.reset(CreateChannel( 1954 GetEndpoint(0)->cd1_.ch_.reset(CreateChannel(
1947 0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[0], kIceParams[1])); 1955 0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[0], kIceParams[1]));
1948 GetEndpoint(1)->cd1_.ch_.reset(CreateChannel( 1956 GetEndpoint(1)->cd1_.ch_.reset(CreateChannel(
1949 1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[1], kIceParams[0])); 1957 1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[1], kIceParams[0]));
1950 ep1_ch1()->SetIceConfig(config); 1958 ep1_ch1()->SetIceConfig(config);
1951 ep2_ch1()->SetIceConfig(config); 1959 ep2_ch1()->SetIceConfig(config);
1952 ep1_ch1()->MaybeStartGathering(); 1960 ep1_ch1()->MaybeStartGathering();
1953 ep2_ch1()->MaybeStartGathering(); 1961 ep2_ch1()->MaybeStartGathering();
1954 // Wait for initial connection as usual. 1962 // Wait for initial connection as usual.
1955 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1963 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1956 ep1_ch1()->selected_connection()->writable() && 1964 ep1_ch1()->selected_connection()->writable() &&
1957 ep2_ch1()->receiving() && 1965 ep2_ch1()->receiving() &&
1958 ep2_ch1()->writable() && 1966 ep2_ch1()->writable() &&
1959 ep2_ch1()->selected_connection()->writable(), 1967 ep2_ch1()->selected_connection()->writable(),
1960 1000, fake_clock); 1968 kShortTimeout, fake_clock);
1961 const Connection* old_selected_connection = ep1_ch1()->selected_connection(); 1969 const Connection* old_selected_connection = ep1_ch1()->selected_connection();
1962 // Destroy the second channel and wait for the current connection on the 1970 // Destroy the second channel and wait for the current connection on the
1963 // first channel to become "unreliable", making it no longer writable. 1971 // first channel to become "unreliable", making it no longer writable.
1964 GetEndpoint(1)->cd1_.ch_.reset(); 1972 GetEndpoint(1)->cd1_.ch_.reset();
1965 EXPECT_TRUE_SIMULATED_WAIT(!ep1_ch1()->writable(), 10000, fake_clock); 1973 EXPECT_TRUE_SIMULATED_WAIT(!ep1_ch1()->writable(), kDefaultTimeout,
1974 fake_clock);
1966 EXPECT_NE(nullptr, ep1_ch1()->selected_connection()); 1975 EXPECT_NE(nullptr, ep1_ch1()->selected_connection());
1967 // Add a remote TURN candidate. The first channel should still have a TURN 1976 // Add a remote TURN candidate. The first channel should still have a TURN
1968 // port available to make a TURN<->TURN pair that's presumed writable. 1977 // port available to make a TURN<->TURN pair that's presumed writable.
1969 ep1_ch1()->AddRemoteCandidate( 1978 ep1_ch1()->AddRemoteCandidate(
1970 CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 0)); 1979 CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 0));
1971 EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type()); 1980 EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type());
1972 EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type()); 1981 EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type());
1973 EXPECT_TRUE(ep1_ch1()->writable()); 1982 EXPECT_TRUE(ep1_ch1()->writable());
1974 EXPECT_TRUE(GetEndpoint(0)->ready_to_send_); 1983 EXPECT_TRUE(GetEndpoint(0)->ready_to_send_);
1975 EXPECT_NE(old_selected_connection, ep1_ch1()->selected_connection()); 1984 EXPECT_NE(old_selected_connection, ep1_ch1()->selected_connection());
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2110 SetAllocatorFlags(1, kOnlyLocalPorts); 2119 SetAllocatorFlags(1, kOnlyLocalPorts);
2111 2120
2112 // Make the receiving timeout shorter for testing. 2121 // Make the receiving timeout shorter for testing.
2113 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); 2122 IceConfig config = CreateIceConfig(1000, GATHER_ONCE);
2114 // Create channels and let them go writable, as usual. 2123 // Create channels and let them go writable, as usual.
2115 CreateChannels(config, config); 2124 CreateChannels(config, config);
2116 2125
2117 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2126 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2118 ep2_ch1()->receiving() && 2127 ep2_ch1()->receiving() &&
2119 ep2_ch1()->writable(), 2128 ep2_ch1()->writable(),
2120 3000, clock); 2129 kMediumTimeout, clock);
2121 EXPECT_TRUE(ep1_ch1()->selected_connection() && 2130 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
2122 ep2_ch1()->selected_connection() && 2131 ep2_ch1()->selected_connection() &&
2123 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 2132 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
2124 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 2133 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
2125 2134
2126 // Blackhole any traffic to or from the public addrs. 2135 // Blackhole any traffic to or from the public addrs.
2127 LOG(LS_INFO) << "Failing over..."; 2136 LOG(LS_INFO) << "Failing over...";
2128 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); 2137 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]);
2129 // The selected connections may switch, so keep references to them. 2138 // The selected connections may switch, so keep references to them.
2130 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); 2139 const Connection* selected_connection1 = ep1_ch1()->selected_connection();
2131 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); 2140 const Connection* selected_connection2 = ep2_ch1()->selected_connection();
2132 // We should detect loss of receiving within 1 second or so. 2141 // We should detect loss of receiving within 1 second or so.
2133 EXPECT_TRUE_SIMULATED_WAIT( 2142 EXPECT_TRUE_SIMULATED_WAIT(
2134 !selected_connection1->receiving() && !selected_connection2->receiving(), 2143 !selected_connection1->receiving() && !selected_connection2->receiving(),
2135 3000, clock); 2144 kMediumTimeout, clock);
2136 2145
2137 // We should switch over to use the alternate addr on both sides 2146 // We should switch over to use the alternate addr on both sides
2138 // when we are not receiving. 2147 // when we are not receiving.
2139 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() && 2148 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() &&
2140 ep2_ch1()->selected_connection()->receiving(), 2149 ep2_ch1()->selected_connection()->receiving(),
2141 3000, clock); 2150 kMediumTimeout, clock);
2142 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); 2151 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]));
2143 EXPECT_TRUE( 2152 EXPECT_TRUE(
2144 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1])); 2153 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]));
2145 EXPECT_TRUE( 2154 EXPECT_TRUE(
2146 LocalCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[1])); 2155 LocalCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[1]));
2147 2156
2148 DestroyChannels(); 2157 DestroyChannels();
2149 } 2158 }
2150 2159
2151 // Test that we can quickly switch links if an interface goes down. 2160 // Test that we can quickly switch links if an interface goes down.
(...skipping 10 matching lines...) Expand all
2162 SetAllocatorFlags(0, kOnlyLocalPorts); 2171 SetAllocatorFlags(0, kOnlyLocalPorts);
2163 SetAllocatorFlags(1, kOnlyLocalPorts); 2172 SetAllocatorFlags(1, kOnlyLocalPorts);
2164 2173
2165 // Make the receiving timeout shorter for testing. 2174 // Make the receiving timeout shorter for testing.
2166 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); 2175 IceConfig config = CreateIceConfig(1000, GATHER_ONCE);
2167 // Create channels and let them go writable, as usual. 2176 // Create channels and let them go writable, as usual.
2168 CreateChannels(config, config); 2177 CreateChannels(config, config);
2169 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2178 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2170 ep2_ch1()->receiving() && 2179 ep2_ch1()->receiving() &&
2171 ep2_ch1()->writable(), 2180 ep2_ch1()->writable(),
2172 3000, clock); 2181 kMediumTimeout, clock);
2173 EXPECT_TRUE(ep1_ch1()->selected_connection() && 2182 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
2174 ep2_ch1()->selected_connection() && 2183 ep2_ch1()->selected_connection() &&
2175 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 2184 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
2176 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 2185 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
2177 2186
2178 // Blackhole any traffic to or from the public addrs. 2187 // Blackhole any traffic to or from the public addrs.
2179 LOG(LS_INFO) << "Failing over..."; 2188 LOG(LS_INFO) << "Failing over...";
2180 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); 2189 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]);
2181 // The selected connections will switch, so keep references to them. 2190 // The selected connections will switch, so keep references to them.
2182 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); 2191 const Connection* selected_connection1 = ep1_ch1()->selected_connection();
2183 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); 2192 const Connection* selected_connection2 = ep2_ch1()->selected_connection();
2184 // We should detect loss of receiving within 1 second or so. 2193 // We should detect loss of receiving within 1 second or so.
2185 EXPECT_TRUE_SIMULATED_WAIT( 2194 EXPECT_TRUE_SIMULATED_WAIT(
2186 !selected_connection1->receiving() && !selected_connection2->receiving(), 2195 !selected_connection1->receiving() && !selected_connection2->receiving(),
2187 3000, clock); 2196 kMediumTimeout, clock);
2188 2197
2189 // We should switch over to use the alternate addr on both sides 2198 // We should switch over to use the alternate addr on both sides
2190 // when we are not receiving. 2199 // when we are not receiving.
2191 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() && 2200 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() &&
2192 ep2_ch1()->selected_connection()->receiving(), 2201 ep2_ch1()->selected_connection()->receiving(),
2193 3000, clock); 2202 kMediumTimeout, clock);
2194 EXPECT_TRUE( 2203 EXPECT_TRUE(
2195 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); 2204 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]));
2196 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 2205 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
2197 EXPECT_TRUE( 2206 EXPECT_TRUE(
2198 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); 2207 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0]));
2199 2208
2200 DestroyChannels(); 2209 DestroyChannels();
2201 } 2210 }
2202 2211
2203 // Test that when the controlling side switches the selected connection, 2212 // Test that when the controlling side switches the selected connection,
(...skipping 13 matching lines...) Expand all
2217 2226
2218 // We want it to set the remote ICE parameters when creating channels. 2227 // We want it to set the remote ICE parameters when creating channels.
2219 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS); 2228 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS);
2220 // Make the receiving timeout shorter for testing. 2229 // Make the receiving timeout shorter for testing.
2221 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); 2230 IceConfig config = CreateIceConfig(1000, GATHER_ONCE);
2222 // Create channels with ICE renomination and let them go writable as usual. 2231 // Create channels with ICE renomination and let them go writable as usual.
2223 CreateChannels(config, config, true); 2232 CreateChannels(config, config, true);
2224 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2233 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2225 ep2_ch1()->receiving() && 2234 ep2_ch1()->receiving() &&
2226 ep2_ch1()->writable(), 2235 ep2_ch1()->writable(),
2227 3000, clock); 2236 kMediumTimeout, clock);
2228 EXPECT_TRUE_SIMULATED_WAIT( 2237 EXPECT_TRUE_SIMULATED_WAIT(
2229 ep2_ch1()->selected_connection()->remote_nomination() > 0 && 2238 ep2_ch1()->selected_connection()->remote_nomination() > 0 &&
2230 ep1_ch1()->selected_connection()->acked_nomination() > 0, 2239 ep1_ch1()->selected_connection()->acked_nomination() > 0,
2231 kDefaultTimeout, clock); 2240 kDefaultTimeout, clock);
2232 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); 2241 const Connection* selected_connection1 = ep1_ch1()->selected_connection();
2233 Connection* selected_connection2 = 2242 Connection* selected_connection2 =
2234 const_cast<Connection*>(ep2_ch1()->selected_connection()); 2243 const_cast<Connection*>(ep2_ch1()->selected_connection());
2235 uint32_t remote_nomination2 = selected_connection2->remote_nomination(); 2244 uint32_t remote_nomination2 = selected_connection2->remote_nomination();
2236 // |selected_connection2| should not be nominated any more since the previous 2245 // |selected_connection2| should not be nominated any more since the previous
2237 // nomination has been acknowledged. 2246 // nomination has been acknowledged.
2238 ConnectSignalNominated(selected_connection2); 2247 ConnectSignalNominated(selected_connection2);
2239 SIMULATED_WAIT(nominated(), 3000, clock); 2248 SIMULATED_WAIT(nominated(), kMediumTimeout, clock);
2240 EXPECT_FALSE(nominated()); 2249 EXPECT_FALSE(nominated());
2241 2250
2242 // Blackhole any traffic to or from the public addrs. 2251 // Blackhole any traffic to or from the public addrs.
2243 LOG(LS_INFO) << "Failing over..."; 2252 LOG(LS_INFO) << "Failing over...";
2244 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); 2253 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]);
2245 2254
2246 // The selected connection on the controlling side should switch. 2255 // The selected connection on the controlling side should switch.
2247 EXPECT_TRUE_SIMULATED_WAIT( 2256 EXPECT_TRUE_SIMULATED_WAIT(
2248 ep1_ch1()->selected_connection() != selected_connection1, 3000, clock); 2257 ep1_ch1()->selected_connection() != selected_connection1, kMediumTimeout,
2258 clock);
2249 // The connection on the controlled side should be nominated again 2259 // The connection on the controlled side should be nominated again
2250 // and have an increased nomination. 2260 // and have an increased nomination.
2251 EXPECT_TRUE_SIMULATED_WAIT( 2261 EXPECT_TRUE_SIMULATED_WAIT(
2252 ep2_ch1()->selected_connection()->remote_nomination() > 2262 ep2_ch1()->selected_connection()->remote_nomination() >
2253 remote_nomination2, 2263 remote_nomination2,
2254 kDefaultTimeout, clock); 2264 kDefaultTimeout, clock);
2255 2265
2256 DestroyChannels(); 2266 DestroyChannels();
2257 } 2267 }
2258 2268
(...skipping 14 matching lines...) Expand all
2273 // Use only local ports for simplicity. 2283 // Use only local ports for simplicity.
2274 SetAllocatorFlags(0, kOnlyLocalPorts); 2284 SetAllocatorFlags(0, kOnlyLocalPorts);
2275 SetAllocatorFlags(1, kOnlyLocalPorts); 2285 SetAllocatorFlags(1, kOnlyLocalPorts);
2276 2286
2277 // Create channels and let them go writable, as usual. 2287 // Create channels and let them go writable, as usual.
2278 CreateChannels(); 2288 CreateChannels();
2279 2289
2280 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2290 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2281 ep2_ch1()->receiving() && 2291 ep2_ch1()->receiving() &&
2282 ep2_ch1()->writable(), 2292 ep2_ch1()->writable(),
2283 3000, clock); 2293 kMediumTimeout, clock);
2284 EXPECT_TRUE(ep1_ch1()->selected_connection() && 2294 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
2285 ep2_ch1()->selected_connection() && 2295 ep2_ch1()->selected_connection() &&
2286 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 2296 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
2287 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 2297 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
2288 2298
2289 // Make the receiving timeout shorter for testing. 2299 // Make the receiving timeout shorter for testing.
2290 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); 2300 IceConfig config = CreateIceConfig(1000, GATHER_ONCE);
2291 ep1_ch1()->SetIceConfig(config); 2301 ep1_ch1()->SetIceConfig(config);
2292 ep2_ch1()->SetIceConfig(config); 2302 ep2_ch1()->SetIceConfig(config);
2293 reset_selected_candidate_pair_switches(); 2303 reset_selected_candidate_pair_switches();
2294 2304
2295 // Blackhole any traffic to or from the public addrs. 2305 // Blackhole any traffic to or from the public addrs.
2296 LOG(LS_INFO) << "Failing over..."; 2306 LOG(LS_INFO) << "Failing over...";
2297 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); 2307 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]);
2298 2308
2299 // The selected connections may switch, so keep references to them. 2309 // The selected connections may switch, so keep references to them.
2300 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); 2310 const Connection* selected_connection1 = ep1_ch1()->selected_connection();
2301 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); 2311 const Connection* selected_connection2 = ep2_ch1()->selected_connection();
2302 // We should detect loss of receiving within 1 second or so. 2312 // We should detect loss of receiving within 1 second or so.
2303 EXPECT_TRUE_SIMULATED_WAIT( 2313 EXPECT_TRUE_SIMULATED_WAIT(
2304 !selected_connection1->receiving() && !selected_connection2->receiving(), 2314 !selected_connection1->receiving() && !selected_connection2->receiving(),
2305 3000, clock); 2315 kMediumTimeout, clock);
2306 // After a short while, the link recovers itself. 2316 // After a short while, the link recovers itself.
2307 SIMULATED_WAIT(false, 10, clock); 2317 SIMULATED_WAIT(false, 10, clock);
2308 fw()->ClearRules(); 2318 fw()->ClearRules();
2309 2319
2310 // We should remain on the public address on both sides and no connection 2320 // We should remain on the public address on both sides and no connection
2311 // switches should have happened. 2321 // switches should have happened.
2312 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() && 2322 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() &&
2313 ep2_ch1()->selected_connection()->receiving(), 2323 ep2_ch1()->selected_connection()->receiving(),
2314 3000, clock); 2324 kMediumTimeout, clock);
2315 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 2325 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
2316 EXPECT_TRUE(LocalCandidate(ep2_ch1())->address().EqualIPs(kPublicAddrs[1])); 2326 EXPECT_TRUE(LocalCandidate(ep2_ch1())->address().EqualIPs(kPublicAddrs[1]));
2317 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); 2327 EXPECT_EQ(0, reset_selected_candidate_pair_switches());
2318 2328
2319 DestroyChannels(); 2329 DestroyChannels();
2320 } 2330 }
2321 2331
2322 // Test that if an interface fails temporarily and then recovers quickly, 2332 // Test that if an interface fails temporarily and then recovers quickly,
2323 // the selected connection will not switch. 2333 // the selected connection will not switch.
2324 TEST_F(P2PTransportChannelMultihomedTest, 2334 TEST_F(P2PTransportChannelMultihomedTest,
2325 TestConnectionSwitchDampeningControllingSide) { 2335 TestConnectionSwitchDampeningControllingSide) {
2326 rtc::ScopedFakeClock clock; 2336 rtc::ScopedFakeClock clock;
2327 // Adding alternate address will make sure |kPublicAddrs| has the higher 2337 // Adding alternate address will make sure |kPublicAddrs| has the higher
2328 // priority than others. This is due to FakeNetwork::AddInterface method. 2338 // priority than others. This is due to FakeNetwork::AddInterface method.
2329 AddAddress(0, kAlternateAddrs[0]); 2339 AddAddress(0, kAlternateAddrs[0]);
2330 AddAddress(0, kPublicAddrs[0]); 2340 AddAddress(0, kPublicAddrs[0]);
2331 AddAddress(1, kPublicAddrs[1]); 2341 AddAddress(1, kPublicAddrs[1]);
2332 2342
2333 // Use only local ports for simplicity. 2343 // Use only local ports for simplicity.
2334 SetAllocatorFlags(0, kOnlyLocalPorts); 2344 SetAllocatorFlags(0, kOnlyLocalPorts);
2335 SetAllocatorFlags(1, kOnlyLocalPorts); 2345 SetAllocatorFlags(1, kOnlyLocalPorts);
2336 2346
2337 // Create channels and let them go writable, as usual. 2347 // Create channels and let them go writable, as usual.
2338 CreateChannels(); 2348 CreateChannels();
2339 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2349 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2340 ep2_ch1()->receiving() && 2350 ep2_ch1()->receiving() &&
2341 ep2_ch1()->writable(), 2351 ep2_ch1()->writable(),
2342 3000, clock); 2352 kMediumTimeout, clock);
2343 EXPECT_TRUE(ep1_ch1()->selected_connection() && 2353 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
2344 ep2_ch1()->selected_connection() && 2354 ep2_ch1()->selected_connection() &&
2345 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 2355 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
2346 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 2356 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
2347 2357
2348 // Make the receiving timeout shorter for testing. 2358 // Make the receiving timeout shorter for testing.
2349 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); 2359 IceConfig config = CreateIceConfig(1000, GATHER_ONCE);
2350 ep1_ch1()->SetIceConfig(config); 2360 ep1_ch1()->SetIceConfig(config);
2351 ep2_ch1()->SetIceConfig(config); 2361 ep2_ch1()->SetIceConfig(config);
2352 reset_selected_candidate_pair_switches(); 2362 reset_selected_candidate_pair_switches();
2353 2363
2354 // Blackhole any traffic to or from the public addrs. 2364 // Blackhole any traffic to or from the public addrs.
2355 LOG(LS_INFO) << "Failing over..."; 2365 LOG(LS_INFO) << "Failing over...";
2356 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); 2366 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]);
2357 // The selected connections may switch, so keep references to them. 2367 // The selected connections may switch, so keep references to them.
2358 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); 2368 const Connection* selected_connection1 = ep1_ch1()->selected_connection();
2359 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); 2369 const Connection* selected_connection2 = ep2_ch1()->selected_connection();
2360 // We should detect loss of receiving within 1 second or so. 2370 // We should detect loss of receiving within 1 second or so.
2361 EXPECT_TRUE_SIMULATED_WAIT( 2371 EXPECT_TRUE_SIMULATED_WAIT(
2362 !selected_connection1->receiving() && !selected_connection2->receiving(), 2372 !selected_connection1->receiving() && !selected_connection2->receiving(),
2363 3000, clock); 2373 kMediumTimeout, clock);
2364 // The link recovers after a short while. 2374 // The link recovers after a short while.
2365 SIMULATED_WAIT(false, 10, clock); 2375 SIMULATED_WAIT(false, 10, clock);
2366 fw()->ClearRules(); 2376 fw()->ClearRules();
2367 2377
2368 // We should not switch to the alternate addr on both sides because of the 2378 // We should not switch to the alternate addr on both sides because of the
2369 // dampening. 2379 // dampening.
2370 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() && 2380 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() &&
2371 ep2_ch1()->selected_connection()->receiving(), 2381 ep2_ch1()->selected_connection()->receiving(),
2372 3000, clock); 2382 kMediumTimeout, clock);
2373 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); 2383 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]));
2374 EXPECT_TRUE(RemoteCandidate(ep2_ch1())->address().EqualIPs(kPublicAddrs[0])); 2384 EXPECT_TRUE(RemoteCandidate(ep2_ch1())->address().EqualIPs(kPublicAddrs[0]));
2375 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); 2385 EXPECT_EQ(0, reset_selected_candidate_pair_switches());
2376 DestroyChannels(); 2386 DestroyChannels();
2377 } 2387 }
2378 2388
2379 // Tests that if the remote side's network failed, it won't cause the local 2389 // Tests that if the remote side's network failed, it won't cause the local
2380 // side to switch connections and networks. 2390 // side to switch connections and networks.
2381 TEST_F(P2PTransportChannelMultihomedTest, TestRemoteFailover) { 2391 TEST_F(P2PTransportChannelMultihomedTest, TestRemoteFailover) {
2382 rtc::ScopedFakeClock clock; 2392 rtc::ScopedFakeClock clock;
(...skipping 14 matching lines...) Expand all
2397 // Set the backup connection ping interval to 25s. 2407 // Set the backup connection ping interval to 25s.
2398 IceConfig config = CreateIceConfig(1000, GATHER_ONCE, 25000); 2408 IceConfig config = CreateIceConfig(1000, GATHER_ONCE, 25000);
2399 // Ping the best connection more frequently since we don't have traffic. 2409 // Ping the best connection more frequently since we don't have traffic.
2400 config.stable_writable_connection_ping_interval = 900; 2410 config.stable_writable_connection_ping_interval = 900;
2401 ep1_ch1()->SetIceConfig(config); 2411 ep1_ch1()->SetIceConfig(config);
2402 ep2_ch1()->SetIceConfig(config); 2412 ep2_ch1()->SetIceConfig(config);
2403 // Need to wait to make sure the connections on both networks are writable. 2413 // Need to wait to make sure the connections on both networks are writable.
2404 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2414 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2405 ep2_ch1()->receiving() && 2415 ep2_ch1()->receiving() &&
2406 ep2_ch1()->writable(), 2416 ep2_ch1()->writable(),
2407 3000, clock); 2417 kMediumTimeout, clock);
2408 EXPECT_TRUE_SIMULATED_WAIT( 2418 EXPECT_TRUE_SIMULATED_WAIT(
2409 ep1_ch1()->selected_connection() && 2419 ep1_ch1()->selected_connection() &&
2410 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && 2420 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) &&
2411 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), 2421 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]),
2412 kDefaultTimeout, clock); 2422 kDefaultTimeout, clock);
2413 Connection* backup_conn = 2423 Connection* backup_conn =
2414 GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]); 2424 GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]);
2415 ASSERT_NE(nullptr, backup_conn); 2425 ASSERT_NE(nullptr, backup_conn);
2416 // After a short while, the backup connection will be writable but not 2426 // After a short while, the backup connection will be writable but not
2417 // receiving because backup connection is pinged at a slower rate. 2427 // receiving because backup connection is pinged at a slower rate.
2418 EXPECT_TRUE_SIMULATED_WAIT( 2428 EXPECT_TRUE_SIMULATED_WAIT(
2419 backup_conn->writable() && !backup_conn->receiving(), 5000, clock); 2429 backup_conn->writable() && !backup_conn->receiving(), kDefaultTimeout,
2430 clock);
2420 reset_selected_candidate_pair_switches(); 2431 reset_selected_candidate_pair_switches();
2421 // Blackhole any traffic to or from the remote WiFi networks. 2432 // Blackhole any traffic to or from the remote WiFi networks.
2422 LOG(LS_INFO) << "Failing over..."; 2433 LOG(LS_INFO) << "Failing over...";
2423 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, wifi[1]); 2434 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, wifi[1]);
2424 2435
2425 int num_switches = 0; 2436 int num_switches = 0;
2426 SIMULATED_WAIT((num_switches = reset_selected_candidate_pair_switches()) > 0, 2437 SIMULATED_WAIT((num_switches = reset_selected_candidate_pair_switches()) > 0,
2427 20000, clock); 2438 20000, clock);
2428 EXPECT_EQ(0, num_switches); 2439 EXPECT_EQ(0, num_switches);
2429 DestroyChannels(); 2440 DestroyChannels();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2513 1000, 1000); 2524 1000, 1000);
2514 int backup_ping_interval = 2000; 2525 int backup_ping_interval = 2000;
2515 ep2_ch1()->SetIceConfig( 2526 ep2_ch1()->SetIceConfig(
2516 CreateIceConfig(2000, GATHER_ONCE, backup_ping_interval)); 2527 CreateIceConfig(2000, GATHER_ONCE, backup_ping_interval));
2517 // After the state becomes COMPLETED, the backup connection will be pinged 2528 // After the state becomes COMPLETED, the backup connection will be pinged
2518 // once every |backup_ping_interval| milliseconds. 2529 // once every |backup_ping_interval| milliseconds.
2519 ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == STATE_COMPLETED, 1000); 2530 ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == STATE_COMPLETED, 1000);
2520 const std::vector<Connection*>& connections = ep2_ch1()->connections(); 2531 const std::vector<Connection*>& connections = ep2_ch1()->connections();
2521 ASSERT_EQ(2U, connections.size()); 2532 ASSERT_EQ(2U, connections.size());
2522 Connection* backup_conn = connections[1]; 2533 Connection* backup_conn = connections[1];
2523 EXPECT_TRUE_WAIT(backup_conn->writable(), 3000); 2534 EXPECT_TRUE_WAIT(backup_conn->writable(), kMediumTimeout);
2524 int64_t last_ping_response_ms = backup_conn->last_ping_response_received(); 2535 int64_t last_ping_response_ms = backup_conn->last_ping_response_received();
2525 EXPECT_TRUE_WAIT( 2536 EXPECT_TRUE_WAIT(
2526 last_ping_response_ms < backup_conn->last_ping_response_received(), 5000); 2537 last_ping_response_ms < backup_conn->last_ping_response_received(),
2538 kDefaultTimeout);
2527 int time_elapsed = 2539 int time_elapsed =
2528 backup_conn->last_ping_response_received() - last_ping_response_ms; 2540 backup_conn->last_ping_response_received() - last_ping_response_ms;
2529 LOG(LS_INFO) << "Time elapsed: " << time_elapsed; 2541 LOG(LS_INFO) << "Time elapsed: " << time_elapsed;
2530 EXPECT_GE(time_elapsed, backup_ping_interval); 2542 EXPECT_GE(time_elapsed, backup_ping_interval);
2531 2543
2532 DestroyChannels(); 2544 DestroyChannels();
2533 } 2545 }
2534 2546
2535 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) { 2547 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) {
2548 rtc::ScopedFakeClock clock;
2536 AddAddress(0, kAlternateAddrs[0]); 2549 AddAddress(0, kAlternateAddrs[0]);
2537 AddAddress(0, kPublicAddrs[0]); 2550 AddAddress(0, kPublicAddrs[0]);
2538 AddAddress(1, kPublicAddrs[1]); 2551 AddAddress(1, kPublicAddrs[1]);
2539 // Create channels and let them go writable, as usual. 2552 // Create channels and let them go writable, as usual.
2540 CreateChannels(); 2553 CreateChannels();
2541 2554
2542 // Both transport channels will reach STATE_COMPLETED quickly. 2555 // Both transport channels will reach STATE_COMPLETED quickly.
2543 EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep1_ch1()->GetState(), 2556 EXPECT_EQ_SIMULATED_WAIT(TransportChannelState::STATE_COMPLETED,
2544 1000); 2557 ep1_ch1()->GetState(), kShortTimeout, clock);
2545 EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep2_ch1()->GetState(), 2558 EXPECT_EQ_SIMULATED_WAIT(TransportChannelState::STATE_COMPLETED,
2546 1000); 2559 ep2_ch1()->GetState(), kShortTimeout, clock);
2547 } 2560 }
2548 2561
2549 // Tests that when a network interface becomes inactive, if Continual Gathering 2562 // Tests that when a network interface becomes inactive, if Continual Gathering
2550 // policy is GATHER_CONTINUALLY, the ports associated with that network 2563 // policy is GATHER_CONTINUALLY, the ports associated with that network
2551 // will be removed from the port list of the channel, and the respective 2564 // will be removed from the port list of the channel, and the respective
2552 // remote candidates on the other participant will be removed eventually. 2565 // remote candidates on the other participant will be removed eventually.
2553 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { 2566 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) {
2554 rtc::ScopedFakeClock clock; 2567 rtc::ScopedFakeClock clock;
2555 AddAddress(0, kPublicAddrs[0]); 2568 AddAddress(0, kPublicAddrs[0]);
2556 AddAddress(1, kPublicAddrs[1]); 2569 AddAddress(1, kPublicAddrs[1]);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
2650 SetAllocatorFlags(1, kOnlyLocalPorts); 2663 SetAllocatorFlags(1, kOnlyLocalPorts);
2651 2664
2652 // Set continual gathering policy. 2665 // Set continual gathering policy.
2653 IceConfig continual_gathering_config = 2666 IceConfig continual_gathering_config =
2654 CreateIceConfig(1000, GATHER_CONTINUALLY); 2667 CreateIceConfig(1000, GATHER_CONTINUALLY);
2655 // Create channels and let them go writable, as usual. 2668 // Create channels and let them go writable, as usual.
2656 CreateChannels(continual_gathering_config, continual_gathering_config); 2669 CreateChannels(continual_gathering_config, continual_gathering_config);
2657 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2670 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2658 ep2_ch1()->receiving() && 2671 ep2_ch1()->receiving() &&
2659 ep2_ch1()->writable(), 2672 ep2_ch1()->writable(),
2660 3000, clock); 2673 kMediumTimeout, clock);
2661 EXPECT_TRUE( 2674 EXPECT_TRUE(
2662 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && 2675 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
2663 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 2676 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
2664 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 2677 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
2665 2678
2666 // Add the new address first and then remove the other one. 2679 // Add the new address first and then remove the other one.
2667 LOG(LS_INFO) << "Draining..."; 2680 LOG(LS_INFO) << "Draining...";
2668 AddAddress(1, kAlternateAddrs[1]); 2681 AddAddress(1, kAlternateAddrs[1]);
2669 RemoveAddress(1, kPublicAddrs[1]); 2682 RemoveAddress(1, kPublicAddrs[1]);
2670 // We should switch to use the alternate address after an exchange of pings. 2683 // We should switch to use the alternate address after an exchange of pings.
2671 EXPECT_TRUE_SIMULATED_WAIT( 2684 EXPECT_TRUE_SIMULATED_WAIT(
2672 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && 2685 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
2673 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 2686 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
2674 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), 2687 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]),
2675 3000, clock); 2688 kMediumTimeout, clock);
2676 2689
2677 // Remove one address first and then add another address. 2690 // Remove one address first and then add another address.
2678 LOG(LS_INFO) << "Draining again..."; 2691 LOG(LS_INFO) << "Draining again...";
2679 RemoveAddress(1, kAlternateAddrs[1]); 2692 RemoveAddress(1, kAlternateAddrs[1]);
2680 AddAddress(1, kAlternateAddrs[0]); 2693 AddAddress(1, kAlternateAddrs[0]);
2681 EXPECT_TRUE_SIMULATED_WAIT( 2694 EXPECT_TRUE_SIMULATED_WAIT(
2682 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && 2695 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
2683 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 2696 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
2684 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]), 2697 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]),
2685 3000, clock); 2698 kMediumTimeout, clock);
2686 2699
2687 DestroyChannels(); 2700 DestroyChannels();
2688 } 2701 }
2689 2702
2690 /* 2703 /*
2691 TODO(honghaiz) Once continual gathering fully supports 2704 TODO(honghaiz) Once continual gathering fully supports
2692 GATHER_CONTINUALLY_AND_RECOVER, put this test back. 2705 GATHER_CONTINUALLY_AND_RECOVER, put this test back.
2693 2706
2694 // Tests that if the backup connections are lost and then the interface with the 2707 // Tests that if the backup connections are lost and then the interface with the
2695 // selected connection is gone, continual gathering will restore the 2708 // selected connection is gone, continual gathering will restore the
(...skipping 10 matching lines...) Expand all
2706 // Use only local ports for simplicity. 2719 // Use only local ports for simplicity.
2707 SetAllocatorFlags(0, kOnlyLocalPorts); 2720 SetAllocatorFlags(0, kOnlyLocalPorts);
2708 SetAllocatorFlags(1, kOnlyLocalPorts); 2721 SetAllocatorFlags(1, kOnlyLocalPorts);
2709 2722
2710 // Set continual gathering policy. 2723 // Set continual gathering policy.
2711 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY_AND_RECOVER); 2724 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY_AND_RECOVER);
2712 // Create channels and let them go writable, as usual. 2725 // Create channels and let them go writable, as usual.
2713 CreateChannels(config, config); 2726 CreateChannels(config, config);
2714 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2727 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2715 ep2_ch1()->receiving() && ep2_ch1()->writable(), 2728 ep2_ch1()->receiving() && ep2_ch1()->writable(),
2716 3000, clock); 2729 kMediumTimeout, clock);
2717 EXPECT_TRUE(ep1_ch1()->selected_connection() && 2730 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
2718 ep2_ch1()->selected_connection() && 2731 ep2_ch1()->selected_connection() &&
2719 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && 2732 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) &&
2720 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1])); 2733 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]));
2721 2734
2722 // First destroy all backup connection. 2735 // First destroy all backup connection.
2723 DestroyAllButBestConnection(ep1_ch1()); 2736 DestroyAllButBestConnection(ep1_ch1());
2724 2737
2725 SIMULATED_WAIT(false, 10, clock); 2738 SIMULATED_WAIT(false, 10, clock);
2726 // Then the interface of the best connection goes away. 2739 // Then the interface of the best connection goes away.
2727 RemoveAddress(0, wifi[0]); 2740 RemoveAddress(0, wifi[0]);
2728 EXPECT_TRUE_SIMULATED_WAIT( 2741 EXPECT_TRUE_SIMULATED_WAIT(
2729 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && 2742 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
2730 LocalCandidate(ep1_ch1())->address().EqualIPs(cellular[0]) && 2743 LocalCandidate(ep1_ch1())->address().EqualIPs(cellular[0]) &&
2731 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), 2744 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]),
2732 3000, clock); 2745 kMediumTimeout, clock);
2733 2746
2734 DestroyChannels(); 2747 DestroyChannels();
2735 } 2748 }
2736 */ 2749 */
2737 2750
2738 // Tests that the backup connection will be restored after it is destroyed. 2751 // Tests that the backup connection will be restored after it is destroyed.
2739 TEST_F(P2PTransportChannelMultihomedTest, TestRestoreBackupConnection) { 2752 TEST_F(P2PTransportChannelMultihomedTest, TestRestoreBackupConnection) {
2740 rtc::ScopedFakeClock clock; 2753 rtc::ScopedFakeClock clock;
2741 auto& wifi = kAlternateAddrs; 2754 auto& wifi = kAlternateAddrs;
2742 auto& cellular = kPublicAddrs; 2755 auto& cellular = kPublicAddrs;
2743 AddAddress(0, wifi[0], "test_wifi0", rtc::ADAPTER_TYPE_WIFI); 2756 AddAddress(0, wifi[0], "test_wifi0", rtc::ADAPTER_TYPE_WIFI);
2744 AddAddress(0, cellular[0], "test_cell0", rtc::ADAPTER_TYPE_CELLULAR); 2757 AddAddress(0, cellular[0], "test_cell0", rtc::ADAPTER_TYPE_CELLULAR);
2745 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI); 2758 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI);
2746 AddAddress(1, cellular[1], "test_cell1", rtc::ADAPTER_TYPE_CELLULAR); 2759 AddAddress(1, cellular[1], "test_cell1", rtc::ADAPTER_TYPE_CELLULAR);
2747 // Use only local ports for simplicity. 2760 // Use only local ports for simplicity.
2748 SetAllocatorFlags(0, kOnlyLocalPorts); 2761 SetAllocatorFlags(0, kOnlyLocalPorts);
2749 SetAllocatorFlags(1, kOnlyLocalPorts); 2762 SetAllocatorFlags(1, kOnlyLocalPorts);
2750 2763
2751 // Create channels and let them go writable, as usual. 2764 // Create channels and let them go writable, as usual.
2752 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); 2765 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY);
2753 config.regather_on_failed_networks_interval = rtc::Optional<int>(2000); 2766 config.regather_on_failed_networks_interval = rtc::Optional<int>(2000);
2754 CreateChannels(config, config); 2767 CreateChannels(config, config);
2755 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2768 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2756 ep2_ch1()->receiving() && 2769 ep2_ch1()->receiving() &&
2757 ep2_ch1()->writable(), 2770 ep2_ch1()->writable(),
2758 3000, clock); 2771 kMediumTimeout, clock);
2759 EXPECT_TRUE(ep1_ch1()->selected_connection() && 2772 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
2760 ep2_ch1()->selected_connection() && 2773 ep2_ch1()->selected_connection() &&
2761 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && 2774 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) &&
2762 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1])); 2775 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]));
2763 2776
2764 // Destroy all backup connections. 2777 // Destroy all backup connections.
2765 DestroyAllButBestConnection(ep1_ch1()); 2778 DestroyAllButBestConnection(ep1_ch1());
2766 // Ensure the backup connection is removed first. 2779 // Ensure the backup connection is removed first.
2767 EXPECT_TRUE_SIMULATED_WAIT( 2780 EXPECT_TRUE_SIMULATED_WAIT(
2768 GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]) == nullptr, 2781 GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]) == nullptr,
2769 kDefaultTimeout, clock); 2782 kDefaultTimeout, clock);
2770 const cricket::Connection* conn; 2783 const cricket::Connection* conn;
2771 EXPECT_TRUE_SIMULATED_WAIT( 2784 EXPECT_TRUE_SIMULATED_WAIT(
2772 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) != 2785 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) !=
2773 nullptr && 2786 nullptr &&
2774 conn != ep1_ch1()->selected_connection() && conn->writable(), 2787 conn != ep1_ch1()->selected_connection() && conn->writable(),
2775 5000, clock); 2788 kDefaultTimeout, clock);
2776 2789
2777 DestroyChannels(); 2790 DestroyChannels();
2778 } 2791 }
2779 2792
2780 // A collection of tests which tests a single P2PTransportChannel by sending 2793 // A collection of tests which tests a single P2PTransportChannel by sending
2781 // pings. 2794 // pings.
2782 class P2PTransportChannelPingTest : public testing::Test, 2795 class P2PTransportChannelPingTest : public testing::Test,
2783 public sigslot::has_slots<> { 2796 public sigslot::has_slots<> {
2784 public: 2797 public:
2785 P2PTransportChannelPingTest() 2798 P2PTransportChannelPingTest()
(...skipping 12 matching lines...) Expand all
2798 &P2PTransportChannelPingTest::OnReadyToSend); 2811 &P2PTransportChannelPingTest::OnReadyToSend);
2799 ch->SignalStateChanged.connect( 2812 ch->SignalStateChanged.connect(
2800 this, &P2PTransportChannelPingTest::OnChannelStateChanged); 2813 this, &P2PTransportChannelPingTest::OnChannelStateChanged);
2801 } 2814 }
2802 2815
2803 Connection* WaitForConnectionTo(P2PTransportChannel* ch, 2816 Connection* WaitForConnectionTo(P2PTransportChannel* ch,
2804 const std::string& ip, 2817 const std::string& ip,
2805 int port_num, 2818 int port_num,
2806 rtc::FakeClock* clock = nullptr) { 2819 rtc::FakeClock* clock = nullptr) {
2807 if (clock == nullptr) { 2820 if (clock == nullptr) {
2808 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); 2821 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr,
2822 kMediumTimeout);
2809 } else { 2823 } else {
2810 EXPECT_TRUE_SIMULATED_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 2824 EXPECT_TRUE_SIMULATED_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr,
2811 3000, *clock); 2825 kMediumTimeout, *clock);
2812 } 2826 }
2813 return GetConnectionTo(ch, ip, port_num); 2827 return GetConnectionTo(ch, ip, port_num);
2814 } 2828 }
2815 2829
2816 Port* GetPort(P2PTransportChannel* ch) { 2830 Port* GetPort(P2PTransportChannel* ch) {
2817 if (ch->ports().empty()) { 2831 if (ch->ports().empty()) {
2818 return nullptr; 2832 return nullptr;
2819 } 2833 }
2820 return static_cast<Port*>(ch->ports()[0]); 2834 return static_cast<Port*>(ch->ports()[0]);
2821 } 2835 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2856 2870
2857 Connection* CreateConnectionWithCandidate(P2PTransportChannel& channel, 2871 Connection* CreateConnectionWithCandidate(P2PTransportChannel& channel,
2858 rtc::ScopedFakeClock& clock, 2872 rtc::ScopedFakeClock& clock,
2859 const std::string& ip_addr, 2873 const std::string& ip_addr,
2860 int port, 2874 int port,
2861 int priority, 2875 int priority,
2862 bool writable) { 2876 bool writable) {
2863 channel.AddRemoteCandidate( 2877 channel.AddRemoteCandidate(
2864 CreateUdpCandidate(LOCAL_PORT_TYPE, ip_addr, port, priority)); 2878 CreateUdpCandidate(LOCAL_PORT_TYPE, ip_addr, port, priority));
2865 EXPECT_TRUE_SIMULATED_WAIT( 2879 EXPECT_TRUE_SIMULATED_WAIT(
2866 GetConnectionTo(&channel, ip_addr, port) != nullptr, 3000, clock); 2880 GetConnectionTo(&channel, ip_addr, port) != nullptr, kMediumTimeout,
2881 clock);
2867 Connection* conn = GetConnectionTo(&channel, ip_addr, port); 2882 Connection* conn = GetConnectionTo(&channel, ip_addr, port);
2868 2883
2869 if (conn && writable) { 2884 if (conn && writable) {
2870 conn->ReceivedPingResponse(LOW_RTT, "id"); // make it writable 2885 conn->ReceivedPingResponse(LOW_RTT, "id"); // make it writable
2871 } 2886 }
2872 return conn; 2887 return conn;
2873 } 2888 }
2874 2889
2875 void NominateConnection(Connection* conn, uint32_t remote_nomination = 1U) { 2890 void NominateConnection(Connection* conn, uint32_t remote_nomination = 1U) {
2876 conn->set_remote_nomination(remote_nomination); 2891 conn->set_remote_nomination(remote_nomination);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
3013 (MIN_PINGS_AT_WEAK_PING_INTERVAL - 1); 3028 (MIN_PINGS_AT_WEAK_PING_INTERVAL - 1);
3014 EXPECT_EQ(ping_interval_ms, WEAK_PING_INTERVAL); 3029 EXPECT_EQ(ping_interval_ms, WEAK_PING_INTERVAL);
3015 3030
3016 // Stabilizing. 3031 // Stabilizing.
3017 3032
3018 conn->ReceivedPingResponse(LOW_RTT, "id"); 3033 conn->ReceivedPingResponse(LOW_RTT, "id");
3019 int ping_sent_before = conn->num_pings_sent(); 3034 int ping_sent_before = conn->num_pings_sent();
3020 start = clock.TimeNanos(); 3035 start = clock.TimeNanos();
3021 // The connection becomes strong but not stable because we haven't been able 3036 // The connection becomes strong but not stable because we haven't been able
3022 // to converge the RTT. 3037 // to converge the RTT.
3023 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 3038 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, kMediumTimeout,
3039 clock);
3024 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 3040 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
3025 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); 3041 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
3026 EXPECT_LE(ping_interval_ms, 3042 EXPECT_LE(ping_interval_ms,
3027 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); 3043 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
3028 3044
3029 // Stabilized. 3045 // Stabilized.
3030 3046
3031 // The connection becomes stable after receiving more than RTT_RATIO rtt 3047 // The connection becomes stable after receiving more than RTT_RATIO rtt
3032 // samples. 3048 // samples.
3033 for (int i = 0; i < RTT_RATIO; i++) { 3049 for (int i = 0; i < RTT_RATIO; i++) {
3034 conn->ReceivedPingResponse(LOW_RTT, "id"); 3050 conn->ReceivedPingResponse(LOW_RTT, "id");
3035 } 3051 }
3036 ping_sent_before = conn->num_pings_sent(); 3052 ping_sent_before = conn->num_pings_sent();
3037 start = clock.TimeNanos(); 3053 start = clock.TimeNanos();
3038 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 3054 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, kMediumTimeout,
3055 clock);
3039 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 3056 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
3040 EXPECT_GE(ping_interval_ms, STABLE_WRITABLE_CONNECTION_PING_INTERVAL); 3057 EXPECT_GE(ping_interval_ms, STABLE_WRITABLE_CONNECTION_PING_INTERVAL);
3041 EXPECT_LE(ping_interval_ms, 3058 EXPECT_LE(ping_interval_ms,
3042 STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); 3059 STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
3043 3060
3044 // Destabilized. 3061 // Destabilized.
3045 3062
3046 conn->ReceivedPingResponse(LOW_RTT, "id"); 3063 conn->ReceivedPingResponse(LOW_RTT, "id");
3047 // Create a in-flight ping. 3064 // Create a in-flight ping.
3048 conn->Ping(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec); 3065 conn->Ping(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec);
3049 start = clock.TimeNanos(); 3066 start = clock.TimeNanos();
3050 // In-flight ping timeout and the connection will be unstable. 3067 // In-flight ping timeout and the connection will be unstable.
3051 SIMULATED_WAIT( 3068 SIMULATED_WAIT(
3052 !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec), 3000, 3069 !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec),
3053 clock); 3070 kMediumTimeout, clock);
3054 int64_t duration_ms = 3071 int64_t duration_ms =
3055 (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 3072 (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
3056 EXPECT_GE(duration_ms, 2 * conn->rtt() - RTT_RANGE); 3073 EXPECT_GE(duration_ms, 2 * conn->rtt() - RTT_RANGE);
3057 EXPECT_LE(duration_ms, 2 * conn->rtt() + RTT_RANGE); 3074 EXPECT_LE(duration_ms, 2 * conn->rtt() + RTT_RANGE);
3058 // The connection become unstable due to not receiving ping responses. 3075 // The connection become unstable due to not receiving ping responses.
3059 ping_sent_before = conn->num_pings_sent(); 3076 ping_sent_before = conn->num_pings_sent();
3060 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 3077 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, kMediumTimeout,
3078 clock);
3061 // The interval is expected to be 3079 // The interval is expected to be
3062 // STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL. 3080 // STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL.
3063 start = clock.TimeNanos(); 3081 start = clock.TimeNanos();
3064 ping_sent_before = conn->num_pings_sent(); 3082 ping_sent_before = conn->num_pings_sent();
3065 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 3083 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, kMediumTimeout,
3084 clock);
3066 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 3085 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
3067 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); 3086 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
3068 EXPECT_LE(ping_interval_ms, 3087 EXPECT_LE(ping_interval_ms,
3069 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); 3088 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
3070 } 3089 }
3071 3090
3072 // Test that we start pinging as soon as we have a connection and remote ICE 3091 // Test that we start pinging as soon as we have a connection and remote ICE
3073 // parameters. 3092 // parameters.
3074 TEST_F(P2PTransportChannelPingTest, PingingStartedAsSoonAsPossible) { 3093 TEST_F(P2PTransportChannelPingTest, PingingStartedAsSoonAsPossible) {
3075 rtc::ScopedFakeClock clock; 3094 rtc::ScopedFakeClock clock;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
3200 CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2, kIceUfrag[1])); 3219 CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2, kIceUfrag[1]));
3201 rtc::Thread::Current()->ProcessMessages(500); 3220 rtc::Thread::Current()->ProcessMessages(500);
3202 EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr); 3221 EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr);
3203 3222
3204 // Add a candidate with the current ufrag, its pwd and generation will be 3223 // Add a candidate with the current ufrag, its pwd and generation will be
3205 // assigned, even if the generation is not set. 3224 // assigned, even if the generation is not set.
3206 ch.AddRemoteCandidate( 3225 ch.AddRemoteCandidate(
3207 CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 0, kIceUfrag[2])); 3226 CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 0, kIceUfrag[2]));
3208 Connection* conn3 = nullptr; 3227 Connection* conn3 = nullptr;
3209 ASSERT_TRUE_WAIT((conn3 = GetConnectionTo(&ch, "3.3.3.3", 3)) != nullptr, 3228 ASSERT_TRUE_WAIT((conn3 = GetConnectionTo(&ch, "3.3.3.3", 3)) != nullptr,
3210 3000); 3229 kMediumTimeout);
3211 const Candidate& new_candidate = conn3->remote_candidate(); 3230 const Candidate& new_candidate = conn3->remote_candidate();
3212 EXPECT_EQ(kIcePwd[2], new_candidate.password()); 3231 EXPECT_EQ(kIcePwd[2], new_candidate.password());
3213 EXPECT_EQ(1U, new_candidate.generation()); 3232 EXPECT_EQ(1U, new_candidate.generation());
3214 3233
3215 // Check that the pwd of all remote candidates are properly assigned. 3234 // Check that the pwd of all remote candidates are properly assigned.
3216 for (const RemoteCandidate& candidate : ch.remote_candidates()) { 3235 for (const RemoteCandidate& candidate : ch.remote_candidates()) {
3217 EXPECT_TRUE(candidate.username() == kIceUfrag[1] || 3236 EXPECT_TRUE(candidate.username() == kIceUfrag[1] ||
3218 candidate.username() == kIceUfrag[2]); 3237 candidate.username() == kIceUfrag[2]);
3219 if (candidate.username() == kIceUfrag[1]) { 3238 if (candidate.username() == kIceUfrag[1]) {
3220 EXPECT_EQ(kIcePwd[1], candidate.password()); 3239 EXPECT_EQ(kIcePwd[1], candidate.password());
(...skipping 17 matching lines...) Expand all
3238 3257
3239 // Create a higher priority candidate and make the connection 3258 // Create a higher priority candidate and make the connection
3240 // receiving/writable. This will prune conn1. 3259 // receiving/writable. This will prune conn1.
3241 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 3260 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
3242 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3261 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3243 ASSERT_TRUE(conn2 != nullptr); 3262 ASSERT_TRUE(conn2 != nullptr);
3244 conn2->ReceivedPing(); 3263 conn2->ReceivedPing();
3245 conn2->ReceivedPingResponse(LOW_RTT, "id"); 3264 conn2->ReceivedPingResponse(LOW_RTT, "id");
3246 3265
3247 // Wait for conn1 to be pruned. 3266 // Wait for conn1 to be pruned.
3248 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); 3267 EXPECT_TRUE_WAIT(conn1->pruned(), kMediumTimeout);
3249 // Destroy the connection to test SignalUnknownAddress. 3268 // Destroy the connection to test SignalUnknownAddress.
3250 conn1->Destroy(); 3269 conn1->Destroy();
3251 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000); 3270 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000);
3252 3271
3253 // Create a minimal STUN message with prflx priority. 3272 // Create a minimal STUN message with prflx priority.
3254 IceMessage request; 3273 IceMessage request;
3255 request.SetType(STUN_BINDING_REQUEST); 3274 request.SetType(STUN_BINDING_REQUEST);
3256 request.AddAttribute( 3275 request.AddAttribute(
3257 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3276 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
3258 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3277 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
3753 EXPECT_EQ(nullptr, ch.selected_connection()); 3772 EXPECT_EQ(nullptr, ch.selected_connection());
3754 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving 3773 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3755 3774
3756 // When a higher-priority, nominated candidate comes in, the connections with 3775 // When a higher-priority, nominated candidate comes in, the connections with
3757 // lower-priority are pruned. 3776 // lower-priority are pruned.
3758 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); 3777 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
3759 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock); 3778 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock);
3760 ASSERT_TRUE(conn2 != nullptr); 3779 ASSERT_TRUE(conn2 != nullptr);
3761 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving 3780 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3762 NominateConnection(conn2); 3781 NominateConnection(conn2);
3763 EXPECT_TRUE_SIMULATED_WAIT(conn1->pruned(), 3000, clock); 3782 EXPECT_TRUE_SIMULATED_WAIT(conn1->pruned(), kMediumTimeout, clock);
3764 3783
3765 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); 3784 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE));
3766 // Wait until conn2 becomes not receiving. 3785 // Wait until conn2 becomes not receiving.
3767 EXPECT_TRUE_SIMULATED_WAIT(!conn2->receiving(), 3000, clock); 3786 EXPECT_TRUE_SIMULATED_WAIT(!conn2->receiving(), kMediumTimeout, clock);
3768 3787
3769 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); 3788 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
3770 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3, &clock); 3789 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3, &clock);
3771 ASSERT_TRUE(conn3 != nullptr); 3790 ASSERT_TRUE(conn3 != nullptr);
3772 // The selected connection should still be conn2. Even through conn3 has lower 3791 // The selected connection should still be conn2. Even through conn3 has lower
3773 // priority and is not receiving/writable, it is not pruned because the 3792 // priority and is not receiving/writable, it is not pruned because the
3774 // selected connection is not receiving. 3793 // selected connection is not receiving.
3775 SIMULATED_WAIT(conn3->pruned(), 1000, clock); 3794 SIMULATED_WAIT(conn3->pruned(), 1000, clock);
3776 EXPECT_FALSE(conn3->pruned()); 3795 EXPECT_FALSE(conn3->pruned());
3777 } 3796 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3846 // receiving, |conn2| will start to ping and upon receiving the ping response, 3865 // receiving, |conn2| will start to ping and upon receiving the ping response,
3847 // it will become the selected connection. 3866 // it will become the selected connection.
3848 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3867 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3849 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock); 3868 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock);
3850 ASSERT_TRUE(conn2 != nullptr); 3869 ASSERT_TRUE(conn2 != nullptr);
3851 EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock); 3870 EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock);
3852 // |conn2| should not send a ping yet. 3871 // |conn2| should not send a ping yet.
3853 EXPECT_EQ(Connection::STATE_WAITING, conn2->state()); 3872 EXPECT_EQ(Connection::STATE_WAITING, conn2->state());
3854 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3873 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3855 // Wait for |conn1| becoming not receiving. 3874 // Wait for |conn1| becoming not receiving.
3856 EXPECT_TRUE_SIMULATED_WAIT(!conn1->receiving(), 3000, clock); 3875 EXPECT_TRUE_SIMULATED_WAIT(!conn1->receiving(), kMediumTimeout, clock);
3857 // Make sure conn2 is not deleted. 3876 // Make sure conn2 is not deleted.
3858 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock); 3877 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock);
3859 ASSERT_TRUE(conn2 != nullptr); 3878 ASSERT_TRUE(conn2 != nullptr);
3860 EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_INPROGRESS, conn2->state(), 3879 EXPECT_EQ_SIMULATED_WAIT(Connection::STATE_INPROGRESS, conn2->state(),
3861 kDefaultTimeout, clock); 3880 kDefaultTimeout, clock);
3862 conn2->ReceivedPingResponse(LOW_RTT, "id"); 3881 conn2->ReceivedPingResponse(LOW_RTT, "id");
3863 EXPECT_EQ_SIMULATED_WAIT(conn2, ch.selected_connection(), kDefaultTimeout, 3882 EXPECT_EQ_SIMULATED_WAIT(conn2, ch.selected_connection(), kDefaultTimeout,
3864 clock); 3883 clock);
3865 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); 3884 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
3866 3885
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
4069 std::unique_ptr<P2PTransportChannel> channel_; 4088 std::unique_ptr<P2PTransportChannel> channel_;
4070 }; 4089 };
4071 4090
4072 // Test that Relay/Relay connections will be pinged first when no other 4091 // Test that Relay/Relay connections will be pinged first when no other
4073 // connections have been pinged yet, unless we need to ping a trigger check or 4092 // connections have been pinged yet, unless we need to ping a trigger check or
4074 // we have a selected connection. 4093 // we have a selected connection.
4075 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, 4094 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
4076 TestRelayRelayFirstWhenNothingPingedYet) { 4095 TestRelayRelayFirstWhenNothingPingedYet) {
4077 const int max_strong_interval = 100; 4096 const int max_strong_interval = 100;
4078 P2PTransportChannel& ch = StartTransportChannel(true, max_strong_interval); 4097 P2PTransportChannel& ch = StartTransportChannel(true, max_strong_interval);
4079 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); 4098 EXPECT_TRUE_WAIT(ch.ports().size() == 2, kDefaultTimeout);
4080 EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE); 4099 EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
4081 EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE); 4100 EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
4082 4101
4083 ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1)); 4102 ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1));
4084 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 4103 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
4085 4104
4086 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); 4105 EXPECT_TRUE_WAIT(ch.connections().size() == 4, kDefaultTimeout);
4087 4106
4088 // Relay/Relay should be the first pingable connection. 4107 // Relay/Relay should be the first pingable connection.
4089 Connection* conn = FindNextPingableConnectionAndPingIt(&ch); 4108 Connection* conn = FindNextPingableConnectionAndPingIt(&ch);
4090 EXPECT_EQ(conn->local_candidate().type(), RELAY_PORT_TYPE); 4109 EXPECT_EQ(conn->local_candidate().type(), RELAY_PORT_TYPE);
4091 EXPECT_EQ(conn->remote_candidate().type(), RELAY_PORT_TYPE); 4110 EXPECT_EQ(conn->remote_candidate().type(), RELAY_PORT_TYPE);
4092 4111
4093 // Unless that we have a trigger check waiting to be pinged. 4112 // Unless that we have a trigger check waiting to be pinged.
4094 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 4113 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
4095 EXPECT_EQ(conn2->local_candidate().type(), LOCAL_PORT_TYPE); 4114 EXPECT_EQ(conn2->local_candidate().type(), LOCAL_PORT_TYPE);
4096 EXPECT_EQ(conn2->remote_candidate().type(), LOCAL_PORT_TYPE); 4115 EXPECT_EQ(conn2->remote_candidate().type(), LOCAL_PORT_TYPE);
(...skipping 13 matching lines...) Expand all
4110 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix 4129 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix
4111 the flakiness. The following test becomes flaky because we now ping the 4130 the flakiness. The following test becomes flaky because we now ping the
4112 connections with fast rates until every connection is pinged at least three 4131 connections with fast rates until every connection is pinged at least three
4113 times. The selected connection may have been pinged before 4132 times. The selected connection may have been pinged before
4114 |max_strong_interval|, so it may not be the next connection to be pinged as 4133 |max_strong_interval|, so it may not be the next connection to be pinged as
4115 expected in the test. 4134 expected in the test.
4116 4135
4117 // Verify that conn3 will be the "selected connection" since it is readable 4136 // Verify that conn3 will be the "selected connection" since it is readable
4118 // and writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next 4137 // and writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next
4119 // pingable connection. 4138 // pingable connection.
4120 EXPECT_TRUE_WAIT(conn3 == ch.selected_connection(), 5000); 4139 EXPECT_TRUE_WAIT(conn3 == ch.selected_connection(), kDefaultTimeout);
4121 WAIT(false, max_strong_interval + 100); 4140 WAIT(false, max_strong_interval + 100);
4122 conn3->ReceivedPingResponse(LOW_RTT, "id"); 4141 conn3->ReceivedPingResponse(LOW_RTT, "id");
4123 ASSERT_TRUE(conn3->writable()); 4142 ASSERT_TRUE(conn3->writable());
4124 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); 4143 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch));
4125 4144
4126 */ 4145 */
4127 } 4146 }
4128 4147
4129 // Test that Relay/Relay connections will be pinged first when everything has 4148 // Test that Relay/Relay connections will be pinged first when everything has
4130 // been pinged even if the Relay/Relay connection wasn't the first to be pinged 4149 // been pinged even if the Relay/Relay connection wasn't the first to be pinged
4131 // in the first round. 4150 // in the first round.
4132 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, 4151 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
4133 TestRelayRelayFirstWhenEverythingPinged) { 4152 TestRelayRelayFirstWhenEverythingPinged) {
4134 P2PTransportChannel& ch = StartTransportChannel(true, 100); 4153 P2PTransportChannel& ch = StartTransportChannel(true, 100);
4135 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); 4154 EXPECT_TRUE_WAIT(ch.ports().size() == 2, kDefaultTimeout);
4136 EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE); 4155 EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
4137 EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE); 4156 EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
4138 4157
4139 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 4158 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
4140 EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000); 4159 EXPECT_TRUE_WAIT(ch.connections().size() == 2, kDefaultTimeout);
4141 4160
4142 // Initially, only have Local/Local and Local/Relay. 4161 // Initially, only have Local/Local and Local/Relay.
4143 VerifyNextPingableConnection(LOCAL_PORT_TYPE, LOCAL_PORT_TYPE); 4162 VerifyNextPingableConnection(LOCAL_PORT_TYPE, LOCAL_PORT_TYPE);
4144 VerifyNextPingableConnection(RELAY_PORT_TYPE, LOCAL_PORT_TYPE); 4163 VerifyNextPingableConnection(RELAY_PORT_TYPE, LOCAL_PORT_TYPE);
4145 4164
4146 // Remote Relay candidate arrives. 4165 // Remote Relay candidate arrives.
4147 ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 2)); 4166 ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 2));
4148 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); 4167 EXPECT_TRUE_WAIT(ch.connections().size() == 4, kDefaultTimeout);
4149 4168
4150 // Relay/Relay should be the first since it hasn't been pinged before. 4169 // Relay/Relay should be the first since it hasn't been pinged before.
4151 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE); 4170 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
4152 4171
4153 // Local/Relay is the final one. 4172 // Local/Relay is the final one.
4154 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 4173 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
4155 4174
4156 // Now, every connection has been pinged once. The next one should be 4175 // Now, every connection has been pinged once. The next one should be
4157 // Relay/Relay. 4176 // Relay/Relay.
4158 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE); 4177 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
4159 } 4178 }
4160 4179
4161 // Test that when we receive a new remote candidate, they will be tried first 4180 // Test that when we receive a new remote candidate, they will be tried first
4162 // before we re-ping Relay/Relay connections again. 4181 // before we re-ping Relay/Relay connections again.
4163 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, 4182 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
4164 TestNoStarvationOnNonRelayConnection) { 4183 TestNoStarvationOnNonRelayConnection) {
4165 P2PTransportChannel& ch = StartTransportChannel(true, 100); 4184 P2PTransportChannel& ch = StartTransportChannel(true, 100);
4166 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); 4185 EXPECT_TRUE_WAIT(ch.ports().size() == 2, kDefaultTimeout);
4167 EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE); 4186 EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
4168 EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE); 4187 EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
4169 4188
4170 ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1)); 4189 ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1));
4171 EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000); 4190 EXPECT_TRUE_WAIT(ch.connections().size() == 2, kDefaultTimeout);
4172 4191
4173 // Initially, only have Relay/Relay and Local/Relay. Ping Relay/Relay first. 4192 // Initially, only have Relay/Relay and Local/Relay. Ping Relay/Relay first.
4174 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE); 4193 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
4175 4194
4176 // Next, ping Local/Relay. 4195 // Next, ping Local/Relay.
4177 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 4196 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
4178 4197
4179 // Remote Local candidate arrives. 4198 // Remote Local candidate arrives.
4180 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 4199 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
4181 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); 4200 EXPECT_TRUE_WAIT(ch.connections().size() == 4, kDefaultTimeout);
4182 4201
4183 // Local/Local should be the first since it hasn't been pinged before. 4202 // Local/Local should be the first since it hasn't been pinged before.
4184 VerifyNextPingableConnection(LOCAL_PORT_TYPE, LOCAL_PORT_TYPE); 4203 VerifyNextPingableConnection(LOCAL_PORT_TYPE, LOCAL_PORT_TYPE);
4185 4204
4186 // Relay/Local is the final one. 4205 // Relay/Local is the final one.
4187 VerifyNextPingableConnection(RELAY_PORT_TYPE, LOCAL_PORT_TYPE); 4206 VerifyNextPingableConnection(RELAY_PORT_TYPE, LOCAL_PORT_TYPE);
4188 4207
4189 // Now, every connection has been pinged once. The next one should be 4208 // Now, every connection has been pinged once. The next one should be
4190 // Relay/Relay. 4209 // Relay/Relay.
4191 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE); 4210 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
4192 } 4211 }
4193 4212
4194 // Test the ping sequence is UDP Relay/Relay followed by TCP Relay/Relay, 4213 // Test the ping sequence is UDP Relay/Relay followed by TCP Relay/Relay,
4195 // followed by the rest. 4214 // followed by the rest.
4196 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestTcpTurn) { 4215 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestTcpTurn) {
4197 // Add a Tcp Turn server. 4216 // Add a Tcp Turn server.
4198 turn_server()->AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); 4217 turn_server()->AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
4199 RelayServerConfig config(RELAY_TURN); 4218 RelayServerConfig config(RELAY_TURN);
4200 config.credentials = kRelayCredentials; 4219 config.credentials = kRelayCredentials;
4201 config.ports.push_back(ProtocolAddress(kTurnTcpIntAddr, PROTO_TCP, false)); 4220 config.ports.push_back(ProtocolAddress(kTurnTcpIntAddr, PROTO_TCP, false));
4202 allocator()->AddTurnServer(config); 4221 allocator()->AddTurnServer(config);
4203 4222
4204 P2PTransportChannel& ch = StartTransportChannel(true, 100); 4223 P2PTransportChannel& ch = StartTransportChannel(true, 100);
4205 EXPECT_TRUE_WAIT(ch.ports().size() == 3, 5000); 4224 EXPECT_TRUE_WAIT(ch.ports().size() == 3, kDefaultTimeout);
4206 EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE); 4225 EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE);
4207 EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE); 4226 EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE);
4208 EXPECT_EQ(ch.ports()[2]->Type(), RELAY_PORT_TYPE); 4227 EXPECT_EQ(ch.ports()[2]->Type(), RELAY_PORT_TYPE);
4209 4228
4210 // Remote Relay candidate arrives. 4229 // Remote Relay candidate arrives.
4211 ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1)); 4230 ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1));
4212 EXPECT_TRUE_WAIT(ch.connections().size() == 3, 5000); 4231 EXPECT_TRUE_WAIT(ch.connections().size() == 3, kDefaultTimeout);
4213 4232
4214 // UDP Relay/Relay should be pinged first. 4233 // UDP Relay/Relay should be pinged first.
4215 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE); 4234 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE);
4216 4235
4217 // TCP Relay/Relay is the next. 4236 // TCP Relay/Relay is the next.
4218 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 4237 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
4219 TCP_PROTOCOL_NAME); 4238 TCP_PROTOCOL_NAME);
4220 4239
4221 // Finally, Local/Relay will be pinged. 4240 // Finally, Local/Relay will be pinged.
4222 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 4241 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
4223 } 4242 }
4224 4243
4225 } // namespace cricket { 4244 } // namespace cricket {
OLDNEW
« no previous file with comments | « no previous file | webrtc/p2p/base/port_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698