Add integration test for new GetStats() with many tracks

Bug: None
Change-Id: Ia134b4563edbb40e5082592666aad8ad70f1f1a4
Reviewed-on: https://webrtc-review.googlesource.com/c/112186
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25859}
This commit is contained in:
Steve Anton 2018-11-30 09:26:08 -08:00 committed by Commit Bot
parent a4dcb749fb
commit ffa6ce4714
2 changed files with 73 additions and 1 deletions

View File

@ -67,6 +67,19 @@ class RTC_EXPORT RTCStatsReport : public rtc::RefCountInterface {
const RTCStats* Get(const std::string& id) const;
size_t size() const { return stats_.size(); }
// Gets the stat object of type |T| by ID, where |T| is any class descending
// from |RTCStats|.
// Returns null if there is no stats object for the given ID or it is the
// wrong type.
template <typename T>
const T* GetAs(const std::string& id) const {
const RTCStats* stats = Get(id);
if (!stats || stats->type() != T::kType) {
return nullptr;
}
return &stats->cast_to<const T>();
}
// Removes the stats object from the report, returning ownership of it or null
// if there is no object with |id|.
std::unique_ptr<const RTCStats> Take(const std::string& id);

View File

@ -82,6 +82,7 @@ using ::testing::UnorderedElementsAreArray;
using ::testing::Return;
using ::testing::SetArgPointee;
using ::testing::Values;
using ::testing::UnorderedElementsAreArray;
using ::testing::_;
using webrtc::DataBuffer;
using webrtc::DataChannelInterface;
@ -2645,7 +2646,65 @@ TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
EXPECT_THAT(callee_stats->TrackIds(), UnorderedElementsAreArray(track_ids));
}
// Test that we can get stats (using the new stats implemnetation) for
// Test that the new GetStats() returns stats for all outgoing/incoming streams
// with the correct track IDs if there are more than one audio and more than one
// video senders/receivers.
TEST_P(PeerConnectionIntegrationTest, NewGetStatsManyAudioAndManyVideoStreams) {
ASSERT_TRUE(CreatePeerConnectionWrappers());
ConnectFakeSignaling();
auto audio_sender_1 = caller()->AddAudioTrack();
auto video_sender_1 = caller()->AddVideoTrack();
auto audio_sender_2 = caller()->AddAudioTrack();
auto video_sender_2 = caller()->AddVideoTrack();
caller()->CreateAndSetAndSignalOffer();
ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
MediaExpectations media_expectations;
media_expectations.CalleeExpectsSomeAudioAndVideo();
ASSERT_TRUE_WAIT(ExpectNewFrames(media_expectations), kDefaultTimeout);
std::vector<std::string> track_ids = {
audio_sender_1->track()->id(), video_sender_1->track()->id(),
audio_sender_2->track()->id(), video_sender_2->track()->id()};
rtc::scoped_refptr<const webrtc::RTCStatsReport> caller_report =
caller()->NewGetStats();
ASSERT_TRUE(caller_report);
auto outbound_stream_stats =
caller_report->GetStatsOfType<webrtc::RTCOutboundRTPStreamStats>();
ASSERT_EQ(4u, outbound_stream_stats.size());
std::vector<std::string> outbound_track_ids;
for (const auto& stat : outbound_stream_stats) {
ASSERT_TRUE(stat->bytes_sent.is_defined());
EXPECT_LT(0u, *stat->bytes_sent);
ASSERT_TRUE(stat->track_id.is_defined());
const auto* track_stat =
caller_report->GetAs<webrtc::RTCMediaStreamTrackStats>(*stat->track_id);
ASSERT_TRUE(track_stat);
outbound_track_ids.push_back(*track_stat->track_identifier);
}
EXPECT_THAT(outbound_track_ids, UnorderedElementsAreArray(track_ids));
rtc::scoped_refptr<const webrtc::RTCStatsReport> callee_report =
callee()->NewGetStats();
ASSERT_TRUE(callee_report);
auto inbound_stream_stats =
callee_report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>();
ASSERT_EQ(4u, inbound_stream_stats.size());
std::vector<std::string> inbound_track_ids;
for (const auto& stat : inbound_stream_stats) {
ASSERT_TRUE(stat->bytes_received.is_defined());
EXPECT_LT(0u, *stat->bytes_received);
ASSERT_TRUE(stat->track_id.is_defined());
const auto* track_stat =
callee_report->GetAs<webrtc::RTCMediaStreamTrackStats>(*stat->track_id);
ASSERT_TRUE(track_stat);
inbound_track_ids.push_back(*track_stat->track_identifier);
}
EXPECT_THAT(inbound_track_ids, UnorderedElementsAreArray(track_ids));
}
// Test that we can get stats (using the new stats implementation) for
// unsignaled streams. Meaning when SSRCs/MSIDs aren't signaled explicitly in
// SDP.
TEST_P(PeerConnectionIntegrationTest,