Skip to content

Commit

Permalink
limiter: include a test case for set_speed_limit involving inf speed
Browse files Browse the repository at this point in the history
Signed-off-by: kennytm <[email protected]>
  • Loading branch information
kennytm committed Jan 4, 2020
1 parent b2d3909 commit 7ce5be0
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,56 @@ mod tests_with_manual_clock {
fx.set_time(4_169_921_875);
assert_eq!(fx.total_bytes_consumed(), 2135);
}

#[test]
fn set_infinite_speed_limit() {
let mut fx = Fixture::new();

fx.spawn(|sfx| {
async move {
for _ in 0..1000 {
sfx.consume(512).await;
}
sfx.sleep(1).await;
for _ in 0..1000 {
sfx.consume(512).await;
}
sfx.sleep(1).await;
sfx.consume(512).await;
sfx.consume(512).await;
}
});

fx.set_time(0);
assert_eq!(fx.total_bytes_consumed(), 512);
fx.set_time(1_000_000_000);
assert_eq!(fx.total_bytes_consumed(), 1024);

// change speed limit to infinity...
fx.set_speed_limit(std::f64::INFINITY);

// should not affect tasks still waiting
fx.set_time(1_500_000_000);
assert_eq!(fx.total_bytes_consumed(), 1024);

// but all future consumptions will be unlimited.
fx.set_time(2_000_000_000);
assert_eq!(fx.total_bytes_consumed(), 512_000);

// should act normal for keeping speed limit at infinity.
fx.set_speed_limit(std::f64::INFINITY);
fx.set_time(2_000_000_001);
assert_eq!(fx.total_bytes_consumed(), 1_024_000);

// reducing speed limit to normal.
fx.set_speed_limit(512.0);
fx.set_time(2_000_000_002);
assert_eq!(fx.total_bytes_consumed(), 1_024_512);
fx.set_time(3_000_000_002);
assert_eq!(fx.total_bytes_consumed(), 1_025_024);
fx.set_time(4_000_000_002);
assert_eq!(fx.total_bytes_consumed(), 1_025_024);
}
}

#[cfg(test)]
Expand Down

0 comments on commit 7ce5be0

Please sign in to comment.