Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions twilight-gateway/src/ratelimiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fn nonreserved_commands_per_reset(heartbeat_interval: Duration) -> u8 {
mod tests {
use super::{CommandRatelimiter, PERIOD, nonreserved_commands_per_reset};
use static_assertions::assert_impl_all;
use std::{fmt::Debug, future::poll_fn, time::Duration};
use std::{fmt::Debug, future::poll_fn, ops::Sub, time::Duration};
use tokio::time;

assert_impl_all!(CommandRatelimiter: Debug, Send, Sync);
Expand Down Expand Up @@ -227,7 +227,7 @@ mod tests {
assert_eq!(ratelimiter.available(), 0);

// Should not refill until PERIOD has passed.
time::advance(PERIOD - Duration::from_millis(100)).await;
time::advance(PERIOD.sub(Duration::from_millis(100))).await;
assert_eq!(ratelimiter.available(), 0);

// All should be refilled.
Expand Down Expand Up @@ -286,7 +286,7 @@ mod tests {
}
assert_eq!(ratelimiter.available(), ratelimiter.max() - 5);

time::advance(PERIOD - Duration::from_millis(80)).await;
time::advance(PERIOD.sub(Duration::from_millis(80))).await;
assert_eq!(ratelimiter.available(), ratelimiter.max() - 4);

for _ in 0..4 {
Expand Down
7 changes: 5 additions & 2 deletions twilight-http-ratelimiting/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,10 @@ pub async fn runner(

#[cfg(test)]
mod tests {
use std::time::{Duration, Instant};
use std::{
ops::Sub,
time::{Duration, Instant},
};
use tokio::time;

use crate::{Endpoint, Method, RateLimitHeaders, RateLimiter, actor::GC_INTERVAL};
Expand Down Expand Up @@ -365,7 +368,7 @@ mod tests {
reset_at: Instant::now() + RESET_AFTER,
}));

time::advance(GC_INTERVAL - RESET_AFTER).await;
time::advance(GC_INTERVAL.sub(RESET_AFTER)).await;

rate_limiter
.acquire(ENDPOINT2())
Expand Down