pub mod rate_limiting;
use crate::errors::Result;
use async_trait::async_trait;
#[async_trait]
pub trait DistributedSessionStore: Send + Sync {
async fn total_session_count(&self) -> Result<u64>;
}
pub struct LocalOnlySessionStore;
#[async_trait]
impl DistributedSessionStore for LocalOnlySessionStore {
async fn total_session_count(&self) -> Result<u64> {
Ok(0)
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::sync::Arc;
#[tokio::test]
async fn test_local_only_returns_zero() {
let store = LocalOnlySessionStore;
assert_eq!(store.total_session_count().await.unwrap(), 0);
}
#[tokio::test]
async fn test_dyn_dispatch() {
let store: Arc<dyn DistributedSessionStore> = Arc::new(LocalOnlySessionStore);
assert_eq!(store.total_session_count().await.unwrap(), 0);
}
#[test]
fn test_local_only_is_send_sync() {
fn assert_send_sync<T: Send + Sync>() {}
assert_send_sync::<LocalOnlySessionStore>();
}
struct FixedCountStore(u64);
#[async_trait]
impl DistributedSessionStore for FixedCountStore {
async fn total_session_count(&self) -> Result<u64> {
Ok(self.0)
}
}
#[tokio::test]
async fn test_custom_store_returns_fixed_count() {
let store: Arc<dyn DistributedSessionStore> = Arc::new(FixedCountStore(99));
assert_eq!(store.total_session_count().await.unwrap(), 99);
}
#[tokio::test]
async fn test_multiple_calls_consistent() {
let store = LocalOnlySessionStore;
for _ in 0..5 {
assert_eq!(store.total_session_count().await.unwrap(), 0);
}
}
}