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

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

Issue 2442813002: Fix more swarming test failures by using fake clock. (Closed)
Patch Set: Advance the clock by 1 second to avoid test failure due to assumptions on non-zero actual time valu… Created 4 years, 1 month 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.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 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 const std::string& local_protocol = LocalCandidate(ep2_ch1())->protocol(); 533 const std::string& local_protocol = LocalCandidate(ep2_ch1())->protocol();
534 const std::string& remote_type = RemoteCandidate(ep2_ch1())->type(); 534 const std::string& remote_type = RemoteCandidate(ep2_ch1())->type();
535 const std::string& remote_protocol = RemoteCandidate(ep2_ch1())->protocol(); 535 const std::string& remote_protocol = RemoteCandidate(ep2_ch1())->protocol();
536 EXPECT_EQ(expected.controlled_type, local_type); 536 EXPECT_EQ(expected.controlled_type, local_type);
537 EXPECT_EQ(expected.controlling_type, remote_type); 537 EXPECT_EQ(expected.controlling_type, remote_type);
538 EXPECT_EQ(expected.controlled_protocol, local_protocol); 538 EXPECT_EQ(expected.controlled_protocol, local_protocol);
539 EXPECT_EQ(expected.controlling_protocol, remote_protocol); 539 EXPECT_EQ(expected.controlling_protocol, remote_protocol);
540 } 540 }
541 541
542 void Test(const Result& expected) { 542 void Test(const Result& expected) {
543 rtc::ScopedFakeClock clock;
543 int64_t connect_start = rtc::TimeMillis(); 544 int64_t connect_start = rtc::TimeMillis();
544 int64_t connect_time; 545 int64_t connect_time;
545 546
546 // Create the channels and wait for them to connect. 547 // Create the channels and wait for them to connect.
547 CreateChannels(); 548 CreateChannels();
548 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && 549 EXPECT_TRUE_SIMULATED_WAIT(
549 ep1_ch1()->receiving() && 550 ep1_ch1() != NULL && ep2_ch1() != NULL && ep1_ch1()->receiving() &&
550 ep1_ch1()->writable() && 551 ep1_ch1()->writable() && ep2_ch1()->receiving() &&
551 ep2_ch1()->receiving() && ep2_ch1()->writable(), 552 ep2_ch1()->writable(),
552 expected.connect_wait, kShortTimeout); 553 expected.connect_wait + kShortTimeout, clock);
553 connect_time = rtc::TimeMillis() - connect_start; 554 connect_time = rtc::TimeMillis() - connect_start;
554 if (connect_time < expected.connect_wait) { 555 if (connect_time < expected.connect_wait) {
555 LOG(LS_INFO) << "Connect time: " << connect_time << " ms"; 556 LOG(LS_INFO) << "Connect time: " << connect_time << " ms";
556 } else { 557 } else {
557 LOG(LS_INFO) << "Connect time: " << "TIMEOUT (" 558 LOG(LS_INFO) << "Connect time: " << "TIMEOUT ("
558 << expected.connect_wait << " ms)"; 559 << expected.connect_wait << " ms)";
559 } 560 }
560 561
561 // Allow a few turns of the crank for the selected connections to emerge. 562 // Allow a few turns of the crank for the selected connections to emerge.
562 // This may take up to 2 seconds. 563 // This may take up to 2 seconds.
563 if (ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection()) { 564 if (ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection()) {
564 int64_t converge_start = rtc::TimeMillis(); 565 int64_t converge_start = rtc::TimeMillis();
565 int64_t converge_time; 566 int64_t converge_time;
566 int64_t converge_wait = 2000;
567 // Verifying local and remote channel selected connection information. 567 // Verifying local and remote channel selected connection information.
568 // This is done only for the RFC 5245 as controlled agent will use 568 // This is done only for the RFC 5245 as controlled agent will use
569 // USE-CANDIDATE from controlling (ep1) agent. We can easily predict from 569 // USE-CANDIDATE from controlling (ep1) agent. We can easily predict from
570 // EP1 result matrix. 570 // EP1 result matrix.
571 EXPECT_TRUE_WAIT_MARGIN( 571 EXPECT_TRUE_SIMULATED_WAIT(
572 CheckCandidate1(expected) && CheckCandidate2(expected), converge_wait, 572 CheckCandidate1(expected) && CheckCandidate2(expected),
573 converge_wait); 573 kMediumTimeout, clock);
574 // Also do EXPECT_EQ on each part so that failures are more verbose. 574 // Also do EXPECT_EQ on each part so that failures are more verbose.
575 ExpectCandidate1(expected); 575 ExpectCandidate1(expected);
576 ExpectCandidate2(expected); 576 ExpectCandidate2(expected);
577 577
578 converge_time = rtc::TimeMillis() - converge_start; 578 converge_time = rtc::TimeMillis() - converge_start;
579 int64_t converge_wait = 2000;
579 if (converge_time < converge_wait) { 580 if (converge_time < converge_wait) {
580 LOG(LS_INFO) << "Converge time: " << converge_time << " ms"; 581 LOG(LS_INFO) << "Converge time: " << converge_time << " ms";
581 } else { 582 } else {
582 LOG(LS_INFO) << "Converge time: " << "TIMEOUT (" 583 LOG(LS_INFO) << "Converge time: " << "TIMEOUT ("
583 << converge_wait << " ms)"; 584 << converge_wait << " ms)";
584 } 585 }
585 } 586 }
586 // Try sending some data to other end. 587 // Try sending some data to other end.
587 TestSendRecv(); 588 TestSendRecv(clock);
588 589
589 // Destroy the channels, and wait for them to be fully cleaned up. 590 // Destroy the channels, and wait for them to be fully cleaned up.
590 DestroyChannels(); 591 DestroyChannels();
591 } 592 }
592 593
593 void TestSendRecv() { 594 void TestSendRecv(rtc::FakeClock& clock) {
594 for (int i = 0; i < 10; ++i) { 595 for (int i = 0; i < 10; ++i) {
595 const char* data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; 596 const char* data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
596 int len = static_cast<int>(strlen(data)); 597 int len = static_cast<int>(strlen(data));
597 // local_channel1 <==> remote_channel1 598 // local_channel1 <==> remote_channel1
598 EXPECT_EQ_WAIT(len, SendData(ep1_ch1(), data, len), kMediumTimeout); 599 EXPECT_EQ_SIMULATED_WAIT(len, SendData(ep1_ch1(), data, len),
599 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch1(), data, len), 600 kMediumTimeout, clock);
600 kMediumTimeout); 601 EXPECT_TRUE_SIMULATED_WAIT(CheckDataOnChannel(ep2_ch1(), data, len),
601 EXPECT_EQ_WAIT(len, SendData(ep2_ch1(), data, len), kMediumTimeout); 602 kMediumTimeout, clock);
602 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch1(), data, len), 603 EXPECT_EQ_SIMULATED_WAIT(len, SendData(ep2_ch1(), data, len),
603 kMediumTimeout); 604 kMediumTimeout, clock);
605 EXPECT_TRUE_SIMULATED_WAIT(CheckDataOnChannel(ep1_ch1(), data, len),
606 kMediumTimeout, clock);
604 } 607 }
605 } 608 }
606 609
607 // This test waits for the transport to become receiving and writable on both 610 // This test waits for the transport to become receiving and writable on both
608 // end points. Once they are, the end points set new local ice parameters and 611 // end points. Once they are, the end points set new local ice parameters and
609 // restart the ice gathering. Finally it waits for the transport to select a 612 // restart the ice gathering. Finally it waits for the transport to select a
610 // new connection using the newly generated ice candidates. 613 // new connection using the newly generated ice candidates.
611 // Before calling this function the end points must be configured. 614 // Before calling this function the end points must be configured.
612 void TestHandleIceUfragPasswordChanged() { 615 void TestHandleIceUfragPasswordChanged() {
616 rtc::ScopedFakeClock clock;
613 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]); 617 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]);
614 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]); 618 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]);
615 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && 619 EXPECT_TRUE_SIMULATED_WAIT(
616 ep2_ch1()->receiving() && ep2_ch1()->writable(), 620 ep1_ch1()->receiving() && ep1_ch1()->writable() &&
617 kShortTimeout, kShortTimeout); 621 ep2_ch1()->receiving() && ep2_ch1()->writable(),
622 kMediumTimeout, clock);
618 623
619 const Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1()); 624 const Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1());
620 const Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1()); 625 const Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1());
621 const Candidate* old_remote_candidate1 = RemoteCandidate(ep1_ch1()); 626 const Candidate* old_remote_candidate1 = RemoteCandidate(ep1_ch1());
622 const Candidate* old_remote_candidate2 = RemoteCandidate(ep2_ch1()); 627 const Candidate* old_remote_candidate2 = RemoteCandidate(ep2_ch1());
623 628
624 ep1_ch1()->SetIceParameters(kIceParams[2]); 629 ep1_ch1()->SetIceParameters(kIceParams[2]);
625 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]); 630 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
626 ep1_ch1()->MaybeStartGathering(); 631 ep1_ch1()->MaybeStartGathering();
627 ep2_ch1()->SetIceParameters(kIceParams[3]); 632 ep2_ch1()->SetIceParameters(kIceParams[3]);
628 633
629 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]); 634 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]);
630 ep2_ch1()->MaybeStartGathering(); 635 ep2_ch1()->MaybeStartGathering();
631 636
632 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() != 637 EXPECT_TRUE_SIMULATED_WAIT(LocalCandidate(ep1_ch1())->generation() !=
633 old_local_candidate1->generation(), 638 old_local_candidate1->generation(),
634 kShortTimeout, kShortTimeout); 639 kMediumTimeout, clock);
635 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep2_ch1())->generation() != 640 EXPECT_TRUE_SIMULATED_WAIT(LocalCandidate(ep2_ch1())->generation() !=
636 old_local_candidate2->generation(), 641 old_local_candidate2->generation(),
637 kShortTimeout, kShortTimeout); 642 kMediumTimeout, clock);
638 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep1_ch1())->generation() != 643 EXPECT_TRUE_SIMULATED_WAIT(RemoteCandidate(ep1_ch1())->generation() !=
639 old_remote_candidate1->generation(), 644 old_remote_candidate1->generation(),
640 kShortTimeout, kShortTimeout); 645 kMediumTimeout, clock);
641 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep2_ch1())->generation() != 646 EXPECT_TRUE_SIMULATED_WAIT(RemoteCandidate(ep2_ch1())->generation() !=
642 old_remote_candidate2->generation(), 647 old_remote_candidate2->generation(),
643 kShortTimeout, kShortTimeout); 648 kMediumTimeout, clock);
644 EXPECT_EQ(1u, RemoteCandidate(ep2_ch1())->generation()); 649 EXPECT_EQ(1u, RemoteCandidate(ep2_ch1())->generation());
645 EXPECT_EQ(1u, RemoteCandidate(ep1_ch1())->generation()); 650 EXPECT_EQ(1u, RemoteCandidate(ep1_ch1())->generation());
646 } 651 }
647 652
648 void TestSignalRoleConflict() { 653 void TestSignalRoleConflict() {
649 SetIceTiebreaker(0, 654 rtc::ScopedFakeClock clock;
650 kLowTiebreaker); // Default EP1 is in controlling state. 655 // Default EP1 is in controlling state.
656 SetIceTiebreaker(0, kLowTiebreaker);
651 657
652 SetIceRole(1, ICEROLE_CONTROLLING); 658 SetIceRole(1, ICEROLE_CONTROLLING);
653 SetIceTiebreaker(1, kHighTiebreaker); 659 SetIceTiebreaker(1, kHighTiebreaker);
654 660
655 // Creating channels with both channels role set to CONTROLLING. 661 // Creating channels with both channels role set to CONTROLLING.
656 CreateChannels(); 662 CreateChannels();
657 // Since both the channels initiated with controlling state and channel2 663 // Since both the channels initiated with controlling state and channel2
658 // has higher tiebreaker value, channel1 should receive SignalRoleConflict. 664 // has higher tiebreaker value, channel1 should receive SignalRoleConflict.
659 EXPECT_TRUE_WAIT(GetRoleConflict(0), kShortTimeout); 665 EXPECT_TRUE_SIMULATED_WAIT(GetRoleConflict(0), kShortTimeout, clock);
660 EXPECT_FALSE(GetRoleConflict(1)); 666 EXPECT_FALSE(GetRoleConflict(1));
661 667
662 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 668 EXPECT_TRUE_SIMULATED_WAIT(
663 ep2_ch1()->receiving() && ep2_ch1()->writable(), 669 ep1_ch1()->receiving() && ep1_ch1()->writable() &&
664 kShortTimeout); 670 ep2_ch1()->receiving() && ep2_ch1()->writable(),
671 kShortTimeout, clock);
665 672
666 EXPECT_TRUE(ep1_ch1()->selected_connection() && 673 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
667 ep2_ch1()->selected_connection()); 674 ep2_ch1()->selected_connection());
668 675
669 TestSendRecv(); 676 TestSendRecv(clock);
670 } 677 }
671 678
672 void OnReadyToSend(TransportChannel* ch) { 679 void OnReadyToSend(TransportChannel* ch) {
673 GetEndpoint(ch)->ready_to_send_ = true; 680 GetEndpoint(ch)->ready_to_send_ = true;
674 } 681 }
675 682
676 // We pass the candidates directly to the other side. 683 // We pass the candidates directly to the other side.
677 void OnCandidateGathered(TransportChannelImpl* ch, const Candidate& c) { 684 void OnCandidateGathered(TransportChannelImpl* ch, const Candidate& c) {
678 if (force_relay_ && c.type() != RELAY_PORT_TYPE) 685 if (force_relay_ && c.type() != RELAY_PORT_TYPE)
679 return; 686 return;
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 TEST_F(P2PTransportChannelTest, HandleUfragPwdChangeSymmetricNat) { 1155 TEST_F(P2PTransportChannelTest, HandleUfragPwdChangeSymmetricNat) {
1149 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, 1156 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags,
1150 kDefaultPortAllocatorFlags); 1157 kDefaultPortAllocatorFlags);
1151 CreateChannels(); 1158 CreateChannels();
1152 TestHandleIceUfragPasswordChanged(); 1159 TestHandleIceUfragPasswordChanged();
1153 DestroyChannels(); 1160 DestroyChannels();
1154 } 1161 }
1155 1162
1156 // Test the operation of GetStats. 1163 // Test the operation of GetStats.
1157 TEST_F(P2PTransportChannelTest, GetStats) { 1164 TEST_F(P2PTransportChannelTest, GetStats) {
1165 rtc::ScopedFakeClock clock;
1158 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1166 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1159 kDefaultPortAllocatorFlags); 1167 kDefaultPortAllocatorFlags);
1160 CreateChannels(); 1168 CreateChannels();
1161 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1169 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1162 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1170 ep2_ch1()->receiving() &&
1163 kShortTimeout, kShortTimeout); 1171 ep2_ch1()->writable(),
1164 TestSendRecv(); 1172 kMediumTimeout, clock);
1173 TestSendRecv(clock);
1165 ConnectionInfos infos; 1174 ConnectionInfos infos;
1166 ASSERT_TRUE(ep1_ch1()->GetStats(&infos)); 1175 ASSERT_TRUE(ep1_ch1()->GetStats(&infos));
1167 ASSERT_TRUE(infos.size() >= 1); 1176 ASSERT_TRUE(infos.size() >= 1);
1168 ConnectionInfo* best_conn_info = nullptr; 1177 ConnectionInfo* best_conn_info = nullptr;
1169 for (ConnectionInfo& info : infos) { 1178 for (ConnectionInfo& info : infos) {
1170 if (info.best_connection) { 1179 if (info.best_connection) {
1171 best_conn_info = &info; 1180 best_conn_info = &info;
1172 break; 1181 break;
1173 } 1182 }
1174 } 1183 }
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 // Wait to make sure the selected connection is not changed. 1516 // Wait to make sure the selected connection is not changed.
1508 SIMULATED_WAIT(ep2_ch1()->selected_connection() != selected_connection, 1517 SIMULATED_WAIT(ep2_ch1()->selected_connection() != selected_connection,
1509 kShortTimeout, clock); 1518 kShortTimeout, clock);
1510 EXPECT_TRUE(ep2_ch1()->selected_connection() == selected_connection); 1519 EXPECT_TRUE(ep2_ch1()->selected_connection() == selected_connection);
1511 DestroyChannels(); 1520 DestroyChannels();
1512 } 1521 }
1513 1522
1514 // Test that a host behind NAT cannot be reached when incoming_only 1523 // Test that a host behind NAT cannot be reached when incoming_only
1515 // is set to true. 1524 // is set to true.
1516 TEST_F(P2PTransportChannelTest, IncomingOnlyBlocked) { 1525 TEST_F(P2PTransportChannelTest, IncomingOnlyBlocked) {
1526 rtc::ScopedFakeClock clock;
1517 ConfigureEndpoints(NAT_FULL_CONE, OPEN, kDefaultPortAllocatorFlags, 1527 ConfigureEndpoints(NAT_FULL_CONE, OPEN, kDefaultPortAllocatorFlags,
1518 kDefaultPortAllocatorFlags); 1528 kDefaultPortAllocatorFlags);
1519 1529
1520 SetAllocatorFlags(0, kOnlyLocalPorts); 1530 SetAllocatorFlags(0, kOnlyLocalPorts);
1521 CreateChannels(); 1531 CreateChannels();
1522 ep1_ch1()->set_incoming_only(true); 1532 ep1_ch1()->set_incoming_only(true);
1523 1533
1524 // Pump for 1 second and verify that the channels are not connected. 1534 // Pump for 1 second and verify that the channels are not connected.
1525 rtc::Thread::Current()->ProcessMessages(kShortTimeout); 1535 SIMULATED_WAIT(false, kShortTimeout, clock);
1526 1536
1527 EXPECT_FALSE(ep1_ch1()->receiving()); 1537 EXPECT_FALSE(ep1_ch1()->receiving());
1528 EXPECT_FALSE(ep1_ch1()->writable()); 1538 EXPECT_FALSE(ep1_ch1()->writable());
1529 EXPECT_FALSE(ep2_ch1()->receiving()); 1539 EXPECT_FALSE(ep2_ch1()->receiving());
1530 EXPECT_FALSE(ep2_ch1()->writable()); 1540 EXPECT_FALSE(ep2_ch1()->writable());
1531 1541
1532 DestroyChannels(); 1542 DestroyChannels();
1533 } 1543 }
1534 1544
1535 // Test that a peer behind NAT can connect to a peer that has 1545 // Test that a peer behind NAT can connect to a peer that has
1536 // incoming_only flag set. 1546 // incoming_only flag set.
1537 TEST_F(P2PTransportChannelTest, IncomingOnlyOpen) { 1547 TEST_F(P2PTransportChannelTest, IncomingOnlyOpen) {
1548 rtc::ScopedFakeClock clock;
1538 ConfigureEndpoints(OPEN, NAT_FULL_CONE, kDefaultPortAllocatorFlags, 1549 ConfigureEndpoints(OPEN, NAT_FULL_CONE, kDefaultPortAllocatorFlags,
1539 kDefaultPortAllocatorFlags); 1550 kDefaultPortAllocatorFlags);
1540 1551
1541 SetAllocatorFlags(0, kOnlyLocalPorts); 1552 SetAllocatorFlags(0, kOnlyLocalPorts);
1542 CreateChannels(); 1553 CreateChannels();
1543 ep1_ch1()->set_incoming_only(true); 1554 ep1_ch1()->set_incoming_only(true);
1544 1555
1545 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && 1556 EXPECT_TRUE_SIMULATED_WAIT(
1546 ep1_ch1()->receiving() && ep1_ch1()->writable() && 1557 ep1_ch1() != NULL && ep2_ch1() != NULL && ep1_ch1()->receiving() &&
1547 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1558 ep1_ch1()->writable() && ep2_ch1()->receiving() &&
1548 kShortTimeout, kShortTimeout); 1559 ep2_ch1()->writable(),
1560 kMediumTimeout, clock);
1549 1561
1550 DestroyChannels(); 1562 DestroyChannels();
1551 } 1563 }
1552 1564
1553 TEST_F(P2PTransportChannelTest, TestTcpConnectionsFromActiveToPassive) { 1565 TEST_F(P2PTransportChannelTest, TestTcpConnectionsFromActiveToPassive) {
1566 rtc::ScopedFakeClock clock;
1554 AddAddress(0, kPublicAddrs[0]); 1567 AddAddress(0, kPublicAddrs[0]);
1555 AddAddress(1, kPublicAddrs[1]); 1568 AddAddress(1, kPublicAddrs[1]);
1556 1569
1557 SetAllocationStepDelay(0, kMinimumStepDelay); 1570 SetAllocationStepDelay(0, kMinimumStepDelay);
1558 SetAllocationStepDelay(1, kMinimumStepDelay); 1571 SetAllocationStepDelay(1, kMinimumStepDelay);
1559 1572
1560 int kOnlyLocalTcpPorts = PORTALLOCATOR_DISABLE_UDP | 1573 int kOnlyLocalTcpPorts = PORTALLOCATOR_DISABLE_UDP |
1561 PORTALLOCATOR_DISABLE_STUN | 1574 PORTALLOCATOR_DISABLE_STUN |
1562 PORTALLOCATOR_DISABLE_RELAY; 1575 PORTALLOCATOR_DISABLE_RELAY;
1563 // Disable all protocols except TCP. 1576 // Disable all protocols except TCP.
(...skipping 14 matching lines...) Expand all
1578 CreateChannels(); 1591 CreateChannels();
1579 1592
1580 // Verify tcp candidates. 1593 // Verify tcp candidates.
1581 VerifySavedTcpCandidates(0, TCPTYPE_PASSIVE_STR); 1594 VerifySavedTcpCandidates(0, TCPTYPE_PASSIVE_STR);
1582 VerifySavedTcpCandidates(1, TCPTYPE_ACTIVE_STR); 1595 VerifySavedTcpCandidates(1, TCPTYPE_ACTIVE_STR);
1583 1596
1584 // Resume candidates. 1597 // Resume candidates.
1585 ResumeCandidates(0); 1598 ResumeCandidates(0);
1586 ResumeCandidates(1); 1599 ResumeCandidates(1);
1587 1600
1588 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1601 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1589 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1602 ep2_ch1()->receiving() &&
1590 kShortTimeout); 1603 ep2_ch1()->writable(),
1604 kShortTimeout, clock);
1591 EXPECT_TRUE(ep1_ch1()->selected_connection() && 1605 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
1592 ep2_ch1()->selected_connection() && 1606 ep2_ch1()->selected_connection() &&
1593 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 1607 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
1594 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 1608 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
1595 1609
1596 TestSendRecv(); 1610 TestSendRecv(clock);
1597 DestroyChannels(); 1611 DestroyChannels();
1598 } 1612 }
1599 1613
1600 TEST_F(P2PTransportChannelTest, TestIceRoleConflict) { 1614 TEST_F(P2PTransportChannelTest, TestIceRoleConflict) {
1601 AddAddress(0, kPublicAddrs[0]); 1615 AddAddress(0, kPublicAddrs[0]);
1602 AddAddress(1, kPublicAddrs[1]); 1616 AddAddress(1, kPublicAddrs[1]);
1603 TestSignalRoleConflict(); 1617 TestSignalRoleConflict();
1604 } 1618 }
1605 1619
1606 // Tests that the ice configs (protocol, tiebreaker and role) can be passed 1620 // Tests that the ice configs (protocol, tiebreaker and role) can be passed
1607 // down to ports. 1621 // down to ports.
1608 TEST_F(P2PTransportChannelTest, TestIceConfigWillPassDownToPort) { 1622 TEST_F(P2PTransportChannelTest, TestIceConfigWillPassDownToPort) {
1623 rtc::ScopedFakeClock clock;
1609 AddAddress(0, kPublicAddrs[0]); 1624 AddAddress(0, kPublicAddrs[0]);
1610 AddAddress(1, kPublicAddrs[1]); 1625 AddAddress(1, kPublicAddrs[1]);
1611 1626
1612 // Give the first connection the higher tiebreaker so its role won't 1627 // Give the first connection the higher tiebreaker so its role won't
1613 // change unless we tell it to. 1628 // change unless we tell it to.
1614 SetIceRole(0, ICEROLE_CONTROLLING); 1629 SetIceRole(0, ICEROLE_CONTROLLING);
1615 SetIceTiebreaker(0, kHighTiebreaker); 1630 SetIceTiebreaker(0, kHighTiebreaker);
1616 SetIceRole(1, ICEROLE_CONTROLLING); 1631 SetIceRole(1, ICEROLE_CONTROLLING);
1617 SetIceTiebreaker(1, kLowTiebreaker); 1632 SetIceTiebreaker(1, kLowTiebreaker);
1618 1633
1619 CreateChannels(); 1634 CreateChannels();
1620 1635
1621 EXPECT_EQ_WAIT(2u, ep1_ch1()->ports().size(), kShortTimeout); 1636 EXPECT_EQ_SIMULATED_WAIT(2u, ep1_ch1()->ports().size(), kShortTimeout, clock);
1622 1637
1623 const std::vector<PortInterface*> ports_before = ep1_ch1()->ports(); 1638 const std::vector<PortInterface*> ports_before = ep1_ch1()->ports();
1624 for (size_t i = 0; i < ports_before.size(); ++i) { 1639 for (size_t i = 0; i < ports_before.size(); ++i) {
1625 EXPECT_EQ(ICEROLE_CONTROLLING, ports_before[i]->GetIceRole()); 1640 EXPECT_EQ(ICEROLE_CONTROLLING, ports_before[i]->GetIceRole());
1626 EXPECT_EQ(kHighTiebreaker, ports_before[i]->IceTiebreaker()); 1641 EXPECT_EQ(kHighTiebreaker, ports_before[i]->IceTiebreaker());
1627 } 1642 }
1628 1643
1629 ep1_ch1()->SetIceRole(ICEROLE_CONTROLLED); 1644 ep1_ch1()->SetIceRole(ICEROLE_CONTROLLED);
1630 ep1_ch1()->SetIceTiebreaker(kLowTiebreaker); 1645 ep1_ch1()->SetIceTiebreaker(kLowTiebreaker);
1631 1646
1632 const std::vector<PortInterface*> ports_after = ep1_ch1()->ports(); 1647 const std::vector<PortInterface*> ports_after = ep1_ch1()->ports();
1633 for (size_t i = 0; i < ports_after.size(); ++i) { 1648 for (size_t i = 0; i < ports_after.size(); ++i) {
1634 EXPECT_EQ(ICEROLE_CONTROLLED, ports_before[i]->GetIceRole()); 1649 EXPECT_EQ(ICEROLE_CONTROLLED, ports_before[i]->GetIceRole());
1635 // SetIceTiebreaker after ports have been created will fail. So expect the 1650 // SetIceTiebreaker after ports have been created will fail. So expect the
1636 // original value. 1651 // original value.
1637 EXPECT_EQ(kHighTiebreaker, ports_before[i]->IceTiebreaker()); 1652 EXPECT_EQ(kHighTiebreaker, ports_before[i]->IceTiebreaker());
1638 } 1653 }
1639 1654
1640 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1655 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1641 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1656 ep2_ch1()->receiving() &&
1642 kShortTimeout); 1657 ep2_ch1()->writable(),
1658 kShortTimeout, clock);
1643 1659
1644 EXPECT_TRUE(ep1_ch1()->selected_connection() && 1660 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
1645 ep2_ch1()->selected_connection()); 1661 ep2_ch1()->selected_connection());
1646 1662
1647 TestSendRecv(); 1663 TestSendRecv(clock);
1648 DestroyChannels(); 1664 DestroyChannels();
1649 } 1665 }
1650 1666
1651 // Verify that we can set DSCP value and retrieve properly from P2PTC. 1667 // Verify that we can set DSCP value and retrieve properly from P2PTC.
1652 TEST_F(P2PTransportChannelTest, TestDefaultDscpValue) { 1668 TEST_F(P2PTransportChannelTest, TestDefaultDscpValue) {
1653 AddAddress(0, kPublicAddrs[0]); 1669 AddAddress(0, kPublicAddrs[0]);
1654 AddAddress(1, kPublicAddrs[1]); 1670 AddAddress(1, kPublicAddrs[1]);
1655 1671
1656 CreateChannels(); 1672 CreateChannels();
1657 EXPECT_EQ(rtc::DSCP_NO_CHANGE, 1673 EXPECT_EQ(rtc::DSCP_NO_CHANGE,
(...skipping 13 matching lines...) Expand all
1671 GetEndpoint(1)->cd1_.ch_->SetOption( 1687 GetEndpoint(1)->cd1_.ch_->SetOption(
1672 rtc::Socket::OPT_DSCP, rtc::DSCP_AF41); 1688 rtc::Socket::OPT_DSCP, rtc::DSCP_AF41);
1673 EXPECT_EQ(rtc::DSCP_AF41, 1689 EXPECT_EQ(rtc::DSCP_AF41,
1674 GetEndpoint(0)->cd1_.ch_->DefaultDscpValue()); 1690 GetEndpoint(0)->cd1_.ch_->DefaultDscpValue());
1675 EXPECT_EQ(rtc::DSCP_AF41, 1691 EXPECT_EQ(rtc::DSCP_AF41,
1676 GetEndpoint(1)->cd1_.ch_->DefaultDscpValue()); 1692 GetEndpoint(1)->cd1_.ch_->DefaultDscpValue());
1677 } 1693 }
1678 1694
1679 // Verify IPv6 connection is preferred over IPv4. 1695 // Verify IPv6 connection is preferred over IPv4.
1680 TEST_F(P2PTransportChannelTest, TestIPv6Connections) { 1696 TEST_F(P2PTransportChannelTest, TestIPv6Connections) {
1697 rtc::ScopedFakeClock clock;
1681 AddAddress(0, kIPv6PublicAddrs[0]); 1698 AddAddress(0, kIPv6PublicAddrs[0]);
1682 AddAddress(0, kPublicAddrs[0]); 1699 AddAddress(0, kPublicAddrs[0]);
1683 AddAddress(1, kIPv6PublicAddrs[1]); 1700 AddAddress(1, kIPv6PublicAddrs[1]);
1684 AddAddress(1, kPublicAddrs[1]); 1701 AddAddress(1, kPublicAddrs[1]);
1685 1702
1686 SetAllocationStepDelay(0, kMinimumStepDelay); 1703 SetAllocationStepDelay(0, kMinimumStepDelay);
1687 SetAllocationStepDelay(1, kMinimumStepDelay); 1704 SetAllocationStepDelay(1, kMinimumStepDelay);
1688 1705
1689 // Enable IPv6 1706 // Enable IPv6
1690 SetAllocatorFlags(0, PORTALLOCATOR_ENABLE_IPV6); 1707 SetAllocatorFlags(0, PORTALLOCATOR_ENABLE_IPV6);
1691 SetAllocatorFlags(1, PORTALLOCATOR_ENABLE_IPV6); 1708 SetAllocatorFlags(1, PORTALLOCATOR_ENABLE_IPV6);
1692 1709
1693 CreateChannels(); 1710 CreateChannels();
1694 1711
1695 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1712 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1696 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1713 ep2_ch1()->receiving() &&
1697 kShortTimeout); 1714 ep2_ch1()->writable(),
1715 kShortTimeout, clock);
1698 EXPECT_TRUE( 1716 EXPECT_TRUE(
1699 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && 1717 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
1700 LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) && 1718 LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) &&
1701 RemoteCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[1])); 1719 RemoteCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[1]));
1702 1720
1703 TestSendRecv(); 1721 TestSendRecv(clock);
1704 DestroyChannels(); 1722 DestroyChannels();
1705 } 1723 }
1706 1724
1707 // Testing forceful TURN connections. 1725 // Testing forceful TURN connections.
1708 TEST_F(P2PTransportChannelTest, TestForceTurn) { 1726 TEST_F(P2PTransportChannelTest, TestForceTurn) {
1727 rtc::ScopedFakeClock clock;
1709 ConfigureEndpoints( 1728 ConfigureEndpoints(
1710 NAT_PORT_RESTRICTED, NAT_SYMMETRIC, 1729 NAT_PORT_RESTRICTED, NAT_SYMMETRIC,
1711 kDefaultPortAllocatorFlags | PORTALLOCATOR_ENABLE_SHARED_SOCKET, 1730 kDefaultPortAllocatorFlags | PORTALLOCATOR_ENABLE_SHARED_SOCKET,
1712 kDefaultPortAllocatorFlags | PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1731 kDefaultPortAllocatorFlags | PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1713 set_force_relay(true); 1732 set_force_relay(true);
1714 1733
1715 SetAllocationStepDelay(0, kMinimumStepDelay); 1734 SetAllocationStepDelay(0, kMinimumStepDelay);
1716 SetAllocationStepDelay(1, kMinimumStepDelay); 1735 SetAllocationStepDelay(1, kMinimumStepDelay);
1717 1736
1718 CreateChannels(); 1737 CreateChannels();
1719 1738
1720 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1739 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1721 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1740 ep2_ch1()->receiving() &&
1722 kMediumTimeout); 1741 ep2_ch1()->writable(),
1742 kMediumTimeout, clock);
1723 1743
1724 EXPECT_TRUE(ep1_ch1()->selected_connection() && 1744 EXPECT_TRUE(ep1_ch1()->selected_connection() &&
1725 ep2_ch1()->selected_connection()); 1745 ep2_ch1()->selected_connection());
1726 1746
1727 EXPECT_EQ("relay", RemoteCandidate(ep1_ch1())->type()); 1747 EXPECT_EQ("relay", RemoteCandidate(ep1_ch1())->type());
1728 EXPECT_EQ("relay", LocalCandidate(ep1_ch1())->type()); 1748 EXPECT_EQ("relay", LocalCandidate(ep1_ch1())->type());
1729 EXPECT_EQ("relay", RemoteCandidate(ep2_ch1())->type()); 1749 EXPECT_EQ("relay", RemoteCandidate(ep2_ch1())->type());
1730 EXPECT_EQ("relay", LocalCandidate(ep2_ch1())->type()); 1750 EXPECT_EQ("relay", LocalCandidate(ep2_ch1())->type());
1731 1751
1732 TestSendRecv(); 1752 TestSendRecv(clock);
1733 DestroyChannels(); 1753 DestroyChannels();
1734 } 1754 }
1735 1755
1736 // Test that if continual gathering is set to true, ICE gathering state will 1756 // Test that if continual gathering is set to true, ICE gathering state will
1737 // not change to "Complete", and vice versa. 1757 // not change to "Complete", and vice versa.
1738 TEST_F(P2PTransportChannelTest, TestContinualGathering) { 1758 TEST_F(P2PTransportChannelTest, TestContinualGathering) {
1739 rtc::ScopedFakeClock clock; 1759 rtc::ScopedFakeClock clock;
1740 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1760 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1741 kDefaultPortAllocatorFlags); 1761 kDefaultPortAllocatorFlags);
1742 SetAllocationStepDelay(0, kDefaultStepDelay); 1762 SetAllocationStepDelay(0, kDefaultStepDelay);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1789 EXPECT_TRUE(pooled_session_1->ReadyCandidates().empty()); 1809 EXPECT_TRUE(pooled_session_1->ReadyCandidates().empty());
1790 EXPECT_TRUE(pooled_session_2->ReadyPorts().empty()); 1810 EXPECT_TRUE(pooled_session_2->ReadyPorts().empty());
1791 EXPECT_TRUE(pooled_session_2->ReadyCandidates().empty()); 1811 EXPECT_TRUE(pooled_session_2->ReadyCandidates().empty());
1792 // Now let the endpoints connect and try exchanging some data. 1812 // Now let the endpoints connect and try exchanging some data.
1793 CreateChannels(); 1813 CreateChannels();
1794 EXPECT_TRUE_SIMULATED_WAIT( 1814 EXPECT_TRUE_SIMULATED_WAIT(
1795 ep1_ch1() != NULL && ep2_ch1() != NULL && ep1_ch1()->receiving() && 1815 ep1_ch1() != NULL && ep2_ch1() != NULL && ep1_ch1()->receiving() &&
1796 ep1_ch1()->writable() && ep2_ch1()->receiving() && 1816 ep1_ch1()->writable() && ep2_ch1()->receiving() &&
1797 ep2_ch1()->writable(), 1817 ep2_ch1()->writable(),
1798 kMediumTimeout, clock); 1818 kMediumTimeout, clock);
1799 TestSendRecv(); 1819 TestSendRecv(clock);
1800 // Make sure the P2PTransportChannels are actually using ports from the 1820 // Make sure the P2PTransportChannels are actually using ports from the
1801 // pooled sessions. 1821 // pooled sessions.
1802 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); 1822 auto pooled_ports_1 = pooled_session_1->ReadyPorts();
1803 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); 1823 auto pooled_ports_2 = pooled_session_2->ReadyPorts();
1804 EXPECT_NE(pooled_ports_1.end(), 1824 EXPECT_NE(pooled_ports_1.end(),
1805 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), 1825 std::find(pooled_ports_1.begin(), pooled_ports_1.end(),
1806 ep1_ch1()->selected_connection()->port())); 1826 ep1_ch1()->selected_connection()->port()));
1807 EXPECT_NE(pooled_ports_2.end(), 1827 EXPECT_NE(pooled_ports_2.end(),
1808 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), 1828 std::find(pooled_ports_2.begin(), pooled_ports_2.end(),
1809 ep2_ch1()->selected_connection()->port())); 1829 ep2_ch1()->selected_connection()->port()));
(...skipping 24 matching lines...) Expand all
1834 EXPECT_TRUE_SIMULATED_WAIT(pooled_session_1->CandidatesAllocationDone() && 1854 EXPECT_TRUE_SIMULATED_WAIT(pooled_session_1->CandidatesAllocationDone() &&
1835 pooled_session_2->CandidatesAllocationDone(), 1855 pooled_session_2->CandidatesAllocationDone(),
1836 kDefaultTimeout, clock); 1856 kDefaultTimeout, clock);
1837 // Now let the endpoints connect and try exchanging some data. 1857 // Now let the endpoints connect and try exchanging some data.
1838 CreateChannels(); 1858 CreateChannels();
1839 EXPECT_TRUE_SIMULATED_WAIT( 1859 EXPECT_TRUE_SIMULATED_WAIT(
1840 ep1_ch1() != NULL && ep2_ch1() != NULL && ep1_ch1()->receiving() && 1860 ep1_ch1() != NULL && ep2_ch1() != NULL && ep1_ch1()->receiving() &&
1841 ep1_ch1()->writable() && ep2_ch1()->receiving() && 1861 ep1_ch1()->writable() && ep2_ch1()->receiving() &&
1842 ep2_ch1()->writable(), 1862 ep2_ch1()->writable(),
1843 kMediumTimeout, clock); 1863 kMediumTimeout, clock);
1844 TestSendRecv(); 1864 TestSendRecv(clock);
1845 // Make sure the P2PTransportChannels are actually using ports from the 1865 // Make sure the P2PTransportChannels are actually using ports from the
1846 // pooled sessions. 1866 // pooled sessions.
1847 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); 1867 auto pooled_ports_1 = pooled_session_1->ReadyPorts();
1848 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); 1868 auto pooled_ports_2 = pooled_session_2->ReadyPorts();
1849 EXPECT_NE(pooled_ports_1.end(), 1869 EXPECT_NE(pooled_ports_1.end(),
1850 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), 1870 std::find(pooled_ports_1.begin(), pooled_ports_1.end(),
1851 ep1_ch1()->selected_connection()->port())); 1871 ep1_ch1()->selected_connection()->port()));
1852 EXPECT_NE(pooled_ports_2.end(), 1872 EXPECT_NE(pooled_ports_2.end(),
1853 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), 1873 std::find(pooled_ports_2.begin(), pooled_ports_2.end(),
1854 ep2_ch1()->selected_connection()->port())); 1874 ep2_ch1()->selected_connection()->port()));
(...skipping 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after
3260 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 3280 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
3261 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3281 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3262 ASSERT_TRUE(conn2 != nullptr); 3282 ASSERT_TRUE(conn2 != nullptr);
3263 conn2->ReceivedPing(); 3283 conn2->ReceivedPing();
3264 conn2->ReceivedPingResponse(LOW_RTT, "id"); 3284 conn2->ReceivedPingResponse(LOW_RTT, "id");
3265 3285
3266 // Wait for conn1 to be pruned. 3286 // Wait for conn1 to be pruned.
3267 EXPECT_TRUE_WAIT(conn1->pruned(), kMediumTimeout); 3287 EXPECT_TRUE_WAIT(conn1->pruned(), kMediumTimeout);
3268 // Destroy the connection to test SignalUnknownAddress. 3288 // Destroy the connection to test SignalUnknownAddress.
3269 conn1->Destroy(); 3289 conn1->Destroy();
3270 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000); 3290 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr,
3291 kMediumTimeout);
3271 3292
3272 // Create a minimal STUN message with prflx priority. 3293 // Create a minimal STUN message with prflx priority.
3273 IceMessage request; 3294 IceMessage request;
3274 request.SetType(STUN_BINDING_REQUEST); 3295 request.SetType(STUN_BINDING_REQUEST);
3275 request.AddAttribute( 3296 request.AddAttribute(
3276 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3297 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
3277 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3298 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3278 request.AddAttribute( 3299 request.AddAttribute(
3279 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3300 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
3280 EXPECT_NE(prflx_priority, remote_priority); 3301 EXPECT_NE(prflx_priority, remote_priority);
3281 3302
3282 Port* port = GetPort(&ch); 3303 Port* port = GetPort(&ch);
3283 // conn1 should be resurrected with original priority. 3304 // conn1 should be resurrected with original priority.
3284 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 3305 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
3285 &request, kIceUfrag[1], false); 3306 &request, kIceUfrag[1], false);
3286 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3307 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3287 ASSERT_TRUE(conn1 != nullptr); 3308 ASSERT_TRUE(conn1 != nullptr);
3288 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority); 3309 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority);
3289 3310
3290 // conn3, a real prflx connection, should have prflx priority. 3311 // conn3, a real prflx connection, should have prflx priority.
3291 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), PROTO_UDP, 3312 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), PROTO_UDP,
3292 &request, kIceUfrag[1], false); 3313 &request, kIceUfrag[1], false);
3293 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1); 3314 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1);
3294 ASSERT_TRUE(conn3 != nullptr); 3315 ASSERT_TRUE(conn3 != nullptr);
3295 EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority); 3316 EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority);
3296 } 3317 }
3297 3318
3298 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { 3319 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) {
3320 rtc::ScopedFakeClock clock;
3299 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3321 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3300 P2PTransportChannel ch("receiving state change", 1, &pa); 3322 P2PTransportChannel ch("receiving state change", 1, &pa);
3301 PrepareChannel(&ch); 3323 PrepareChannel(&ch);
3302 // Default receiving timeout and checking receiving interval should not be too 3324 // Default receiving timeout and checking receiving interval should not be too
3303 // small. 3325 // small.
3304 EXPECT_LE(1000, ch.receiving_timeout()); 3326 EXPECT_LE(1000, ch.receiving_timeout());
3305 EXPECT_LE(200, ch.check_receiving_interval()); 3327 EXPECT_LE(200, ch.check_receiving_interval());
3306 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); 3328 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE));
3307 EXPECT_EQ(500, ch.receiving_timeout()); 3329 EXPECT_EQ(500, ch.receiving_timeout());
3308 EXPECT_EQ(50, ch.check_receiving_interval()); 3330 EXPECT_EQ(50, ch.check_receiving_interval());
3309 ch.MaybeStartGathering(); 3331 ch.MaybeStartGathering();
3310 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3332 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3311 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3333 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
3312 ASSERT_TRUE(conn1 != nullptr); 3334 ASSERT_TRUE(conn1 != nullptr);
3313 3335
3336 clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
3314 conn1->ReceivedPing(); 3337 conn1->ReceivedPing();
3315 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); 3338 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
3316 EXPECT_TRUE_WAIT(ch.receiving(), 1000); 3339 EXPECT_TRUE_SIMULATED_WAIT(ch.receiving(), kShortTimeout, clock);
3317 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); 3340 EXPECT_TRUE_SIMULATED_WAIT(!ch.receiving(), kShortTimeout, clock);
3318 } 3341 }
3319 3342
3320 // The controlled side will select a connection as the "selected connection" 3343 // The controlled side will select a connection as the "selected connection"
3321 // based on priority until the controlling side nominates a connection, at which 3344 // based on priority until the controlling side nominates a connection, at which
3322 // point the controlled side will select that connection as the 3345 // point the controlled side will select that connection as the
3323 // "selected connection". Plus, SignalSelectedCandidatePair will be fired if the 3346 // "selected connection". Plus, SignalSelectedCandidatePair will be fired if the
3324 // selected connection changes and SignalReadyToSend will be fired if the new 3347 // selected connection changes and SignalReadyToSend will be fired if the new
3325 // selected connection is writable. 3348 // selected connection is writable.
3326 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { 3349 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
3327 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3350 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
3529 // selected connection was nominated by the controlling side. 3552 // selected connection was nominated by the controlling side.
3530 conn2->ReceivedPing(); 3553 conn2->ReceivedPing();
3531 conn2->ReceivedPingResponse(LOW_RTT, "id"); 3554 conn2->ReceivedPingResponse(LOW_RTT, "id");
3532 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); 3555 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
3533 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); 3556 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout);
3534 } 3557 }
3535 3558
3536 TEST_F(P2PTransportChannelPingTest, 3559 TEST_F(P2PTransportChannelPingTest,
3537 TestControlledAgentDataReceivingTakesHigherPrecedenceThanPriority) { 3560 TestControlledAgentDataReceivingTakesHigherPrecedenceThanPriority) {
3538 rtc::ScopedFakeClock clock; 3561 rtc::ScopedFakeClock clock;
3539 3562 clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
3540 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3563 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3541 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); 3564 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
3542 PrepareChannel(&ch); 3565 PrepareChannel(&ch);
3543 ch.SetIceRole(ICEROLE_CONTROLLED); 3566 ch.SetIceRole(ICEROLE_CONTROLLED);
3544 ch.MaybeStartGathering(); 3567 ch.MaybeStartGathering();
3545 // The connections have decreasing priority. 3568 // The connections have decreasing priority.
3546 Connection* conn1 = 3569 Connection* conn1 =
3547 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true); 3570 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true);
3548 ASSERT_TRUE(conn1 != nullptr); 3571 ASSERT_TRUE(conn1 != nullptr);
3549 Connection* conn2 = 3572 Connection* conn2 =
(...skipping 27 matching lines...) Expand all
3577 EXPECT_EQ(conn2, last_selected_candidate_pair()); 3600 EXPECT_EQ(conn2, last_selected_candidate_pair());
3578 3601
3579 // Make sure sorting won't reselect candidate pair. 3602 // Make sure sorting won't reselect candidate pair.
3580 SIMULATED_WAIT(false, 10, clock); 3603 SIMULATED_WAIT(false, 10, clock);
3581 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); 3604 EXPECT_EQ(0, reset_selected_candidate_pair_switches());
3582 } 3605 }
3583 3606
3584 TEST_F(P2PTransportChannelPingTest, 3607 TEST_F(P2PTransportChannelPingTest,
3585 TestControlledAgentNominationTakesHigherPrecedenceThanDataReceiving) { 3608 TestControlledAgentNominationTakesHigherPrecedenceThanDataReceiving) {
3586 rtc::ScopedFakeClock clock; 3609 rtc::ScopedFakeClock clock;
3610 clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
3587 3611
3588 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3612 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3589 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); 3613 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa);
3590 PrepareChannel(&ch); 3614 PrepareChannel(&ch);
3591 ch.SetIceRole(ICEROLE_CONTROLLED); 3615 ch.SetIceRole(ICEROLE_CONTROLLED);
3592 ch.MaybeStartGathering(); 3616 ch.MaybeStartGathering();
3593 // The connections have decreasing priority. 3617 // The connections have decreasing priority.
3594 Connection* conn1 = 3618 Connection* conn1 =
3595 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true); 3619 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true);
3596 ASSERT_TRUE(conn1 != nullptr); 3620 ASSERT_TRUE(conn1 != nullptr);
(...skipping 19 matching lines...) Expand all
3616 EXPECT_EQ(conn1, last_selected_candidate_pair()); 3640 EXPECT_EQ(conn1, last_selected_candidate_pair());
3617 3641
3618 // Make sure sorting won't reselect candidate pair. 3642 // Make sure sorting won't reselect candidate pair.
3619 SIMULATED_WAIT(false, 10, clock); 3643 SIMULATED_WAIT(false, 10, clock);
3620 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); 3644 EXPECT_EQ(0, reset_selected_candidate_pair_switches());
3621 } 3645 }
3622 3646
3623 TEST_F(P2PTransportChannelPingTest, 3647 TEST_F(P2PTransportChannelPingTest,
3624 TestControlledAgentSelectsConnectionWithHigherNomination) { 3648 TestControlledAgentSelectsConnectionWithHigherNomination) {
3625 rtc::ScopedFakeClock clock; 3649 rtc::ScopedFakeClock clock;
3650 clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
3626 3651
3627 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3652 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3628 P2PTransportChannel ch("test", 1, &pa); 3653 P2PTransportChannel ch("test", 1, &pa);
3629 PrepareChannel(&ch); 3654 PrepareChannel(&ch);
3630 ch.SetIceRole(ICEROLE_CONTROLLED); 3655 ch.SetIceRole(ICEROLE_CONTROLLED);
3631 ch.MaybeStartGathering(); 3656 ch.MaybeStartGathering();
3632 // The connections have decreasing priority. 3657 // The connections have decreasing priority.
3633 Connection* conn1 = 3658 Connection* conn1 =
3634 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true); 3659 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true);
3635 ASSERT_TRUE(conn1 != nullptr); 3660 ASSERT_TRUE(conn1 != nullptr);
(...skipping 22 matching lines...) Expand all
3658 EXPECT_EQ(conn2, last_selected_candidate_pair()); 3683 EXPECT_EQ(conn2, last_selected_candidate_pair());
3659 3684
3660 // Make sure sorting won't reselect candidate pair. 3685 // Make sure sorting won't reselect candidate pair.
3661 SIMULATED_WAIT(false, 100, clock); 3686 SIMULATED_WAIT(false, 100, clock);
3662 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); 3687 EXPECT_EQ(0, reset_selected_candidate_pair_switches());
3663 } 3688 }
3664 3689
3665 TEST_F(P2PTransportChannelPingTest, 3690 TEST_F(P2PTransportChannelPingTest,
3666 TestControlledAgentIgnoresSmallerNomination) { 3691 TestControlledAgentIgnoresSmallerNomination) {
3667 rtc::ScopedFakeClock clock; 3692 rtc::ScopedFakeClock clock;
3693 clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
3694
3668 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3695 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3669 P2PTransportChannel ch("test", 1, &pa); 3696 P2PTransportChannel ch("test", 1, &pa);
3670 PrepareChannel(&ch); 3697 PrepareChannel(&ch);
3671 ch.SetIceRole(ICEROLE_CONTROLLED); 3698 ch.SetIceRole(ICEROLE_CONTROLLED);
3672 ch.MaybeStartGathering(); 3699 ch.MaybeStartGathering();
3673 Connection* conn = 3700 Connection* conn =
3674 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); 3701 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false);
3675 ReceivePingOnConnection(conn, kIceUfrag[1], 1, 2U); 3702 ReceivePingOnConnection(conn, kIceUfrag[1], 1, 2U);
3676 EXPECT_EQ(2U, conn->remote_nomination()); 3703 EXPECT_EQ(2U, conn->remote_nomination());
3677 // Smaller nomination is ignored. 3704 // Smaller nomination is ignored.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
3754 // connection. 3781 // connection.
3755 EXPECT_EQ(0, conn2->last_ping_received()); 3782 EXPECT_EQ(0, conn2->last_ping_received());
3756 ReceivePingOnConnection(conn2, kIceUfrag[2], 1 /* priority */); 3783 ReceivePingOnConnection(conn2, kIceUfrag[2], 1 /* priority */);
3757 EXPECT_TRUE(conn2->last_ping_received() > 0); 3784 EXPECT_TRUE(conn2->last_ping_received() > 0);
3758 } 3785 }
3759 3786
3760 // When the current selected connection is strong, lower-priority connections 3787 // When the current selected connection is strong, lower-priority connections
3761 // will be pruned. Otherwise, lower-priority connections are kept. 3788 // will be pruned. Otherwise, lower-priority connections are kept.
3762 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { 3789 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
3763 rtc::ScopedFakeClock clock; 3790 rtc::ScopedFakeClock clock;
3791 clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
3764 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3792 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3765 P2PTransportChannel ch("test channel", 1, &pa); 3793 P2PTransportChannel ch("test channel", 1, &pa);
3766 PrepareChannel(&ch); 3794 PrepareChannel(&ch);
3767 ch.SetIceRole(ICEROLE_CONTROLLED); 3795 ch.SetIceRole(ICEROLE_CONTROLLED);
3768 ch.MaybeStartGathering(); 3796 ch.MaybeStartGathering();
3769 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3797 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3770 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3798 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3771 ASSERT_TRUE(conn1 != nullptr); 3799 ASSERT_TRUE(conn1 != nullptr);
3772 EXPECT_EQ(nullptr, ch.selected_connection()); 3800 EXPECT_EQ(nullptr, ch.selected_connection());
3773 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving 3801 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
(...skipping 10 matching lines...) Expand all
3784 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); 3812 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE));
3785 // Wait until conn2 becomes not receiving. 3813 // Wait until conn2 becomes not receiving.
3786 EXPECT_TRUE_SIMULATED_WAIT(!conn2->receiving(), kMediumTimeout, clock); 3814 EXPECT_TRUE_SIMULATED_WAIT(!conn2->receiving(), kMediumTimeout, clock);
3787 3815
3788 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); 3816 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
3789 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3, &clock); 3817 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3, &clock);
3790 ASSERT_TRUE(conn3 != nullptr); 3818 ASSERT_TRUE(conn3 != nullptr);
3791 // The selected connection should still be conn2. Even through conn3 has lower 3819 // The selected connection should still be conn2. Even through conn3 has lower
3792 // priority and is not receiving/writable, it is not pruned because the 3820 // priority and is not receiving/writable, it is not pruned because the
3793 // selected connection is not receiving. 3821 // selected connection is not receiving.
3794 SIMULATED_WAIT(conn3->pruned(), 1000, clock); 3822 SIMULATED_WAIT(conn3->pruned(), kShortTimeout, clock);
3795 EXPECT_FALSE(conn3->pruned()); 3823 EXPECT_FALSE(conn3->pruned());
3796 } 3824 }
3797 3825
3798 TEST_F(P2PTransportChannelPingTest, TestDontPruneHighPriorityConnections) { 3826 TEST_F(P2PTransportChannelPingTest, TestDontPruneHighPriorityConnections) {
3799 rtc::ScopedFakeClock clock; 3827 rtc::ScopedFakeClock clock;
3800 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3828 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3801 P2PTransportChannel ch("test channel", 1, &pa); 3829 P2PTransportChannel ch("test channel", 1, &pa);
3802 PrepareChannel(&ch); 3830 PrepareChannel(&ch);
3803 ch.SetIceRole(ICEROLE_CONTROLLED); 3831 ch.SetIceRole(ICEROLE_CONTROLLED);
3804 ch.MaybeStartGathering(); 3832 ch.MaybeStartGathering();
3805 Connection* conn1 = 3833 Connection* conn1 =
3806 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 100, true); 3834 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 100, true);
3807 ASSERT_TRUE(conn1 != nullptr); 3835 ASSERT_TRUE(conn1 != nullptr);
3808 Connection* conn2 = 3836 Connection* conn2 =
3809 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 200, false); 3837 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 200, false);
3810 ASSERT_TRUE(conn2 != nullptr); 3838 ASSERT_TRUE(conn2 != nullptr);
3811 // Even if conn1 is writable, nominated, receiving data, it should not prune 3839 // Even if conn1 is writable, nominated, receiving data, it should not prune
3812 // conn2. 3840 // conn2.
3813 NominateConnection(conn1); 3841 NominateConnection(conn1);
3814 SIMULATED_WAIT(false, 1, clock); 3842 SIMULATED_WAIT(false, 1, clock);
3815 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); 3843 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
3816 SIMULATED_WAIT(conn2->pruned(), 100, clock); 3844 SIMULATED_WAIT(conn2->pruned(), 100, clock);
3817 EXPECT_FALSE(conn2->pruned()); 3845 EXPECT_FALSE(conn2->pruned());
3818 } 3846 }
3819 3847
3820 // Test that GetState returns the state correctly. 3848 // Test that GetState returns the state correctly.
3821 TEST_F(P2PTransportChannelPingTest, TestGetState) { 3849 TEST_F(P2PTransportChannelPingTest, TestGetState) {
3850 rtc::ScopedFakeClock clock;
3851 clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
3822 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3852 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3823 P2PTransportChannel ch("test channel", 1, &pa); 3853 P2PTransportChannel ch("test channel", 1, &pa);
3824 PrepareChannel(&ch); 3854 PrepareChannel(&ch);
3825 ch.MaybeStartGathering(); 3855 ch.MaybeStartGathering();
3826 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState()); 3856 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState());
3827 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3857 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3828 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3858 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3829 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3859 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
3830 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3860 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock);
3831 ASSERT_TRUE(conn1 != nullptr); 3861 ASSERT_TRUE(conn1 != nullptr);
3832 ASSERT_TRUE(conn2 != nullptr); 3862 ASSERT_TRUE(conn2 != nullptr);
3833 // Now there are two connections, so the transport channel is connecting. 3863 // Now there are two connections, so the transport channel is connecting.
3834 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); 3864 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
3835 // |conn1| becomes writable and receiving; it then should prune |conn2|. 3865 // |conn1| becomes writable and receiving; it then should prune |conn2|.
3836 conn1->ReceivedPingResponse(LOW_RTT, "id"); 3866 conn1->ReceivedPingResponse(LOW_RTT, "id");
3837 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); 3867 EXPECT_TRUE_SIMULATED_WAIT(conn2->pruned(), kShortTimeout, clock);
3838 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3868 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3839 conn1->Prune(); // All connections are pruned. 3869 conn1->Prune(); // All connections are pruned.
3840 // Need to wait until the channel state is updated. 3870 // Need to wait until the channel state is updated.
3841 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); 3871 EXPECT_EQ_SIMULATED_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(),
3872 kShortTimeout, clock);
3842 } 3873 }
3843 3874
3844 // Test that when a low-priority connection is pruned, it is not deleted 3875 // Test that when a low-priority connection is pruned, it is not deleted
3845 // right away, and it can become active and be pruned again. 3876 // right away, and it can become active and be pruned again.
3846 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { 3877 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
3847 rtc::ScopedFakeClock clock; 3878 rtc::ScopedFakeClock clock;
3879 clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
3880
3848 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3881 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3849 P2PTransportChannel ch("test channel", 1, &pa); 3882 P2PTransportChannel ch("test channel", 1, &pa);
3850 PrepareChannel(&ch); 3883 PrepareChannel(&ch);
3851 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); 3884 IceConfig config = CreateIceConfig(1000, GATHER_ONCE);
3852 config.receiving_switching_delay = rtc::Optional<int>(800); 3885 config.receiving_switching_delay = rtc::Optional<int>(800);
3853 ch.SetIceConfig(config); 3886 ch.SetIceConfig(config);
3854 ch.MaybeStartGathering(); 3887 ch.MaybeStartGathering();
3855 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3888 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3856 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock); 3889 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
3857 ASSERT_TRUE(conn1 != nullptr); 3890 ASSERT_TRUE(conn1 != nullptr);
(...skipping 29 matching lines...) Expand all
3887 conn1->ReceivedPingResponse(LOW_RTT, "id"); 3920 conn1->ReceivedPingResponse(LOW_RTT, "id");
3888 EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout, 3921 EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout,
3889 clock); 3922 clock);
3890 EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock); 3923 EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock);
3891 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3924 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3892 } 3925 }
3893 3926
3894 // Test that if all connections in a channel has timed out on writing, they 3927 // Test that if all connections in a channel has timed out on writing, they
3895 // will all be deleted. We use Prune to simulate write_time_out. 3928 // will all be deleted. We use Prune to simulate write_time_out.
3896 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { 3929 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
3930 rtc::ScopedFakeClock clock;
3897 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3931 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3898 P2PTransportChannel ch("test channel", 1, &pa); 3932 P2PTransportChannel ch("test channel", 1, &pa);
3899 PrepareChannel(&ch); 3933 PrepareChannel(&ch);
3900 ch.MaybeStartGathering(); 3934 ch.MaybeStartGathering();
3901 // Have one connection only but later becomes write-time-out. 3935 // Have one connection only but later becomes write-time-out.
3902 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3936 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3903 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3937 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1, &clock);
3904 ASSERT_TRUE(conn1 != nullptr); 3938 ASSERT_TRUE(conn1 != nullptr);
3905 conn1->ReceivedPing(); // Becomes receiving 3939 conn1->ReceivedPing(); // Becomes receiving
3906 conn1->Prune(); 3940 conn1->Prune();
3907 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); 3941 EXPECT_TRUE_SIMULATED_WAIT(ch.connections().empty(), kShortTimeout, clock);
3908 3942
3909 // Have two connections but both become write-time-out later. 3943 // Have two connections but both become write-time-out later.
3910 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 3944 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1));
3911 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3945 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2, &clock);
3912 ASSERT_TRUE(conn2 != nullptr); 3946 ASSERT_TRUE(conn2 != nullptr);
3913 conn2->ReceivedPing(); // Becomes receiving 3947 conn2->ReceivedPing(); // Becomes receiving
3914 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 2)); 3948 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 2));
3915 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3949 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3, &clock);
3916 ASSERT_TRUE(conn3 != nullptr); 3950 ASSERT_TRUE(conn3 != nullptr);
3917 conn3->ReceivedPing(); // Becomes receiving 3951 conn3->ReceivedPing(); // Becomes receiving
3918 // Now prune both conn2 and conn3; they will be deleted soon. 3952 // Now prune both conn2 and conn3; they will be deleted soon.
3919 conn2->Prune(); 3953 conn2->Prune();
3920 conn3->Prune(); 3954 conn3->Prune();
3921 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); 3955 EXPECT_TRUE_SIMULATED_WAIT(ch.connections().empty(), kShortTimeout, clock);
3922 } 3956 }
3923 3957
3924 // Tests that after a port allocator session is started, it will be stopped 3958 // Tests that after a port allocator session is started, it will be stopped
3925 // when a new connection becomes writable and receiving. Also tests that if a 3959 // when a new connection becomes writable and receiving. Also tests that if a
3926 // connection belonging to an old session becomes writable, it won't stop 3960 // connection belonging to an old session becomes writable, it won't stop
3927 // the current port allocator session. 3961 // the current port allocator session.
3928 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { 3962 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
3929 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3963 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3930 P2PTransportChannel ch("test channel", 1, &pa); 3964 P2PTransportChannel ch("test channel", 1, &pa);
3931 PrepareChannel(&ch); 3965 PrepareChannel(&ch);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
4235 4269
4236 // TCP Relay/Relay is the next. 4270 // TCP Relay/Relay is the next.
4237 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 4271 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
4238 TCP_PROTOCOL_NAME); 4272 TCP_PROTOCOL_NAME);
4239 4273
4240 // Finally, Local/Relay will be pinged. 4274 // Finally, Local/Relay will be pinged.
4241 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 4275 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
4242 } 4276 }
4243 4277
4244 } // namespace cricket { 4278 } // namespace cricket {
OLDNEW
« no previous file with comments | « no previous file | webrtc/p2p/base/port.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698