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

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

Issue 1371623003: Delete a connection only if it has timed out on writing and not receiving for 10 seconds. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Rename a test Created 5 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 | « 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 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 TEST_F(P2PTransportChannelTest, GetStats) { 1105 TEST_F(P2PTransportChannelTest, GetStats) {
1106 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1106 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1107 kDefaultPortAllocatorFlags); 1107 kDefaultPortAllocatorFlags);
1108 CreateChannels(1); 1108 CreateChannels(1);
1109 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1109 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1110 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1110 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1111 1000, 1000); 1111 1000, 1000);
1112 TestSendRecv(1); 1112 TestSendRecv(1);
1113 cricket::ConnectionInfos infos; 1113 cricket::ConnectionInfos infos;
1114 ASSERT_TRUE(ep1_ch1()->GetStats(&infos)); 1114 ASSERT_TRUE(ep1_ch1()->GetStats(&infos));
1115 ASSERT_EQ(1U, infos.size()); 1115 ASSERT_TRUE(infos.size() >= 1);
1116 EXPECT_TRUE(infos[0].new_connection); 1116 cricket::ConnectionInfo* best_conn_info = nullptr;
1117 EXPECT_TRUE(infos[0].best_connection); 1117 for (cricket::ConnectionInfo& info : infos) {
1118 EXPECT_TRUE(infos[0].receiving); 1118 if (info.best_connection) {
1119 EXPECT_TRUE(infos[0].writable); 1119 best_conn_info = &info;
1120 EXPECT_FALSE(infos[0].timeout); 1120 break;
1121 EXPECT_EQ(10U, infos[0].sent_total_packets); 1121 }
1122 EXPECT_EQ(0U, infos[0].sent_discarded_packets); 1122 }
1123 EXPECT_EQ(10 * 36U, infos[0].sent_total_bytes); 1123 ASSERT_TRUE(best_conn_info != nullptr);
1124 EXPECT_EQ(10 * 36U, infos[0].recv_total_bytes); 1124 EXPECT_TRUE(best_conn_info->new_connection);
1125 EXPECT_GT(infos[0].rtt, 0U); 1125 EXPECT_TRUE(best_conn_info->receiving);
1126 EXPECT_TRUE(best_conn_info->writable);
1127 EXPECT_FALSE(best_conn_info->timeout);
1128 EXPECT_EQ(10U, best_conn_info->sent_total_packets);
1129 EXPECT_EQ(0U, best_conn_info->sent_discarded_packets);
1130 EXPECT_EQ(10 * 36U, best_conn_info->sent_total_bytes);
1131 EXPECT_EQ(10 * 36U, best_conn_info->recv_total_bytes);
1132 EXPECT_GT(best_conn_info->rtt, 0U);
1126 DestroyChannels(); 1133 DestroyChannels();
1127 } 1134 }
1128 1135
1129 // Test that we properly create a connection on a STUN ping from unknown address 1136 // Test that we properly create a connection on a STUN ping from unknown address
1130 // when the signaling is slow. 1137 // when the signaling is slow.
1131 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) { 1138 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) {
1132 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1139 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1133 kDefaultPortAllocatorFlags); 1140 kDefaultPortAllocatorFlags);
1134 // Emulate no remote credentials coming in. 1141 // Emulate no remote credentials coming in.
1135 set_clear_remote_candidates_ufrag_pwd(false); 1142 set_clear_remote_candidates_ufrag_pwd(false);
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 ep2_ch1()->best_connection()->receiving(), 1000); 1620 ep2_ch1()->best_connection()->receiving(), 1000);
1614 EXPECT_TRUE( 1621 EXPECT_TRUE(
1615 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); 1622 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]));
1616 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 1623 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
1617 EXPECT_TRUE( 1624 EXPECT_TRUE(
1618 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); 1625 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0]));
1619 1626
1620 DestroyChannels(); 1627 DestroyChannels();
1621 } 1628 }
1622 1629
1630 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) {
1631 AddAddress(0, kAlternateAddrs[0]);
1632 AddAddress(0, kPublicAddrs[0]);
1633 AddAddress(1, kPublicAddrs[1]);
1634 // Create channels and let them go writable, as usual.
1635 CreateChannels(1);
1636
1637 // Both transport channels will reach STATE_COMPLETED quickly.
1638 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED,
1639 ep1_ch1()->GetState(), 1000);
1640 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED,
1641 ep2_ch1()->GetState(), 1000);
1642 }
1643
1623 /* 1644 /*
1624 1645
1625 TODO(pthatcher): Once have a way to handle network interfaces changes 1646 TODO(pthatcher): Once have a way to handle network interfaces changes
1626 without signalling an ICE restart, put a test like this back. In the 1647 without signalling an ICE restart, put a test like this back. In the
1627 mean time, this test only worked for GICE. With ICE, it's currently 1648 mean time, this test only worked for GICE. With ICE, it's currently
1628 not possible without an ICE restart. 1649 not possible without an ICE restart.
1629 1650
1630 // Test that we can switch links in a coordinated fashion. 1651 // Test that we can switch links in a coordinated fashion.
1631 TEST_F(P2PTransportChannelMultihomedTest, TestDrain) { 1652 TEST_F(P2PTransportChannelMultihomedTest, TestDrain) {
1632 AddAddress(0, kPublicAddrs[0]); 1653 AddAddress(0, kPublicAddrs[0]);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1789 uint32 remote_priority = conn1->remote_candidate().priority(); 1810 uint32 remote_priority = conn1->remote_candidate().priority();
1790 1811
1791 // Create a higher priority candidate and make the connection 1812 // Create a higher priority candidate and make the connection
1792 // receiving/writable. This will prune conn1. 1813 // receiving/writable. This will prune conn1.
1793 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); 1814 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2));
1794 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 1815 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
1795 ASSERT_TRUE(conn2 != nullptr); 1816 ASSERT_TRUE(conn2 != nullptr);
1796 conn2->ReceivedPing(); 1817 conn2->ReceivedPing();
1797 conn2->ReceivedPingResponse(); 1818 conn2->ReceivedPingResponse();
1798 1819
1799 // Wait for conn1 to be destroyed. 1820 // Wait for conn1 to be pruned.
1800 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 3000); 1821 EXPECT_TRUE_WAIT(conn1->pruned(), 3000);
1801 cricket::Port* port = GetPort(&ch); 1822 // Destroy the connection to test SignalUnknownAddress.
1823 conn1->Destroy();
1824 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000);
1802 1825
1803 // Create a minimal STUN message with prflx priority. 1826 // Create a minimal STUN message with prflx priority.
1804 cricket::IceMessage request; 1827 cricket::IceMessage request;
1805 request.SetType(cricket::STUN_BINDING_REQUEST); 1828 request.SetType(cricket::STUN_BINDING_REQUEST);
1806 request.AddAttribute(new cricket::StunByteStringAttribute( 1829 request.AddAttribute(new cricket::StunByteStringAttribute(
1807 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); 1830 cricket::STUN_ATTR_USERNAME, kIceUfrag[1]));
1808 uint32 prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; 1831 uint32 prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24;
1809 request.AddAttribute(new cricket::StunUInt32Attribute( 1832 request.AddAttribute(new cricket::StunUInt32Attribute(
1810 cricket::STUN_ATTR_PRIORITY, prflx_priority)); 1833 cricket::STUN_ATTR_PRIORITY, prflx_priority));
1811 EXPECT_NE(prflx_priority, remote_priority); 1834 EXPECT_NE(prflx_priority, remote_priority);
1812 1835
1836 cricket::Port* port = GetPort(&ch);
1813 // conn1 should be resurrected with original priority. 1837 // conn1 should be resurrected with original priority.
1814 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), 1838 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1),
1815 cricket::PROTO_UDP, &request, kIceUfrag[1], false); 1839 cricket::PROTO_UDP, &request, kIceUfrag[1], false);
1816 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 1840 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
1817 ASSERT_TRUE(conn1 != nullptr); 1841 ASSERT_TRUE(conn1 != nullptr);
1818 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority); 1842 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority);
1819 1843
1820 // conn3, a real prflx connection, should have prflx priority. 1844 // conn3, a real prflx connection, should have prflx priority.
1821 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), 1845 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1),
1822 cricket::PROTO_UDP, &request, kIceUfrag[1], false); 1846 cricket::PROTO_UDP, &request, kIceUfrag[1], false);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
2061 2085
2062 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1)); 2086 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1));
2063 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 2087 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
2064 ASSERT_TRUE(conn3 != nullptr); 2088 ASSERT_TRUE(conn3 != nullptr);
2065 // The best connection should still be conn2. Even through conn3 has lower 2089 // The best connection should still be conn2. Even through conn3 has lower
2066 // priority and is not receiving/writable, it is not pruned because the best 2090 // priority and is not receiving/writable, it is not pruned because the best
2067 // connection is not receiving. 2091 // connection is not receiving.
2068 WAIT(conn3->pruned(), 1000); 2092 WAIT(conn3->pruned(), 1000);
2069 EXPECT_FALSE(conn3->pruned()); 2093 EXPECT_FALSE(conn3->pruned());
2070 } 2094 }
2095
2096 // Test that GetState returns the state correctly.
2097 TEST_F(P2PTransportChannelPingTest, TestGetState) {
2098 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2099 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa);
2100 PrepareChannel(&ch);
2101 ch.Connect();
2102 ch.MaybeStartGathering();
2103 EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState());
2104 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100));
2105 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1));
2106 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2107 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2108 ASSERT_TRUE(conn1 != nullptr);
2109 ASSERT_TRUE(conn2 != nullptr);
2110 // Now there are two connections, so the transport channel is connecting.
2111 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState());
2112 // |conn1| becomes writable and receiving; it then should prune |conn2|.
2113 conn1->ReceivedPingResponse();
2114 EXPECT_TRUE_WAIT(conn2->pruned(), 1000);
2115 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState());
2116 conn1->Prune(); // All connections are pruned.
2117 EXPECT_EQ(cricket::TransportChannelState::STATE_FAILED, ch.GetState());
2118 }
2119
2120 // Test that when a low-priority connection is pruned, it is not deleted
2121 // right away, and it can become active and be pruned again.
2122 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
2123 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2124 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa);
2125 PrepareChannel(&ch);
2126 ch.SetIceConfig(CreateIceConfig(1000, false));
2127 ch.Connect();
2128 ch.MaybeStartGathering();
2129 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100));
2130 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2131 ASSERT_TRUE(conn1 != nullptr);
2132 EXPECT_EQ(conn1, ch.best_connection());
2133 conn1->ReceivedPingResponse(); // Becomes writable and receiving
2134
2135 // Add a low-priority connection |conn2|, which will be pruned, but it will
2136 // not be deleted right away. Once the current best connection becomes not
2137 // receiving, |conn2| will start to ping and upon receiving the ping response,
2138 // it will become the best connection.
2139 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1));
2140 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2141 ASSERT_TRUE(conn2 != nullptr);
2142 EXPECT_TRUE_WAIT(!conn2->active(), 1000);
2143 // |conn2| should not send a ping yet.
2144 EXPECT_EQ(cricket::Connection::STATE_WAITING, conn2->state());
2145 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState());
2146 // Wait for |conn1| becoming not receiving.
2147 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000);
2148 // Make sure conn2 is not deleted.
2149 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2150 ASSERT_TRUE(conn2 != nullptr);
2151 EXPECT_EQ_WAIT(cricket::Connection::STATE_INPROGRESS, conn2->state(), 1000);
2152 conn2->ReceivedPingResponse();
2153 EXPECT_EQ_WAIT(conn2, ch.best_connection(), 1000);
2154 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState());
2155
2156 // When |conn1| comes back again, |conn2| will be pruned again.
2157 conn1->ReceivedPingResponse();
2158 EXPECT_EQ_WAIT(conn1, ch.best_connection(), 1000);
2159 EXPECT_TRUE_WAIT(!conn2->active(), 1000);
2160 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState());
2161 }
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