Repository navigation
Expand file tree
/
Copy pathfailover_test.rs
More file actions
55 lines (44 loc) · 1.58 KB
/
Copy pathfailover_test.rs
File metadata and controls
55 lines (44 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! Failover and circuit-breaker tests.
//!
//! These tests do NOT spin up the Bonsai classifier (it would require loading
//! the 8B GGUF model). Instead, they verify the primitives used by the router:
//! the `HealthTracker` circuit breaker.
use brainrouter::health::HealthTracker;
#[test]
fn circuit_breaker_opens_after_threshold_failures() {
let tracker = HealthTracker::new();
let key = "manifest";
// Initially healthy
assert!(tracker.is_healthy(key));
// Report the threshold number of failures (3 per implementation)
tracker.report_failure(key);
tracker.report_failure(key);
assert!(tracker.is_healthy(key), "still healthy below threshold");
tracker.report_failure(key);
// Now the circuit should be open
assert!(!tracker.is_healthy(key), "circuit should be open after 3 failures");
}
#[test]
fn reporting_success_resets_circuit() {
let tracker = HealthTracker::new();
let key = "manifest";
// Trip the breaker
tracker.report_failure(key);
tracker.report_failure(key);
tracker.report_failure(key);
assert!(!tracker.is_healthy(key));
// Success reports should reset it
tracker.report_success(key);
assert!(tracker.is_healthy(key));
}
#[test]
fn independent_providers_have_independent_state() {
let tracker = HealthTracker::new();
// Break one provider
tracker.report_failure("manifest");
tracker.report_failure("manifest");
tracker.report_failure("manifest");
assert!(!tracker.is_healthy("manifest"));
// The other provider is unaffected
assert!(tracker.is_healthy("llama-swap"));
}