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

Unified Diff: webrtc/p2p/base/p2ptransportchannel_unittest.cc

Issue 1311433009: A few updates on connection states (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Merge and address comments 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/p2p/base/p2ptransportchannel_unittest.cc
diff --git a/webrtc/p2p/base/p2ptransportchannel_unittest.cc b/webrtc/p2p/base/p2ptransportchannel_unittest.cc
index d0277f481461015f67320fc6f1eadc4166a59813..aaf34734d71b08e6cd53b2251ab94095fb5da004 100644
--- a/webrtc/p2p/base/p2ptransportchannel_unittest.cc
+++ b/webrtc/p2p/base/p2ptransportchannel_unittest.cc
@@ -1123,6 +1123,32 @@ TEST_F(P2PTransportChannelTest, GetStats) {
DestroyChannels();
}
+
+// Test that p2ptransportchannel returns the state correctly.
+TEST_F(P2PTransportChannelTest, TestGetState) {
+ ConfigureEndpoints(OPEN, OPEN,
+ kDefaultPortAllocatorFlags,
+ kDefaultPortAllocatorFlags);
+ CreateChannels(1);
+ EXPECT_TRUE_WAIT(ep1_ch1()->writable() && ep2_ch1()->writable(), 1000);
+ EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED,
+ ep1_ch1()->GetState(), 1000);
+ const std::vector<cricket::Connection*>& connections =
+ ep1_ch1()->connections();
+
+ ASSERT_TRUE(connections.size() >= 2);
+ connections[0]->Unprune();
+ connections[1]->Unprune();
+ EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING,
+ ep1_ch1()->GetState());
+
+ for (cricket::Connection* conn : connections) {
+ conn->Prune();
+ }
+ EXPECT_EQ(cricket::TransportChannelState::STATE_FAILED,
+ ep1_ch1()->GetState());
+}
+
// Test that we properly create a connection on a STUN ping from unknown address
// when the signaling is slow.
TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) {
@@ -1426,8 +1452,10 @@ TEST_F(P2PTransportChannelTest, TestForceTurn) {
CreateChannels(1);
- EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
- ep2_ch1()->receiving() && ep2_ch1()->writable(),
+ EXPECT_TRUE_WAIT(ep1_ch1()->receiving() &&
+ ep1_ch1()->writable() &&
+ ep2_ch1()->receiving() &&
+ ep2_ch1()->writable(),
2000);
EXPECT_TRUE(ep1_ch1()->best_connection() &&
@@ -1519,16 +1547,21 @@ TEST_F(P2PTransportChannelMultihomedTest, TestFailover) {
fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
kPublicAddrs[1]);
- // We should detect loss of connectivity within 5 seconds or so.
- EXPECT_TRUE_WAIT(!ep1_ch1()->writable(), 7000);
+ // We should detect loss of connectivity within 2.5 seconds or so.
+ // The best connection will be switched. So keep a reference to the
+ // current best connection.
+ const cricket::Connection* best_connection = ep1_ch1()->best_connection();
+ EXPECT_TRUE_WAIT(!best_connection->receiving(), 3000);
+ // The channel is still receiving because the backup connection is receiving.
+ EXPECT_TRUE(ep1_ch1()->receiving());
// We should switch over to use the alternate addr immediately
- // when we lose writability.
+ // when we lose receiving.
EXPECT_TRUE_WAIT(
ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]),
- 3000);
+ 1000);
DestroyChannels();
}
@@ -1709,11 +1742,18 @@ TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) {
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPing();
+ // Need Ping to set the last_ping_sent so that the write state will not
+ // become stale.
+ conn2->Ping(rtc::Time());
conn2->ReceivedPingResponse();
- // Wait for conn1 to be destroyed.
+ // Wait for conn1 being pruned.
+ ASSERT_EQ(conn1, GetConnectionTo(&ch, "1.1.1.1", 1));
+ EXPECT_TRUE_WAIT(
+ conn1 == GetConnectionTo(&ch, "1.1.1.1", 1) && conn1->pruned(), 3000);
+ // conn1 won't be deleted right away. Destroy it.
+ conn1->Destroy();
EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 3000);
- cricket::Port* port = GetPort(&ch);
// Create a minimal STUN message with prflx priority.
cricket::IceMessage request;
@@ -1725,6 +1765,7 @@ TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) {
cricket::STUN_ATTR_PRIORITY, prflx_priority));
EXPECT_NE(prflx_priority, remote_priority);
+ cricket::Port* port = GetPort(&ch);
// conn1 should be resurrected with original priority.
port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1),
cricket::PROTO_UDP, &request, kIceUfrag[1], false);

Powered by Google App Engine
This is Rietveld 408576698