Skip to content

Commit

Permalink
Some feature clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsnaps committed May 21, 2024
1 parent 2ebd3d7 commit e83fbad
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions limitador/src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl Counter {
}
}

#[cfg(any(feature = "redis_storage", feature = "disk_storage"))]
pub(crate) fn key(&self) -> Self {
Self {
limit: self.limit.clone(),
Expand Down
9 changes: 2 additions & 7 deletions limitador/src/storage/atomic_expiring_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl AtomicExpiringValue {
self.value_at(SystemTime::now())
}

#[allow(dead_code)]
#[cfg(feature = "redis_storage")]
pub fn add_and_set_expiry(&self, delta: u64, expiry: SystemTime) -> u64 {
self.expiry.update(expiry);
self.value.fetch_add(delta, Ordering::SeqCst) + delta
Expand Down Expand Up @@ -59,11 +59,6 @@ impl AtomicExpiryTime {
}
}

#[allow(dead_code)]
pub fn from_now(ttl: Duration) -> Self {
Self::new(SystemTime::now() + ttl)
}

fn since_epoch(when: SystemTime) -> u64 {
when.duration_since(UNIX_EPOCH)
.expect("SystemTime before UNIX EPOCH!")
Expand All @@ -83,7 +78,7 @@ impl AtomicExpiryTime {
self.expiry.load(Ordering::SeqCst) <= when
}

#[allow(dead_code)]
#[cfg(feature = "redis_storage")]
pub fn update(&self, expiry: SystemTime) {
self.expiry
.store(Self::since_epoch(expiry), Ordering::SeqCst);
Expand Down
1 change: 1 addition & 0 deletions limitador/src/storage/redis/counters_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl CachedCounterValue {
}
}

#[cfg(feature = "redis_storage")]
pub fn add_from_authority(&self, delta: u64, expire_at: SystemTime, max_value: u64) {
let new_val = self.value.add_and_set_expiry(delta, expire_at);
if new_val > max_value {
Expand Down
4 changes: 2 additions & 2 deletions limitador/tests/helpers/tests_limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::collections::{HashMap, HashSet};

enum LimiterImpl {
Blocking(RateLimiter),
#[allow(dead_code)] // dead when no "redis_storage"
#[cfg(feature = "redis_storage")]
Async(AsyncRateLimiter),
}

Expand All @@ -25,7 +25,7 @@ impl TestsLimiter {
}
}

#[allow(dead_code)] // dead when no "redis_storage"
#[cfg(feature = "redis_storage")]
pub fn new_from_async_impl(limiter: AsyncRateLimiter) -> Self {
Self {
limiter_impl: LimiterImpl::Async(limiter),
Expand Down
3 changes: 3 additions & 0 deletions limitador/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ macro_rules! test_with_all_storage_impls {
$function(&mut TestsLimiter::new_from_blocking_impl(rate_limiter)).await;
}

#[cfg(feature = "disk_storage")]
#[tokio::test]
async fn [<$function _disk_storage>]() {
let dir = TempDir::new().expect("We should have a dir!");
Expand Down Expand Up @@ -96,13 +97,15 @@ mod test {
use self::limitador::RateLimiter;
use crate::helpers::tests_limiter::*;
use limitador::limit::Limit;
#[cfg(feature = "disk_storage")]
use limitador::storage::disk::{DiskStorage, OptimizeFor};
#[cfg(feature = "distributed_storage")]
use limitador::storage::distributed::CrInMemoryStorage;
use limitador::storage::in_memory::InMemoryStorage;
use std::collections::{HashMap, HashSet};
use std::thread::sleep;
use std::time::Duration;
#[cfg(feature = "disk_storage")]
use tempfile::TempDir;

test_with_all_storage_impls!(get_namespaces);
Expand Down

0 comments on commit e83fbad

Please sign in to comment.