From 6c6f33b5bb934602896cdf06c9397fca1b9f6bdf Mon Sep 17 00:00:00 2001 From: "jiayl@webrtc.org" Date: Thu, 12 Jun 2014 21:05:19 +0000 Subject: [PATCH] Fix the flaky RTP DataChannel test. BUG=2891 R=wu@webrtc.org Review URL: https://webrtc-codereview.appspot.com/18519004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6418 4adac7df-926f-26a2-2b94-8c16560cd09d --- talk/app/webrtc/peerconnection_unittest.cc | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/talk/app/webrtc/peerconnection_unittest.cc b/talk/app/webrtc/peerconnection_unittest.cc index a98c256458..0c39297ab2 100644 --- a/talk/app/webrtc/peerconnection_unittest.cc +++ b/talk/app/webrtc/peerconnection_unittest.cc @@ -1009,6 +1009,16 @@ class P2PTestConductor : public testing::Test { kMaxWaitForFramesMs); } + void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { + // Messages may get lost on the unreliable DataChannel, so we send multiple + // times to avoid test flakiness. + static const size_t kSendAttempts = 5; + + for (size_t i = 0; i < kSendAttempts; ++i) { + dc->Send(DataBuffer(data)); + } + } + SignalingClass* initializing_client() { return initiating_client_.get(); } SignalingClass* receiving_client() { return receiving_client_.get(); } @@ -1251,12 +1261,7 @@ TEST_F(JsepPeerConnectionP2PTestClient, GetBytesSentStats) { } // This test sets up a call between two parties with audio, video and data. -// TODO(jiayl): fix the flakiness on Windows and reenable. Issue 2891. -#if defined(WIN32) -TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestDataChannel) { -#else TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestDataChannel) { -#endif FakeConstraints setup_constraints; setup_constraints.SetAllowRtpDataChannels(); ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); @@ -1270,10 +1275,12 @@ TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestDataChannel) { kMaxWaitMs); std::string data = "hello world"; - initializing_client()->data_channel()->Send(DataBuffer(data)); + + SendRtpData(initializing_client()->data_channel(), data); EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(), kMaxWaitMs); - receiving_client()->data_channel()->Send(DataBuffer(data)); + + SendRtpData(receiving_client()->data_channel(), data); EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(), kMaxWaitMs); @@ -1307,8 +1314,10 @@ TEST_F(JsepPeerConnectionP2PTestClient, RegisterDataChannelObserver) { // Unregister the existing observer. receiving_client()->data_channel()->UnregisterObserver(); + std::string data = "hello world"; - initializing_client()->data_channel()->Send(DataBuffer(data)); + SendRtpData(initializing_client()->data_channel(), data); + // Wait a while to allow the sent data to arrive before an observer is // registered.. talk_base::Thread::Current()->ProcessMessages(100);