use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LifecycleConfig {
pub enable_background_execution: bool,
pub background_execution_limit_seconds: u64,
pub enable_state_persistence: bool,
pub state_save_interval_seconds: u64,
pub resource_management: ResourceManagementConfig,
pub background_tasks: BackgroundTaskConfig,
pub notifications: NotificationConfig,
pub memory_warning_handling: MemoryWarningConfig,
pub thermal_warning_handling: ThermalWarningConfig,
pub network_interruption_handling: NetworkInterruptionConfig,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResourceManagementConfig {
pub enable_auto_scaling: bool,
pub memory_pressure_response: MemoryPressureResponse,
pub thermal_pressure_response: ThermalPressureResponse,
pub battery_pressure_response: BatteryPressureResponse,
pub background_limits: BackgroundResourceLimits,
pub foreground_allocation: ForegroundResourceAllocation,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryPressureResponse {
pub enable_cleanup: bool,
pub pressure_thresholds: MemoryPressureThresholds,
pub cleanup_strategies: HashMap<MemoryPressureLevel, CleanupStrategy>,
pub model_eviction_policy: ModelEvictionPolicy,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryPressureThresholds {
pub warning_percent: u8,
pub critical_percent: u8,
pub emergency_percent: u8,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub enum MemoryPressureLevel {
Normal,
Warning,
Critical,
Emergency,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CleanupStrategy {
pub clear_model_cache: bool,
pub clear_intermediate_tensors: bool,
pub reduce_batch_sizes: bool,
pub compress_models: bool,
pub offload_to_disk: bool,
pub cleanup_priority: CleanupPriority,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum CleanupPriority {
Low,
Medium,
High,
Critical,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ModelEvictionPolicy {
LeastRecentlyUsed,
LeastFrequentlyUsed,
SizeBasedEviction,
PriorityBasedEviction,
AdaptiveEviction,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ThermalPressureResponse {
pub enable_response: bool,
pub throttling_levels: ThermalThrottlingLevels,
pub performance_scaling: PerformanceScalingStrategy,
pub frequency_reduction: FrequencyReductionConfig,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ThermalThrottlingLevels {
pub light_throttle_celsius: f32,
pub moderate_throttle_celsius: f32,
pub heavy_throttle_celsius: f32,
pub emergency_throttle_celsius: f32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum PerformanceScalingStrategy {
Linear,
Exponential,
Adaptive,
UserDefined,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FrequencyReductionConfig {
pub enable_reduction: bool,
pub reduction_factors: HashMap<ThermalLevel, f32>,
pub min_frequency_hz: f32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum ThermalLevel {
Normal,
Light,
Moderate,
Heavy,
Emergency,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatteryPressureResponse {
pub enable_response: bool,
pub battery_thresholds: BatteryThresholds,
pub power_saving_strategies: HashMap<crate::battery::BatteryLevel, PowerSavingStrategy>,
pub background_processing_limits: BackgroundProcessingLimits,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatteryThresholds {
pub critical_percent: u8,
pub low_percent: u8,
pub medium_percent: u8,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PowerSavingStrategy {
pub reduce_inference_frequency: bool,
pub lower_model_precision: bool,
pub disable_background_updates: bool,
pub cpu_only_inference: bool,
pub defer_non_critical_tasks: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BackgroundProcessingLimits {
pub max_background_time_seconds: u64,
pub max_cpu_usage_percent: u8,
pub max_memory_usage_mb: usize,
pub priority_adjustments: HashMap<TaskType, i8>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BackgroundResourceLimits {
pub max_cpu_percent: u8,
pub max_memory_mb: usize,
pub max_network_mbps: f32,
pub max_execution_time_seconds: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ForegroundResourceAllocation {
pub cpu_allocation_percent: u8,
pub memory_allocation_mb: usize,
pub network_allocation_mbps: f32,
pub gpu_allocation_percent: Option<u8>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BackgroundTaskConfig {
pub enable_model_updates: bool,
pub enable_federated_learning: bool,
pub enable_data_processing: bool,
pub task_priorities: HashMap<TaskType, TaskPriority>,
pub scheduling_strategies: HashMap<TaskType, SchedulingStrategy>,
pub max_concurrent_tasks: usize,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum TaskType {
ModelUpdate,
FederatedLearning,
DataSync,
CacheCleanup,
Analytics,
Backup,
Precomputation,
HealthCheck,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum TaskPriority {
Low,
Normal,
High,
Critical,
Emergency,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum SchedulingStrategy {
Immediate,
Deferred,
OpportunisticAgg,
UserIdle,
NetworkOptimal,
BatteryOptimal,
ThermalOptimal,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NotificationConfig {
pub enable_push_notifications: bool,
pub enable_local_notifications: bool,
pub enabled_types: Vec<NotificationType>,
pub background_handling: BackgroundNotificationHandling,
pub throttling: NotificationThrottling,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum NotificationType {
ModelUpdateAvailable,
FederatedLearningTask,
SystemAlert,
PerformanceWarning,
MaintenanceRequired,
UserAction,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BackgroundNotificationHandling {
pub queue_when_background: bool,
pub max_queued_notifications: usize,
pub batch_delivery: bool,
pub delivery_strategies: HashMap<NotificationType, DeliveryStrategy>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum DeliveryStrategy {
Immediate,
Batched,
Deferred,
OnForeground,
UserTriggered,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NotificationThrottling {
pub enable_throttling: bool,
pub max_per_hour: u32,
pub min_interval_seconds: u64,
pub notification_rate_limits: HashMap<NotificationType, u32>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryWarningConfig {
pub enable_handling: bool,
pub automatic_cleanup: bool,
pub response_strategies: Vec<MemoryWarningResponse>,
pub grace_period_seconds: u64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum MemoryWarningResponse {
ClearCaches,
ReduceBatchSizes,
OffloadModels,
PauseBackgroundTasks,
NotifyUser,
ForceGarbageCollection,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ThermalWarningConfig {
pub enable_handling: bool,
pub automatic_throttling: bool,
pub response_strategies: Vec<ThermalWarningResponse>,
pub cooldown_period_seconds: u64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ThermalWarningResponse {
ReduceInferenceFrequency,
LowerModelPrecision,
PauseComputeIntensiveTasks,
SwitchToCpuOnly,
NotifyUser,
EnterCooldownMode,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NetworkInterruptionConfig {
pub enable_handling: bool,
pub automatic_reconnection: bool,
pub max_reconnection_attempts: u32,
pub backoff_strategy: ReconnectionBackoffStrategy,
pub offline_mode: OfflineModeConfig,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ReconnectionBackoffStrategy {
Linear,
Exponential,
Fibonacci,
Custom,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OfflineModeConfig {
pub enable_offline_mode: bool,
pub local_model_fallback: bool,
pub cache_inference_results: bool,
pub queue_sync_operations: bool,
pub max_offline_cache_mb: usize,
}
impl Default for LifecycleConfig {
fn default() -> Self {
Self {
enable_background_execution: true,
background_execution_limit_seconds: 30,
enable_state_persistence: true,
state_save_interval_seconds: 60,
resource_management: ResourceManagementConfig::default(),
background_tasks: BackgroundTaskConfig::default(),
notifications: NotificationConfig::default(),
memory_warning_handling: MemoryWarningConfig::default(),
thermal_warning_handling: ThermalWarningConfig::default(),
network_interruption_handling: NetworkInterruptionConfig::default(),
}
}
}
impl Default for ResourceManagementConfig {
fn default() -> Self {
Self {
enable_auto_scaling: true,
memory_pressure_response: MemoryPressureResponse::default(),
thermal_pressure_response: ThermalPressureResponse::default(),
battery_pressure_response: BatteryPressureResponse::default(),
background_limits: BackgroundResourceLimits::default(),
foreground_allocation: ForegroundResourceAllocation::default(),
}
}
}
impl Default for MemoryPressureResponse {
fn default() -> Self {
let mut cleanup_strategies = HashMap::new();
cleanup_strategies.insert(
MemoryPressureLevel::Warning,
CleanupStrategy {
clear_model_cache: true,
clear_intermediate_tensors: false,
reduce_batch_sizes: false,
compress_models: false,
offload_to_disk: false,
cleanup_priority: CleanupPriority::Low,
},
);
cleanup_strategies.insert(
MemoryPressureLevel::Critical,
CleanupStrategy {
clear_model_cache: true,
clear_intermediate_tensors: true,
reduce_batch_sizes: true,
compress_models: true,
offload_to_disk: false,
cleanup_priority: CleanupPriority::Medium,
},
);
cleanup_strategies.insert(
MemoryPressureLevel::Emergency,
CleanupStrategy {
clear_model_cache: true,
clear_intermediate_tensors: true,
reduce_batch_sizes: true,
compress_models: true,
offload_to_disk: true,
cleanup_priority: CleanupPriority::Critical,
},
);
Self {
enable_cleanup: true,
pressure_thresholds: MemoryPressureThresholds {
warning_percent: 70,
critical_percent: 85,
emergency_percent: 95,
},
cleanup_strategies,
model_eviction_policy: ModelEvictionPolicy::LeastRecentlyUsed,
}
}
}
impl Default for ThermalPressureResponse {
fn default() -> Self {
let mut reduction_factors = HashMap::new();
reduction_factors.insert(ThermalLevel::Light, 0.9);
reduction_factors.insert(ThermalLevel::Moderate, 0.7);
reduction_factors.insert(ThermalLevel::Heavy, 0.5);
reduction_factors.insert(ThermalLevel::Emergency, 0.3);
Self {
enable_response: true,
throttling_levels: ThermalThrottlingLevels {
light_throttle_celsius: 40.0,
moderate_throttle_celsius: 45.0,
heavy_throttle_celsius: 50.0,
emergency_throttle_celsius: 55.0,
},
performance_scaling: PerformanceScalingStrategy::Adaptive,
frequency_reduction: FrequencyReductionConfig {
enable_reduction: true,
reduction_factors,
min_frequency_hz: 1.0,
},
}
}
}
impl Default for BatteryPressureResponse {
fn default() -> Self {
use crate::battery::BatteryLevel;
let mut power_saving_strategies = HashMap::new();
power_saving_strategies.insert(
BatteryLevel::Critical,
PowerSavingStrategy {
reduce_inference_frequency: true,
lower_model_precision: true,
disable_background_updates: true,
cpu_only_inference: true,
defer_non_critical_tasks: true,
},
);
power_saving_strategies.insert(
BatteryLevel::Low,
PowerSavingStrategy {
reduce_inference_frequency: true,
lower_model_precision: false,
disable_background_updates: true,
cpu_only_inference: false,
defer_non_critical_tasks: true,
},
);
let mut priority_adjustments = HashMap::new();
priority_adjustments.insert(TaskType::ModelUpdate, -1);
priority_adjustments.insert(TaskType::FederatedLearning, -2);
priority_adjustments.insert(TaskType::Analytics, -1);
Self {
enable_response: true,
battery_thresholds: BatteryThresholds {
critical_percent: 15,
low_percent: 30,
medium_percent: 50,
},
power_saving_strategies,
background_processing_limits: BackgroundProcessingLimits {
max_background_time_seconds: 10,
max_cpu_usage_percent: 20,
max_memory_usage_mb: 100,
priority_adjustments,
},
}
}
}
impl Default for BackgroundResourceLimits {
fn default() -> Self {
Self {
max_cpu_percent: 30,
max_memory_mb: 256,
max_network_mbps: 1.0,
max_execution_time_seconds: 30,
}
}
}
impl Default for ForegroundResourceAllocation {
fn default() -> Self {
Self {
cpu_allocation_percent: 80,
memory_allocation_mb: 1024,
network_allocation_mbps: 10.0,
gpu_allocation_percent: Some(70),
}
}
}
impl Default for BackgroundTaskConfig {
fn default() -> Self {
let mut task_priorities = HashMap::new();
task_priorities.insert(TaskType::ModelUpdate, TaskPriority::Normal);
task_priorities.insert(TaskType::FederatedLearning, TaskPriority::Low);
task_priorities.insert(TaskType::DataSync, TaskPriority::Normal);
task_priorities.insert(TaskType::CacheCleanup, TaskPriority::Low);
task_priorities.insert(TaskType::Analytics, TaskPriority::Low);
task_priorities.insert(TaskType::Backup, TaskPriority::Low);
task_priorities.insert(TaskType::Precomputation, TaskPriority::Normal);
task_priorities.insert(TaskType::HealthCheck, TaskPriority::High);
let mut scheduling_strategies = HashMap::new();
scheduling_strategies.insert(TaskType::ModelUpdate, SchedulingStrategy::NetworkOptimal);
scheduling_strategies.insert(
TaskType::FederatedLearning,
SchedulingStrategy::BatteryOptimal,
);
scheduling_strategies.insert(TaskType::DataSync, SchedulingStrategy::NetworkOptimal);
scheduling_strategies.insert(TaskType::CacheCleanup, SchedulingStrategy::UserIdle);
scheduling_strategies.insert(TaskType::Analytics, SchedulingStrategy::UserIdle);
scheduling_strategies.insert(TaskType::Backup, SchedulingStrategy::UserIdle);
scheduling_strategies.insert(TaskType::Precomputation, SchedulingStrategy::ThermalOptimal);
scheduling_strategies.insert(TaskType::HealthCheck, SchedulingStrategy::Immediate);
Self {
enable_model_updates: true,
enable_federated_learning: false,
enable_data_processing: true,
task_priorities,
scheduling_strategies,
max_concurrent_tasks: 3,
}
}
}
impl Default for NotificationConfig {
fn default() -> Self {
let enabled_types = vec![
NotificationType::SystemAlert,
NotificationType::PerformanceWarning,
NotificationType::MaintenanceRequired,
];
Self {
enable_push_notifications: true,
enable_local_notifications: true,
enabled_types,
background_handling: BackgroundNotificationHandling::default(),
throttling: NotificationThrottling::default(),
}
}
}
impl Default for BackgroundNotificationHandling {
fn default() -> Self {
let mut delivery_strategies = HashMap::new();
delivery_strategies.insert(
NotificationType::ModelUpdateAvailable,
DeliveryStrategy::Batched,
);
delivery_strategies.insert(
NotificationType::FederatedLearningTask,
DeliveryStrategy::Deferred,
);
delivery_strategies.insert(NotificationType::SystemAlert, DeliveryStrategy::Immediate);
delivery_strategies.insert(
NotificationType::PerformanceWarning,
DeliveryStrategy::OnForeground,
);
delivery_strategies.insert(
NotificationType::MaintenanceRequired,
DeliveryStrategy::Batched,
);
delivery_strategies.insert(
NotificationType::UserAction,
DeliveryStrategy::UserTriggered,
);
Self {
queue_when_background: true,
max_queued_notifications: 10,
batch_delivery: true,
delivery_strategies,
}
}
}
impl Default for NotificationThrottling {
fn default() -> Self {
let mut notification_rate_limits = HashMap::new();
notification_rate_limits.insert(NotificationType::ModelUpdateAvailable, 2);
notification_rate_limits.insert(NotificationType::FederatedLearningTask, 5);
notification_rate_limits.insert(NotificationType::SystemAlert, 10);
notification_rate_limits.insert(NotificationType::PerformanceWarning, 20);
notification_rate_limits.insert(NotificationType::MaintenanceRequired, 100);
Self {
enable_throttling: true,
max_per_hour: 10,
min_interval_seconds: 300, notification_rate_limits,
}
}
}
impl Default for MemoryWarningConfig {
fn default() -> Self {
Self {
enable_handling: true,
automatic_cleanup: true,
response_strategies: vec![
MemoryWarningResponse::ClearCaches,
MemoryWarningResponse::ReduceBatchSizes,
MemoryWarningResponse::PauseBackgroundTasks,
],
grace_period_seconds: 10,
}
}
}
impl Default for ThermalWarningConfig {
fn default() -> Self {
Self {
enable_handling: true,
automatic_throttling: true,
response_strategies: vec![
ThermalWarningResponse::ReduceInferenceFrequency,
ThermalWarningResponse::PauseComputeIntensiveTasks,
],
cooldown_period_seconds: 30,
}
}
}
impl Default for NetworkInterruptionConfig {
fn default() -> Self {
Self {
enable_handling: true,
automatic_reconnection: true,
max_reconnection_attempts: 5,
backoff_strategy: ReconnectionBackoffStrategy::Exponential,
offline_mode: OfflineModeConfig::default(),
}
}
}
impl Default for OfflineModeConfig {
fn default() -> Self {
Self {
enable_offline_mode: true,
local_model_fallback: true,
cache_inference_results: true,
queue_sync_operations: true,
max_offline_cache_mb: 100,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_lifecycle_config_default_fields() {
let cfg = LifecycleConfig::default();
assert!(cfg.enable_background_execution);
assert!(cfg.background_execution_limit_seconds > 0);
assert!(cfg.enable_state_persistence);
assert!(cfg.state_save_interval_seconds > 0);
}
#[test]
fn test_memory_pressure_level_ordering() {
assert!(MemoryPressureLevel::Normal < MemoryPressureLevel::Warning);
assert!(MemoryPressureLevel::Warning < MemoryPressureLevel::Critical);
assert!(MemoryPressureLevel::Critical < MemoryPressureLevel::Emergency);
}
#[test]
fn test_memory_pressure_level_equality() {
assert_eq!(MemoryPressureLevel::Normal, MemoryPressureLevel::Normal);
assert_ne!(MemoryPressureLevel::Warning, MemoryPressureLevel::Critical);
}
#[test]
fn test_cleanup_priority_ordering() {
assert!(CleanupPriority::Low < CleanupPriority::Medium);
assert!(CleanupPriority::Medium < CleanupPriority::High);
assert!(CleanupPriority::High < CleanupPriority::Critical);
}
#[test]
fn test_model_eviction_policy_variants() {
let policies = [
ModelEvictionPolicy::LeastRecentlyUsed,
ModelEvictionPolicy::LeastFrequentlyUsed,
ModelEvictionPolicy::SizeBasedEviction,
ModelEvictionPolicy::PriorityBasedEviction,
ModelEvictionPolicy::AdaptiveEviction,
];
for p in &policies {
assert!(!format!("{:?}", p).is_empty());
}
}
#[test]
fn test_thermal_level_ordering() {
assert!(ThermalLevel::Normal < ThermalLevel::Light);
assert!(ThermalLevel::Light < ThermalLevel::Moderate);
assert!(ThermalLevel::Moderate < ThermalLevel::Heavy);
assert!(ThermalLevel::Heavy < ThermalLevel::Emergency);
}
#[test]
fn test_performance_scaling_strategy_variants() {
let strats = [
PerformanceScalingStrategy::Linear,
PerformanceScalingStrategy::Exponential,
PerformanceScalingStrategy::Adaptive,
PerformanceScalingStrategy::UserDefined,
];
for s in &strats {
assert!(!format!("{:?}", s).is_empty());
}
}
#[test]
fn test_task_type_variants() {
let types = [
TaskType::ModelUpdate,
TaskType::FederatedLearning,
TaskType::DataSync,
TaskType::CacheCleanup,
TaskType::Analytics,
TaskType::Backup,
TaskType::Precomputation,
TaskType::HealthCheck,
];
for t in &types {
assert!(!format!("{:?}", t).is_empty());
}
}
#[test]
fn test_task_priority_ordering() {
assert!(TaskPriority::Low < TaskPriority::Normal);
assert!(TaskPriority::Normal < TaskPriority::High);
assert!(TaskPriority::High < TaskPriority::Critical);
assert!(TaskPriority::Critical < TaskPriority::Emergency);
}
#[test]
fn test_scheduling_strategy_variants() {
let strats = [
SchedulingStrategy::Immediate,
SchedulingStrategy::Deferred,
SchedulingStrategy::OpportunisticAgg,
SchedulingStrategy::UserIdle,
SchedulingStrategy::NetworkOptimal,
SchedulingStrategy::BatteryOptimal,
SchedulingStrategy::ThermalOptimal,
];
for s in &strats {
assert!(!format!("{:?}", s).is_empty());
}
}
#[test]
fn test_notification_type_variants() {
let types = [
NotificationType::ModelUpdateAvailable,
NotificationType::FederatedLearningTask,
NotificationType::SystemAlert,
NotificationType::PerformanceWarning,
NotificationType::MaintenanceRequired,
NotificationType::UserAction,
];
for t in &types {
assert!(!format!("{:?}", t).is_empty());
}
}
#[test]
fn test_delivery_strategy_variants() {
let strats = [
DeliveryStrategy::Immediate,
DeliveryStrategy::Batched,
DeliveryStrategy::Deferred,
DeliveryStrategy::OnForeground,
DeliveryStrategy::UserTriggered,
];
for s in &strats {
assert!(!format!("{:?}", s).is_empty());
}
}
#[test]
fn test_memory_warning_response_variants() {
let responses = [
MemoryWarningResponse::ClearCaches,
MemoryWarningResponse::ReduceBatchSizes,
MemoryWarningResponse::OffloadModels,
MemoryWarningResponse::PauseBackgroundTasks,
MemoryWarningResponse::NotifyUser,
MemoryWarningResponse::ForceGarbageCollection,
];
for r in &responses {
assert!(!format!("{:?}", r).is_empty());
}
}
#[test]
fn test_thermal_warning_response_variants() {
let responses = [
ThermalWarningResponse::ReduceInferenceFrequency,
ThermalWarningResponse::LowerModelPrecision,
ThermalWarningResponse::PauseComputeIntensiveTasks,
ThermalWarningResponse::SwitchToCpuOnly,
ThermalWarningResponse::NotifyUser,
ThermalWarningResponse::EnterCooldownMode,
];
for r in &responses {
assert!(!format!("{:?}", r).is_empty());
}
}
#[test]
fn test_reconnection_backoff_strategy_variants() {
let strats = [
ReconnectionBackoffStrategy::Linear,
ReconnectionBackoffStrategy::Exponential,
ReconnectionBackoffStrategy::Fibonacci,
ReconnectionBackoffStrategy::Custom,
];
for s in &strats {
assert!(!format!("{:?}", s).is_empty());
}
}
#[test]
fn test_background_resource_limits_default() {
let limits = BackgroundResourceLimits::default();
assert!(limits.max_cpu_percent > 0);
assert!(limits.max_memory_mb > 0);
assert!(limits.max_network_mbps > 0.0);
assert!(limits.max_execution_time_seconds > 0);
}
#[test]
fn test_foreground_resource_allocation_default() {
let alloc = ForegroundResourceAllocation::default();
assert!(alloc.cpu_allocation_percent > 0);
assert!(alloc.memory_allocation_mb > 0);
assert!(alloc.gpu_allocation_percent.is_some());
}
#[test]
fn test_offline_mode_config_default() {
let cfg = OfflineModeConfig::default();
assert!(cfg.enable_offline_mode);
assert!(cfg.local_model_fallback);
assert!(cfg.max_offline_cache_mb > 0);
}
#[test]
fn test_network_interruption_config_default() {
let cfg = NetworkInterruptionConfig::default();
assert!(cfg.enable_handling);
assert!(cfg.automatic_reconnection);
assert!(cfg.max_reconnection_attempts > 0);
}
#[test]
fn test_memory_warning_config_default() {
let cfg = MemoryWarningConfig::default();
assert!(cfg.enable_handling);
assert!(cfg.automatic_cleanup);
assert!(!cfg.response_strategies.is_empty());
}
#[test]
fn test_notification_throttling_default() {
let throttle = NotificationThrottling::default();
assert!(throttle.enable_throttling);
assert!(throttle.max_per_hour > 0);
assert!(throttle.min_interval_seconds > 0);
}
#[test]
fn test_background_task_config_default() {
let cfg = BackgroundTaskConfig::default();
assert!(cfg.enable_model_updates);
assert!(cfg.max_concurrent_tasks > 0);
assert!(cfg.task_priorities.contains_key(&TaskType::HealthCheck));
assert_eq!(
cfg.task_priorities.get(&TaskType::HealthCheck).copied(),
Some(TaskPriority::High)
);
}
#[test]
fn test_memory_pressure_thresholds_ordering() {
let cfg = LifecycleConfig::default();
let thresholds = &cfg.resource_management.memory_pressure_response.pressure_thresholds;
assert!(thresholds.warning_percent < thresholds.critical_percent);
assert!(thresholds.critical_percent < thresholds.emergency_percent);
}
}