Skip to content

Commit

Permalink
Fix exceptions due to too high marker rates (lynckia#1359)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcague authored Feb 12, 2019
1 parent e0f9dbe commit 218bca7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions erizo/src/erizo/stats/StatNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ uint64_t MovingIntervalRateStat::calculateRateForInterval(uint64_t interval_to_c
last_value_part_in_interval = 0;
added_intervals++;
}
// Didn't pass enough time to know the rate
if (now_ms == interval_start_time) {
return 0;
}
double rate = static_cast<double> (total_sum) / (now_ms - interval_start_time);
return (rate * 1000 * scale_);
}
Expand Down
8 changes: 8 additions & 0 deletions erizo/src/test/stats/MovingIntervalRateStatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class MovingIntervalRateStatTest : public ::testing::Test {
void advanceClockMs(int time_ms) {
clock->advanceTime(std::chrono::milliseconds(time_ms));
}
void advanceClockUs(int time_us) {
clock->advanceTime(std::chrono::microseconds(time_us));
}
virtual void SetUp() {
}

Expand All @@ -53,6 +56,11 @@ TEST_F(MovingIntervalRateStatTest, shouldCalculateAverageForLessThanWindowSize)
EXPECT_EQ(moving_interval_stat.value(), uint((100 + 110 + 120)/3));
}

TEST_F(MovingIntervalRateStatTest, shouldReturnZeroIfNotEnoughTimePassed) {
moving_interval_stat+=1;
advanceClockUs(1);
EXPECT_EQ(moving_interval_stat.value(), 0u);
}

TEST_F(MovingIntervalRateStatTest, shouldReturnAverageOfWindowSize) {
const int kTotalSamples = 10;
Expand Down

0 comments on commit 218bca7

Please sign in to comment.