Skip to content
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
19 changes: 13 additions & 6 deletions src/vmm/src/rate_limiter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,13 @@ pub(crate) mod tests {

use super::*;

// Define custom refill interval to be a bit bigger. This will help
// in tests which wait for a limiter refill in 2 stages. This will make it so
// second wait will always result in the limiter being refilled. Otherwise
// there is a chance for a race condition between limiter refilling and limiter
// checking.
const TEST_REFILL_TIMER_INTERVAL_MS: u64 = REFILL_TIMER_INTERVAL_MS + 10;

impl TokenBucket {
// Resets the token bucket: budget set to max capacity and last-updated set to now.
fn reset(&mut self) {
Expand Down Expand Up @@ -1009,11 +1016,11 @@ pub(crate) mod tests {
// since consume failed, limiter should be blocked now
assert!(l.is_blocked());
// wait half the timer period
thread::sleep(Duration::from_millis(REFILL_TIMER_INTERVAL_MS / 2));
thread::sleep(Duration::from_millis(TEST_REFILL_TIMER_INTERVAL_MS / 2));
// limiter should still be blocked
assert!(l.is_blocked());
// wait the other half of the timer period
thread::sleep(Duration::from_millis(REFILL_TIMER_INTERVAL_MS / 2));
thread::sleep(Duration::from_millis(TEST_REFILL_TIMER_INTERVAL_MS / 2));
// the timer_fd should have an event on it by now
l.event_handler().unwrap();
// limiter should now be unblocked
Expand Down Expand Up @@ -1042,11 +1049,11 @@ pub(crate) mod tests {
// since consume failed, limiter should be blocked now
assert!(l.is_blocked());
// wait half the timer period
thread::sleep(Duration::from_millis(REFILL_TIMER_INTERVAL_MS / 2));
thread::sleep(Duration::from_millis(TEST_REFILL_TIMER_INTERVAL_MS / 2));
// limiter should still be blocked
assert!(l.is_blocked());
// wait the other half of the timer period
thread::sleep(Duration::from_millis(REFILL_TIMER_INTERVAL_MS / 2));
thread::sleep(Duration::from_millis(TEST_REFILL_TIMER_INTERVAL_MS / 2));
// the timer_fd should have an event on it by now
l.event_handler().unwrap();
// limiter should now be unblocked
Expand Down Expand Up @@ -1076,11 +1083,11 @@ pub(crate) mod tests {
// since consume failed, limiter should be blocked now
assert!(l.is_blocked());
// wait half the timer period
thread::sleep(Duration::from_millis(REFILL_TIMER_INTERVAL_MS / 2));
thread::sleep(Duration::from_millis(TEST_REFILL_TIMER_INTERVAL_MS / 2));
// limiter should still be blocked
assert!(l.is_blocked());
// wait the other half of the timer period
thread::sleep(Duration::from_millis(REFILL_TIMER_INTERVAL_MS / 2));
thread::sleep(Duration::from_millis(TEST_REFILL_TIMER_INTERVAL_MS / 2));
// the timer_fd should have an event on it by now
l.event_handler().unwrap();
// limiter should now be unblocked
Expand Down
4 changes: 3 additions & 1 deletion tests/integration_tests/functional/test_balloon.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ def get_rss_from_pmap():
first_rss = get_rss_from_pmap()
time.sleep(1)
second_rss = get_rss_from_pmap()
print(f"RSS readings: {first_rss}, {second_rss}")
abs_diff = abs(first_rss - second_rss)
abs_delta = 100 * abs_diff / first_rss
print(
f"RSS readings: old: {first_rss} new: {second_rss} abs_diff: {abs_diff} abs_delta: {abs_delta}"
)
assert abs_delta < percentage_delta or abs_diff < 2**10
return second_rss

Expand Down