Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exceptions happening due to too high marker rates #1359

Merged
merged 3 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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