#![cfg(all(
feature = "config",
feature = "worker-batch",
feature = "governor",
feature = "memory",
feature = "scaling"
))]
use hyperi_rustlib::config::{self, ConfigOptions};
use hyperi_rustlib::memory::MemoryGuardConfig;
use hyperi_rustlib::worker::BatchProcessingConfig;
use hyperi_rustlib::{ScalingPressureConfig, SelfRegulationConfig, WorkerPoolConfig};
#[test]
fn platform_sections_in_config_file_are_honoured() {
let yaml = "\
worker_pool:
min_threads: 7
max_threads: 9
self_regulation:
enabled: false
batch_processing:
max_chunk_size: 12345
scaling:
enabled: false
memory_gate_threshold: 0.55
memory:
limit_bytes: 123456789
pressure_threshold: 0.66
";
let dir = std::env::temp_dir().join(format!("rustlib-cascade-honoured-{}", std::process::id()));
std::fs::create_dir_all(&dir).expect("create temp dir");
let file = dir.join("config.yaml");
std::fs::write(&file, yaml).expect("write temp config");
config::setup(ConfigOptions {
config_file: Some(file.clone()),
..Default::default()
})
.expect("config setup");
let wp = WorkerPoolConfig::from_cascade("worker_pool").expect("worker pool config valid");
assert_eq!(
wp.min_threads, 7,
"worker_pool.min_threads must come from the config file, not the default (2)"
);
assert_eq!(wp.max_threads, 9, "worker_pool.max_threads from file");
let bp =
BatchProcessingConfig::from_cascade("batch_processing").expect("batch config deserialises");
assert_eq!(
bp.max_chunk_size, 12345,
"batch_processing.max_chunk_size must come from the config file, not the default (10_000)"
);
let sr = SelfRegulationConfig::from_cascade();
assert!(
!sr.enabled,
"self_regulation.enabled=false in the file must override the default-ON"
);
let sp = ScalingPressureConfig::from_cascade();
assert!(
!sp.enabled,
"scaling.enabled=false in the file must override the default (true)"
);
assert!(
(sp.memory_gate_threshold - 0.55).abs() < 1e-9,
"scaling.memory_gate_threshold must come from the file (0.55), not the default (0.8)"
);
let mem = MemoryGuardConfig::from_cascade_with_env("RUSTLIB_CASCADE_HONOURED_UNSET");
assert_eq!(
mem.limit_bytes, 123_456_789,
"memory.limit_bytes must come from the config file, not the default (0)"
);
assert!(
(mem.pressure_threshold - 0.66).abs() < 1e-9,
"memory.pressure_threshold must come from the file (0.66), not the default (0.80)"
);
std::fs::remove_dir_all(&dir).ok();
}