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

Unified Diff: webrtc/modules/pacing/alr_detector_unittest.cc

Issue 2965233002: Let alr dectector use a budged to detect underuse. (Closed)
Patch Set: Rebased. Created 3 years, 5 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/modules/pacing/alr_detector.cc ('k') | webrtc/modules/pacing/interval_budget.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/pacing/alr_detector_unittest.cc
diff --git a/webrtc/modules/pacing/alr_detector_unittest.cc b/webrtc/modules/pacing/alr_detector_unittest.cc
index 3c912772235a13b94b705de1f1cb2e2855e50089..e1a78103dfa235b8333b1529af6fbe59267b43b9 100644
--- a/webrtc/modules/pacing/alr_detector_unittest.cc
+++ b/webrtc/modules/pacing/alr_detector_unittest.cc
@@ -20,33 +20,58 @@ constexpr int kEstimatedBitrateBps = 300000;
namespace webrtc {
-class AlrDetectorTest : public testing::Test {
+namespace {
+class SimulateOutgoingTrafficIn {
public:
- void SetUp() override {
- alr_detector_.SetEstimatedBitrate(kEstimatedBitrateBps);
+ explicit SimulateOutgoingTrafficIn(AlrDetector* alr_detector)
+ : alr_detector_(alr_detector) {
+ RTC_CHECK(alr_detector_);
+ }
+
+ SimulateOutgoingTrafficIn& ForTimeMs(int time_ms) {
+ interval_ms_ = rtc::Optional<int>(time_ms);
+ interval_ms_.emplace(time_ms);
+ ProduceTraffic();
+ return *this;
}
- void SimulateOutgoingTraffic(int interval_ms, int usage_percentage) {
+ SimulateOutgoingTrafficIn& AtPercentOfEstimatedBitrate(int usage_percentage) {
+ usage_percentage_.emplace(usage_percentage);
+ ProduceTraffic();
+ return *this;
+ }
+
+ private:
+ void ProduceTraffic() {
+ if (!interval_ms_ || !usage_percentage_)
+ return;
const int kTimeStepMs = 10;
- for (int t = 0; t < interval_ms; t += kTimeStepMs) {
- now_ms += kTimeStepMs;
- alr_detector_.OnBytesSent(kEstimatedBitrateBps * usage_percentage *
- kTimeStepMs / (8 * 100 * 1000),
- now_ms);
+ for (int t = 0; t < *interval_ms_; t += kTimeStepMs) {
+ alr_detector_->OnBytesSent(kEstimatedBitrateBps * *usage_percentage_ *
+ kTimeStepMs / (8 * 100 * 1000),
+ kTimeStepMs);
}
-
- int remainder_ms = interval_ms % kTimeStepMs;
- now_ms += remainder_ms;
+ int remainder_ms = *interval_ms_ % kTimeStepMs;
if (remainder_ms > 0) {
- alr_detector_.OnBytesSent(kEstimatedBitrateBps * usage_percentage *
- remainder_ms / (8 * 100 * 1000),
- remainder_ms);
+ alr_detector_->OnBytesSent(kEstimatedBitrateBps * *usage_percentage_ *
+ remainder_ms / (8 * 100 * 1000),
+ kTimeStepMs);
}
}
+ AlrDetector* const alr_detector_;
+ rtc::Optional<int> interval_ms_;
+ rtc::Optional<int> usage_percentage_;
+};
+} // namespace
+
+class AlrDetectorTest : public testing::Test {
+ public:
+ void SetUp() override {
+ alr_detector_.SetEstimatedBitrate(kEstimatedBitrateBps);
+ }
protected:
AlrDetector alr_detector_;
- int64_t now_ms = 1;
};
TEST_F(AlrDetectorTest, AlrDetection) {
@@ -54,19 +79,21 @@ TEST_F(AlrDetectorTest, AlrDetection) {
EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
// Stay in non-ALR state when usage is close to 100%.
- SimulateOutgoingTraffic(500, 90);
+ SimulateOutgoingTrafficIn(&alr_detector_)
+ .ForTimeMs(1000)
+ .AtPercentOfEstimatedBitrate(90);
EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
// Verify that we ALR starts when bitrate drops below 20%.
- SimulateOutgoingTraffic(500, 20);
- EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
-
- // Verify that we remain in ALR state while usage is still below 70%.
- SimulateOutgoingTraffic(500, 69);
+ SimulateOutgoingTrafficIn(&alr_detector_)
+ .ForTimeMs(1000)
+ .AtPercentOfEstimatedBitrate(20);
EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
- // Verify that ALR ends when usage is above 70%.
- SimulateOutgoingTraffic(500, 75);
+ // Verify that ALR ends when usage is above 65%.
+ SimulateOutgoingTrafficIn(&alr_detector_)
+ .ForTimeMs(1000)
+ .AtPercentOfEstimatedBitrate(100);
EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
}
@@ -75,18 +102,21 @@ TEST_F(AlrDetectorTest, ShortSpike) {
EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
// Verify that we ALR starts when bitrate drops below 20%.
- SimulateOutgoingTraffic(500, 20);
+ SimulateOutgoingTrafficIn(&alr_detector_)
+ .ForTimeMs(1000)
+ .AtPercentOfEstimatedBitrate(20);
EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
// Verify that we stay in ALR region even after a short bitrate spike.
- SimulateOutgoingTraffic(100, 150);
- EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
-
- SimulateOutgoingTraffic(200, 20);
+ SimulateOutgoingTrafficIn(&alr_detector_)
+ .ForTimeMs(200)
+ .AtPercentOfEstimatedBitrate(150);
EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
- // ALR ends when usage is above 70%.
- SimulateOutgoingTraffic(500, 75);
+ // ALR ends when usage is above 65%.
+ SimulateOutgoingTrafficIn(&alr_detector_)
+ .ForTimeMs(1000)
+ .AtPercentOfEstimatedBitrate(100);
EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
}
@@ -95,7 +125,9 @@ TEST_F(AlrDetectorTest, BandwidthEstimateChanges) {
EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
// ALR starts when bitrate drops below 20%.
- SimulateOutgoingTraffic(500, 20);
+ SimulateOutgoingTrafficIn(&alr_detector_)
+ .ForTimeMs(1000)
+ .AtPercentOfEstimatedBitrate(20);
EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
// When bandwidth estimate drops the detector should stay in ALR mode and quit
@@ -104,7 +136,9 @@ TEST_F(AlrDetectorTest, BandwidthEstimateChanges) {
// to the BWE drop by initiating a new probe.
alr_detector_.SetEstimatedBitrate(kEstimatedBitrateBps / 5);
EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
- SimulateOutgoingTraffic(10, 20);
+ SimulateOutgoingTrafficIn(&alr_detector_)
+ .ForTimeMs(1000)
+ .AtPercentOfEstimatedBitrate(50);
EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
}
« no previous file with comments | « webrtc/modules/pacing/alr_detector.cc ('k') | webrtc/modules/pacing/interval_budget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698