quota 0.1.0

High-performance Rate-limiter
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use super::{Quota, QuotaPolicy, QuotaPool};

#[test]
fn pool_auto_creates_quota() {
    let mut pool = QuotaPool::new(QuotaPolicy::new(10, 0.0000000005));

    let quota = pool.quota("testing");

    let mut results = vec![];
    for _ in 0..100 {
        results.push(quota.consume(1));
    }

    assert_eq!(results.iter().filter(|r| r.is_ok()).count(), 10);
    assert_eq!(results.iter().filter(|r| r.is_err()).count(), 90);
}