diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 16:53:03 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 16:53:03 +0000 |
| commit | 2a9160836bb87fdea3ae891563b0169c68d1c2ab (patch) | |
| tree | 583c890687beaf7f380fc0be131bdf17485f06fa /src/sync/health.rs | |
| parent | 52489d3b1a7d79e164b4cc901b53fd06c05ce1b1 (diff) | |
fix: resolve all fmt and clippy warnings
Main lib (src/):
- Add #[allow(dead_code)] for build_info field (stored to prevent Prometheus unregistration)
- Add #[allow(dead_code)] for first_seen field (reserved for future rate limiting)
- Replace .or_insert_with(RelaySyncNeeds::default) with .or_default()
- Replace manual div_ceil implementations with .div_ceil(100)
Test code (tests/):
- Replace .expect(&format!(...)) with .unwrap_or_else(|_| panic!(...))
- Remove needless borrows in fetch_metrics() calls
- Add #[allow(dead_code)] and #[allow(unused_imports)] to test helpers module
grasp-audit:
- Apply cargo fmt to fix formatting
Diffstat (limited to 'src/sync/health.rs')
| -rw-r--r-- | src/sync/health.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/sync/health.rs b/src/sync/health.rs index f9a5f3a..0ae7dee 100644 --- a/src/sync/health.rs +++ b/src/sync/health.rs | |||
| @@ -206,11 +206,7 @@ impl RelayHealthTracker { | |||
| 206 | health.next_retry_at = Some(now + backoff); | 206 | health.next_retry_at = Some(now + backoff); |
| 207 | 207 | ||
| 208 | if old_state != HealthState::Degraded { | 208 | if old_state != HealthState::Degraded { |
| 209 | tracing::warn!( | 209 | tracing::warn!("Relay {} degraded, backoff {:?}", relay_url, backoff); |
| 210 | "Relay {} degraded, backoff {:?}", | ||
| 211 | relay_url, | ||
| 212 | backoff | ||
| 213 | ); | ||
| 214 | } else { | 210 | } else { |
| 215 | tracing::debug!( | 211 | tracing::debug!( |
| 216 | "Relay {} failure #{}, backoff {:?}", | 212 | "Relay {} failure #{}, backoff {:?}", |
| @@ -308,12 +304,17 @@ impl RelayHealthTracker { | |||
| 308 | 304 | ||
| 309 | /// Get all tracked relay URLs | 305 | /// Get all tracked relay URLs |
| 310 | pub fn get_tracked_relays(&self) -> Vec<String> { | 306 | pub fn get_tracked_relays(&self) -> Vec<String> { |
| 311 | self.health.iter().map(|entry| entry.key().clone()).collect() | 307 | self.health |
| 308 | .iter() | ||
| 309 | .map(|entry| entry.key().clone()) | ||
| 310 | .collect() | ||
| 312 | } | 311 | } |
| 313 | 312 | ||
| 314 | /// Get a clone of the health info for a relay | 313 | /// Get a clone of the health info for a relay |
| 315 | pub fn get_health(&self, relay_url: &str) -> Option<RelayHealth> { | 314 | pub fn get_health(&self, relay_url: &str) -> Option<RelayHealth> { |
| 316 | self.health.get(relay_url).map(|entry| entry.value().clone()) | 315 | self.health |
| 316 | .get(relay_url) | ||
| 317 | .map(|entry| entry.value().clone()) | ||
| 317 | } | 318 | } |
| 318 | } | 319 | } |
| 319 | 320 | ||
| @@ -369,7 +370,7 @@ mod tests { | |||
| 369 | fn test_backoff_increases_exponentially() { | 370 | fn test_backoff_increases_exponentially() { |
| 370 | let base = DEFAULT_BASE_BACKOFF_SECS; // 5 seconds | 371 | let base = DEFAULT_BASE_BACKOFF_SECS; // 5 seconds |
| 371 | let max = 3600u64; | 372 | let max = 3600u64; |
| 372 | 373 | ||
| 373 | // failure 1: 5s (base * 2^0 = 5) | 374 | // failure 1: 5s (base * 2^0 = 5) |
| 374 | assert_eq!( | 375 | assert_eq!( |
| 375 | RelayHealthTracker::get_backoff_duration(1, base, max), | 376 | RelayHealthTracker::get_backoff_duration(1, base, max), |
| @@ -498,4 +499,4 @@ mod tests { | |||
| 498 | let health = tracker.get_health("wss://nonexistent.example.com"); | 499 | let health = tracker.get_health("wss://nonexistent.example.com"); |
| 499 | assert!(health.is_none()); | 500 | assert!(health.is_none()); |
| 500 | } | 501 | } |
| 501 | } \ No newline at end of file | 502 | } |