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

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

Issue 1944003002: Increase the stun ping interval. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add unit test with fake clock. Created 4 years, 6 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
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/port.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/p2ptransportchannel_unittest.cc
diff --git a/webrtc/p2p/base/p2ptransportchannel_unittest.cc b/webrtc/p2p/base/p2ptransportchannel_unittest.cc
index 68543a5f39ed3af006541bfdcdd747c84a2d5df9..4a8b10f880cee53a18a98c107f42319c86d7f3a9 100644
--- a/webrtc/p2p/base/p2ptransportchannel_unittest.cc
+++ b/webrtc/p2p/base/p2ptransportchannel_unittest.cc
@@ -38,6 +38,7 @@ using cricket::kDefaultStepDelay;
using cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET;
using cricket::ServerAddresses;
using cricket::MIN_PINGS_AT_WEAK_PING_INTERVAL;
+using cricket::MIN_PINGS_TO_STABILIZE;
using rtc::SocketAddress;
static const int kDefaultTimeout = 1000;
@@ -2076,6 +2077,110 @@ TEST_F(P2PTransportChannelPingTest, TestAllConnectionsPingedSufficiently) {
kDefaultTimeout);
}
+TEST_F(P2PTransportChannelPingTest, TestInitialPingInterval) {
+ rtc::ScopedFakeClock clock;
+
+ cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ cricket::P2PTransportChannel ch("TestChannel", 1, &pa);
+ PrepareChannel(&ch);
+ ch.Connect();
+ ch.MaybeStartGathering();
+ ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
+ cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ASSERT_TRUE(conn != nullptr);
+
+ int64_t start = clock.TimeNanos() / 1000000;
+ // Wait for the connection to send MIN_PINGS_AT_WEAK_PING_INTERVAL pings.
+ SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL,
+ kDefaultTimeout, clock);
+ int64_t duration = clock.TimeNanos() / 1000000 - start;
+ EXPECT_TRUE(duration >= 100 && duration <= 200);
Zhi Huang 2016/06/10 20:39:02 The duration is not expected to be exactly the sam
Zhi Huang 2016/06/20 17:18:17 We can get the exact ping interval for initial pin
+}
+
+TEST_F(P2PTransportChannelPingTest, TestStabilizingPingInterval) {
+ rtc::ScopedFakeClock clock;
+ int stablilizing_timeout = 2000;
+
+ cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ cricket::P2PTransportChannel ch("TestChannel", 1, &pa);
+ PrepareChannel(&ch);
+ ch.Connect();
+ ch.MaybeStartGathering();
+ ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
+ cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+
+ ASSERT_TRUE(conn != nullptr);
+ // Wait for the connection to send MIN_PINGS_AT_WEAK_PING_INTERVAL pings.
+ SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL,
+ kDefaultTimeout, clock);
+ // The connection become strong but not stabilized. The ping interval is
+ // expected to be STABLIZING_WRITABLE_CONNECTION_PING_INTERVAL.
+ conn->ReceivedPingResponse();
+ int ping_sent_before = conn->num_pings_sent();
+ int64_t start = clock.TimeNanos() / 1000000;
+ SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1,
+ stablilizing_timeout, clock);
+ int64_t duration = clock.TimeNanos() / 1000000 - start;
+ EXPECT_TRUE(duration >= 900 && duration <= 1100);
+}
+
+TEST_F(P2PTransportChannelPingTest, TestStabilizedPingInterval) {
+ rtc::ScopedFakeClock clock;
+ int stabilized_timeout = 3000;
+
+ cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ cricket::P2PTransportChannel ch("TestChannel", 1, &pa);
+ PrepareChannel(&ch);
+ ch.Connect();
+ ch.MaybeStartGathering();
+ ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
+ cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ASSERT_TRUE(conn != nullptr);
+
+ // Wait for the connection to send MIN_PINGS_TO_STABILIZE pings to stablize.
+ SIMULATED_WAIT(conn->num_pings_sent() > MIN_PINGS_TO_STABILIZE,
+ kDefaultTimeout, clock);
+ // The connection become writable and receiving.
+ conn->ReceivedPingResponse();
+ int ping_sent_before = conn->num_pings_sent();
+ int64_t start = clock.TimeNanos() / 1000000;
+ SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1,
+ stabilized_timeout, clock);
+ int64_t duration = clock.TimeNanos() / 1000000 - start;
+ EXPECT_TRUE(duration >= 2500 && duration <= 2600);
+}
+
+// Verify that a stabilized connection will ping faster if a in-flight ping time
+// out.
+TEST_F(P2PTransportChannelPingTest, TestTimeoutPingInterval) {
+ rtc::ScopedFakeClock clock;
+ int stablilizing_timeout = 2000;
+
+ cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
+ cricket::P2PTransportChannel ch("TestChannel", 1, &pa);
+ PrepareChannel(&ch);
+ ch.Connect();
+ ch.MaybeStartGathering();
+ ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
+ cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ ASSERT_TRUE(conn != nullptr);
+
+ // Wait for the connection to send MIN_PINGS_TO_STABILIZE pings to stablize.
+ SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_TO_STABILIZE,
+ kDefaultTimeout, clock);
+ // The connection become writable and receiving.
+ conn->ReceivedPingResponse();
+
+ // Create a in-flight ping.
+ conn->Ping(clock.TimeNanos() / 1000000);
+ int ping_sent_before = conn->num_pings_sent();
+ int64_t start = clock.TimeNanos() / 1000000;
+ SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1,
+ stablilizing_timeout, clock);
+ int64_t duration = clock.TimeNanos() / 1000000 - start;
+ EXPECT_TRUE(duration >= 900 && duration <= 1100);
+}
+
TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
cricket::P2PTransportChannel ch("trigger checks", 1, &pa);
@@ -2707,13 +2812,14 @@ class P2PTransportChannelMostLikelyToWorkFirstTest
cricket::P2PTransportChannel& StartTransportChannel(
bool prioritize_most_likely_to_work,
- int max_strong_interval) {
+ int stable_writable_connection_ping_interval) {
channel_.reset(
new cricket::P2PTransportChannel("checks", 1, nullptr, allocator()));
cricket::IceConfig config = channel_->config();
config.prioritize_most_likely_candidate_pairs =
prioritize_most_likely_to_work;
- config.max_strong_interval = max_strong_interval;
+ config.stable_writable_connection_ping_interval =
+ stable_writable_connection_ping_interval;
channel_->SetIceConfig(config);
PrepareChannel(channel_.get());
channel_->Connect();
« 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