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

Side by Side Diff: webrtc/api/rtcstatscollector_unittest.cc

Issue 2521663002: RTCStatsIntegrationTest added. (Closed)
Patch Set: Rebase /w master and taking RTCCodecStats into account Created 4 years 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/api/rtcstats_integrationtest.cc ('k') | webrtc/api/test/peerconnectiontestwrapper.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 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2016 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
11 #include "webrtc/api/rtcstatscollector.h" 11 #include "webrtc/api/rtcstatscollector.h"
12 12
13 #include <memory> 13 #include <memory>
14 #include <ostream> 14 #include <ostream>
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "webrtc/api/jsepsessiondescription.h" 18 #include "webrtc/api/jsepsessiondescription.h"
19 #include "webrtc/api/mediastream.h" 19 #include "webrtc/api/mediastream.h"
20 #include "webrtc/api/mediastreamtrack.h" 20 #include "webrtc/api/mediastreamtrack.h"
21 #include "webrtc/api/rtpparameters.h" 21 #include "webrtc/api/rtpparameters.h"
22 #include "webrtc/api/stats/rtcstats_objects.h" 22 #include "webrtc/api/stats/rtcstats_objects.h"
23 #include "webrtc/api/stats/rtcstatsreport.h" 23 #include "webrtc/api/stats/rtcstatsreport.h"
24 #include "webrtc/api/test/mock_datachannel.h" 24 #include "webrtc/api/test/mock_datachannel.h"
25 #include "webrtc/api/test/mock_peerconnection.h" 25 #include "webrtc/api/test/mock_peerconnection.h"
26 #include "webrtc/api/test/mock_webrtcsession.h" 26 #include "webrtc/api/test/mock_webrtcsession.h"
27 #include "webrtc/api/test/rtcstatsobtainer.h"
27 #include "webrtc/base/checks.h" 28 #include "webrtc/base/checks.h"
28 #include "webrtc/base/fakeclock.h" 29 #include "webrtc/base/fakeclock.h"
29 #include "webrtc/base/fakesslidentity.h" 30 #include "webrtc/base/fakesslidentity.h"
30 #include "webrtc/base/gunit.h" 31 #include "webrtc/base/gunit.h"
31 #include "webrtc/base/logging.h" 32 #include "webrtc/base/logging.h"
32 #include "webrtc/base/socketaddress.h" 33 #include "webrtc/base/socketaddress.h"
33 #include "webrtc/base/thread_checker.h" 34 #include "webrtc/base/thread_checker.h"
34 #include "webrtc/base/timedelta.h" 35 #include "webrtc/base/timedelta.h"
35 #include "webrtc/base/timeutils.h" 36 #include "webrtc/base/timeutils.h"
36 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" 37 #include "webrtc/logging/rtc_event_log/rtc_event_log.h"
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 rtc::Thread* const worker_thread_; 466 rtc::Thread* const worker_thread_;
466 rtc::Thread* const network_thread_; 467 rtc::Thread* const network_thread_;
467 468
468 rtc::CriticalSection lock_; 469 rtc::CriticalSection lock_;
469 rtc::scoped_refptr<const RTCStatsReport> delivered_report_; 470 rtc::scoped_refptr<const RTCStatsReport> delivered_report_;
470 int produced_on_signaling_thread_ = 0; 471 int produced_on_signaling_thread_ = 0;
471 int produced_on_worker_thread_ = 0; 472 int produced_on_worker_thread_ = 0;
472 int produced_on_network_thread_ = 0; 473 int produced_on_network_thread_ = 0;
473 }; 474 };
474 475
475 class StatsCallback : public RTCStatsCollectorCallback {
476 public:
477 static rtc::scoped_refptr<StatsCallback> Create(
478 rtc::scoped_refptr<const RTCStatsReport>* report_ptr = nullptr) {
479 return rtc::scoped_refptr<StatsCallback>(
480 new rtc::RefCountedObject<StatsCallback>(report_ptr));
481 }
482
483 void OnStatsDelivered(
484 const rtc::scoped_refptr<const RTCStatsReport>& report) override {
485 EXPECT_TRUE(thread_checker_.CalledOnValidThread());
486 report_ = report;
487 if (report_ptr_)
488 *report_ptr_ = report_;
489 }
490
491 rtc::scoped_refptr<const RTCStatsReport> report() const {
492 EXPECT_TRUE(thread_checker_.CalledOnValidThread());
493 return report_;
494 }
495
496 protected:
497 explicit StatsCallback(rtc::scoped_refptr<const RTCStatsReport>* report_ptr)
498 : report_ptr_(report_ptr) {}
499
500 private:
501 rtc::ThreadChecker thread_checker_;
502 rtc::scoped_refptr<const RTCStatsReport> report_;
503 rtc::scoped_refptr<const RTCStatsReport>* report_ptr_;
504 };
505
506 class RTCStatsCollectorTest : public testing::Test { 476 class RTCStatsCollectorTest : public testing::Test {
507 public: 477 public:
508 RTCStatsCollectorTest() 478 RTCStatsCollectorTest()
509 : test_(new rtc::RefCountedObject<RTCStatsCollectorTestHelper>()), 479 : test_(new rtc::RefCountedObject<RTCStatsCollectorTestHelper>()),
510 collector_(RTCStatsCollector::Create( 480 collector_(RTCStatsCollector::Create(
511 &test_->pc(), 50 * rtc::kNumMicrosecsPerMillisec)) { 481 &test_->pc(), 50 * rtc::kNumMicrosecsPerMillisec)) {
512 } 482 }
513 483
514 rtc::scoped_refptr<const RTCStatsReport> GetStatsReport() { 484 rtc::scoped_refptr<const RTCStatsReport> GetStatsReport() {
515 rtc::scoped_refptr<StatsCallback> callback = StatsCallback::Create(); 485 rtc::scoped_refptr<RTCStatsObtainer> callback = RTCStatsObtainer::Create();
516 collector_->GetStatsReport(callback); 486 collector_->GetStatsReport(callback);
517 EXPECT_TRUE_WAIT(callback->report(), kGetStatsReportTimeoutMs); 487 EXPECT_TRUE_WAIT(callback->report(), kGetStatsReportTimeoutMs);
518 int64_t after = rtc::TimeUTCMicros(); 488 int64_t after = rtc::TimeUTCMicros();
519 for (const RTCStats& stats : *callback->report()) { 489 for (const RTCStats& stats : *callback->report()) {
520 EXPECT_LE(stats.timestamp_us(), after); 490 EXPECT_LE(stats.timestamp_us(), after);
521 } 491 }
522 return callback->report(); 492 return callback->report();
523 } 493 }
524 494
525 const RTCIceCandidateStats* ExpectReportContainsCandidate( 495 const RTCIceCandidateStats* ExpectReportContainsCandidate(
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 data_channel.bytes_received()); 686 data_channel.bytes_received());
717 } 687 }
718 688
719 protected: 689 protected:
720 rtc::scoped_refptr<RTCStatsCollectorTestHelper> test_; 690 rtc::scoped_refptr<RTCStatsCollectorTestHelper> test_;
721 rtc::scoped_refptr<RTCStatsCollector> collector_; 691 rtc::scoped_refptr<RTCStatsCollector> collector_;
722 }; 692 };
723 693
724 TEST_F(RTCStatsCollectorTest, SingleCallback) { 694 TEST_F(RTCStatsCollectorTest, SingleCallback) {
725 rtc::scoped_refptr<const RTCStatsReport> result; 695 rtc::scoped_refptr<const RTCStatsReport> result;
726 collector_->GetStatsReport(StatsCallback::Create(&result)); 696 collector_->GetStatsReport(RTCStatsObtainer::Create(&result));
727 EXPECT_TRUE_WAIT(result, kGetStatsReportTimeoutMs); 697 EXPECT_TRUE_WAIT(result, kGetStatsReportTimeoutMs);
728 } 698 }
729 699
730 TEST_F(RTCStatsCollectorTest, MultipleCallbacks) { 700 TEST_F(RTCStatsCollectorTest, MultipleCallbacks) {
731 rtc::scoped_refptr<const RTCStatsReport> a; 701 rtc::scoped_refptr<const RTCStatsReport> a;
732 rtc::scoped_refptr<const RTCStatsReport> b; 702 rtc::scoped_refptr<const RTCStatsReport> b;
733 rtc::scoped_refptr<const RTCStatsReport> c; 703 rtc::scoped_refptr<const RTCStatsReport> c;
734 collector_->GetStatsReport(StatsCallback::Create(&a)); 704 collector_->GetStatsReport(RTCStatsObtainer::Create(&a));
735 collector_->GetStatsReport(StatsCallback::Create(&b)); 705 collector_->GetStatsReport(RTCStatsObtainer::Create(&b));
736 collector_->GetStatsReport(StatsCallback::Create(&c)); 706 collector_->GetStatsReport(RTCStatsObtainer::Create(&c));
737 EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs); 707 EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs);
738 EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs); 708 EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs);
739 EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs); 709 EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs);
740 EXPECT_EQ(a.get(), b.get()); 710 EXPECT_EQ(a.get(), b.get());
741 EXPECT_EQ(b.get(), c.get()); 711 EXPECT_EQ(b.get(), c.get());
742 } 712 }
743 713
744 TEST_F(RTCStatsCollectorTest, CachedStatsReports) { 714 TEST_F(RTCStatsCollectorTest, CachedStatsReports) {
745 // Caching should ensure |a| and |b| are the same report. 715 // Caching should ensure |a| and |b| are the same report.
746 rtc::scoped_refptr<const RTCStatsReport> a = GetStatsReport(); 716 rtc::scoped_refptr<const RTCStatsReport> a = GetStatsReport();
747 rtc::scoped_refptr<const RTCStatsReport> b = GetStatsReport(); 717 rtc::scoped_refptr<const RTCStatsReport> b = GetStatsReport();
748 EXPECT_EQ(a.get(), b.get()); 718 EXPECT_EQ(a.get(), b.get());
749 // Invalidate cache by clearing it. 719 // Invalidate cache by clearing it.
750 collector_->ClearCachedStatsReport(); 720 collector_->ClearCachedStatsReport();
751 rtc::scoped_refptr<const RTCStatsReport> c = GetStatsReport(); 721 rtc::scoped_refptr<const RTCStatsReport> c = GetStatsReport();
752 EXPECT_NE(b.get(), c.get()); 722 EXPECT_NE(b.get(), c.get());
753 // Invalidate cache by advancing time. 723 // Invalidate cache by advancing time.
754 test_->fake_clock().AdvanceTime(rtc::TimeDelta::FromMilliseconds(51)); 724 test_->fake_clock().AdvanceTime(rtc::TimeDelta::FromMilliseconds(51));
755 rtc::scoped_refptr<const RTCStatsReport> d = GetStatsReport(); 725 rtc::scoped_refptr<const RTCStatsReport> d = GetStatsReport();
756 EXPECT_TRUE(d); 726 EXPECT_TRUE(d);
757 EXPECT_NE(c.get(), d.get()); 727 EXPECT_NE(c.get(), d.get());
758 } 728 }
759 729
760 TEST_F(RTCStatsCollectorTest, MultipleCallbacksWithInvalidatedCacheInBetween) { 730 TEST_F(RTCStatsCollectorTest, MultipleCallbacksWithInvalidatedCacheInBetween) {
761 rtc::scoped_refptr<const RTCStatsReport> a; 731 rtc::scoped_refptr<const RTCStatsReport> a;
762 rtc::scoped_refptr<const RTCStatsReport> b; 732 rtc::scoped_refptr<const RTCStatsReport> b;
763 rtc::scoped_refptr<const RTCStatsReport> c; 733 rtc::scoped_refptr<const RTCStatsReport> c;
764 collector_->GetStatsReport(StatsCallback::Create(&a)); 734 collector_->GetStatsReport(RTCStatsObtainer::Create(&a));
765 collector_->GetStatsReport(StatsCallback::Create(&b)); 735 collector_->GetStatsReport(RTCStatsObtainer::Create(&b));
766 // Cache is invalidated after 50 ms. 736 // Cache is invalidated after 50 ms.
767 test_->fake_clock().AdvanceTime(rtc::TimeDelta::FromMilliseconds(51)); 737 test_->fake_clock().AdvanceTime(rtc::TimeDelta::FromMilliseconds(51));
768 collector_->GetStatsReport(StatsCallback::Create(&c)); 738 collector_->GetStatsReport(RTCStatsObtainer::Create(&c));
769 EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs); 739 EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs);
770 EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs); 740 EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs);
771 EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs); 741 EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs);
772 EXPECT_EQ(a.get(), b.get()); 742 EXPECT_EQ(a.get(), b.get());
773 // The act of doing |AdvanceTime| processes all messages. If this was not the 743 // The act of doing |AdvanceTime| processes all messages. If this was not the
774 // case we might not require |c| to be fresher than |b|. 744 // case we might not require |c| to be fresher than |b|.
775 EXPECT_NE(c.get(), b.get()); 745 EXPECT_NE(c.get(), b.get());
776 } 746 }
777 747
778 TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsSingle) { 748 TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsSingle) {
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; 1787 rtc::scoped_refptr<FakeRTCStatsCollector> collector_;
1818 }; 1788 };
1819 1789
1820 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { 1790 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) {
1821 collector_->VerifyThreadUsageAndResultsMerging(); 1791 collector_->VerifyThreadUsageAndResultsMerging();
1822 } 1792 }
1823 1793
1824 } // namespace 1794 } // namespace
1825 1795
1826 } // namespace webrtc 1796 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/rtcstats_integrationtest.cc ('k') | webrtc/api/test/peerconnectiontestwrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698