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

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

Issue 1364683002: Do not prune if the current best connection is weak. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Change the test name and merge Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/port.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 1814 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 ch.MaybeStartGathering(); 1825 ch.MaybeStartGathering();
1826 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); 1826 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1));
1827 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 1827 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
1828 ASSERT_TRUE(conn1 != nullptr); 1828 ASSERT_TRUE(conn1 != nullptr);
1829 EXPECT_EQ(conn1, ch.best_connection()); 1829 EXPECT_EQ(conn1, ch.best_connection());
1830 1830
1831 // When a higher priority candidate comes in, the new connection is chosen 1831 // When a higher priority candidate comes in, the new connection is chosen
1832 // as the best connection. 1832 // as the best connection.
1833 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 10)); 1833 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 10));
1834 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 1834 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
1835 ASSERT_TRUE(conn1 != nullptr); 1835 ASSERT_TRUE(conn2 != nullptr);
1836 EXPECT_EQ(conn2, ch.best_connection()); 1836 EXPECT_EQ(conn2, ch.best_connection());
1837 1837
1838 // If a stun request with use-candidate attribute arrives, the receiving 1838 // If a stun request with use-candidate attribute arrives, the receiving
1839 // connection will be set as the best connection, even though 1839 // connection will be set as the best connection, even though
1840 // its priority is lower. 1840 // its priority is lower.
1841 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1)); 1841 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1));
1842 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 1842 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
1843 ASSERT_TRUE(conn3 != nullptr); 1843 ASSERT_TRUE(conn3 != nullptr);
1844 // Because it has a lower priority, the best connection is still conn2. 1844 // Because it has a lower priority, the best connection is still conn2.
1845 EXPECT_EQ(conn2, ch.best_connection()); 1845 EXPECT_EQ(conn2, ch.best_connection());
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1985 conn3->ReceivedPingResponse(); // Become writable. 1985 conn3->ReceivedPingResponse(); // Become writable.
1986 EXPECT_EQ(conn3, ch.best_connection()); 1986 EXPECT_EQ(conn3, ch.best_connection());
1987 1987
1988 // Now another data packet will not switch the best connection because the 1988 // Now another data packet will not switch the best connection because the
1989 // best connection was nominated by the controlling side. 1989 // best connection was nominated by the controlling side.
1990 conn2->ReceivedPing(); 1990 conn2->ReceivedPing();
1991 conn2->ReceivedPingResponse(); 1991 conn2->ReceivedPingResponse();
1992 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); 1992 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
1993 EXPECT_EQ(conn3, ch.best_connection()); 1993 EXPECT_EQ(conn3, ch.best_connection());
1994 } 1994 }
1995
1996 // When the current best connection is strong, lower-priority connections will
1997 // be pruned. Otherwise, lower-priority connections are kept.
1998 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
1999 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2000 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa);
2001 PrepareChannel(&ch);
2002 ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
2003 ch.Connect();
2004 ch.MaybeStartGathering();
2005 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1));
2006 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2007 ASSERT_TRUE(conn1 != nullptr);
2008 EXPECT_EQ(conn1, ch.best_connection());
2009 conn1->ReceivedPingResponse(); // Becomes writable and receiving
2010
2011 // When a higher-priority, nominated candidate comes in, the connections with
2012 // lower-priority are pruned.
2013 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 10));
2014 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2015 ASSERT_TRUE(conn2 != nullptr);
2016 conn2->ReceivedPingResponse(); // Becomes writable and receiving
2017 conn2->set_nominated(true);
2018 conn2->SignalNominated(conn2);
2019 EXPECT_TRUE_WAIT(conn1->pruned(), 3000);
2020
2021 ch.SetReceivingTimeout(500);
2022 // Wait until conn2 becomes not receiving.
2023 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000);
2024
2025 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1));
2026 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
2027 ASSERT_TRUE(conn3 != nullptr);
2028 // The best connection should still be conn2. Even through conn3 has lower
2029 // priority and is not receiving/writable, it is not pruned because the best
2030 // connection is not receiving.
2031 WAIT(conn3->pruned(), 1000);
2032 EXPECT_FALSE(conn3->pruned());
2033 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/port.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698