MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / refills_over_time

Function refills_over_time

nodedb/src/control/server/sync/rate_limit.rs:132–150  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

130
131 #[test]
132 fn refills_over_time() {
133 let config = RateLimitConfig {
134 rate_per_sec: 1000.0, // Fast refill for test.
135 burst: 5,
136 };
137 let mut limiter = SyncRateLimiter::new(&config);
138
139 // Drain all tokens.
140 for _ in 0..5 {
141 limiter.try_acquire().ok();
142 }
143 assert!(limiter.try_acquire().is_err());
144
145 // Wait for refill (at 1000/s, 10ms = ~10 tokens, capped at burst=5).
146 thread::sleep(Duration::from_millis(10));
147
148 // Should have tokens again.
149 assert!(limiter.try_acquire().is_ok());
150 }
151
152 #[test]
153 fn retry_after_is_reasonable() {

Callers

nothing calls this directly

Calls 2

okMethod · 0.45
try_acquireMethod · 0.45

Tested by

no test coverage detected