Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,6 @@ mod tests {
assert!(matches!(err, ConfigError::SerdeJson(_)));
}

/// Test that pretty-printed default JSON includes engine, poll
/// interval, and engine config path.
#[test]
fn dump_default_config_contains_engine() {
let dumped = dump_default_config();
assert!(dumped.contains(r#""engine": "threshold""#));
assert!(dumped.contains(r#""scale_poll_secs": 10.0"#));
assert!(dumped.contains(r#""/etc/io-thread-controller.d/engines""#));
}

/// Test that serde defaults for min/max threads, host CPU ceiling,
/// and cooldown match `Config::default()`.
#[test]
Expand Down
24 changes: 0 additions & 24 deletions src/engines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,30 +247,6 @@ pub fn load_registered_engine(
mod tests {
use super::*;

/// Test that `ScaleAction::target`/`Display` cover None/Up/Down
/// variants.
#[test]
fn scale_action_target_and_display() {
assert_eq!(ScaleAction::None.target(), None);
assert_eq!(ScaleAction::Up(4).target(), Some(4));
assert_eq!(ScaleAction::Down(2).target(), Some(2));
assert_eq!(ScaleAction::Revert(3).target(), Some(3));

assert_eq!(ScaleAction::None.to_string(), "none");
assert_eq!(ScaleAction::Up(1).to_string(), "up");
assert_eq!(ScaleAction::Down(1).to_string(), "down");
assert_eq!(ScaleAction::Revert(1).to_string(), "revert");
}

/// Test that `InstanceDecision::new` stores the VM id and
/// `ScaleAction` unchanged.
#[test]
fn instance_decision_new_preserves_fields() {
let decision = InstanceDecision::new("vm-1", ScaleAction::Up(5));
assert_eq!(decision.instance_id, "vm-1");
assert_eq!(decision.decision, ScaleAction::Up(5));
}

/// Test that registry loads the threshold engine by name and errors
/// on unknown engines.
#[test]
Expand Down
22 changes: 0 additions & 22 deletions src/engines/threshold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,26 +765,4 @@ mod tests {
ScaleAction::Revert(4)
);
}

/// Test that a missing `threshold.json` still builds an engine with
/// defaults.
#[test]
fn missing_config_file_uses_defaults() {
let dir = tempfile::tempdir().unwrap();
let engine =
ThresholdEngine::from_config_dir(&Path::new(dir.path().to_str().unwrap())).unwrap();
assert_eq!(engine.name(), super::ENGINE_NAME);
let _ = engine.config();
}

/// Test that CPU utilisation below scale-up/down thresholds yields
/// Hold/`None`.
#[rstest]
#[tokio::test]
async fn evaluate_holds_when_util_below_thresholds(#[future] instance: Arc<Instance>) {
let instance = instance.await;
let engine = ThresholdEngine::new(ThresholdConfig::default());
let action = engine.evaluate(&instance, &context()).await;
assert_eq!(action, ScaleAction::None);
}
}
12 changes: 0 additions & 12 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,18 +662,6 @@ mod tests {
assert!(closed.load(Ordering::Relaxed));
}

/// Test that `Display` for an instance prints the bare VM id.
#[test]
fn display_trims_instance_id() {
let instance = Instance::new(
" vm-1 ".to_string(),
Path::new(""),
1,
SnapshotClient { threads: 1 },
);
assert_eq!(instance.to_string(), "vm-1");
}

use super::{TaskCpuSample, compute_per_worker_util};

fn task(tid: i32, name: &str, cpu_ticks: u64) -> TaskCpuSample {
Expand Down
27 changes: 0 additions & 27 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,30 +141,3 @@ macro_rules! path {
}
};
}

#[cfg(test)]
mod tests {
use super::*;

/// Test that relative `Path` values are stored unchanged.
#[test]
fn relative_paths_are_unchanged() {
let path = Path::new("relative/sock");
assert_eq!(path.as_os_str(), OsStr::new("relative/sock"));
}

/// Test that absolute `Path` values stay absolute under the default
/// root.
#[test]
fn absolute_paths_keep_absolute_form_under_default_root() {
let path = Path::new("/var/run/example.sock");
assert_eq!(path.as_os_str(), OsStr::new("/var/run/example.sock"));
}

/// Test that `FromStr` builds a `Path` from a string.
#[test]
fn from_str_builds_path() {
let path: Path = "tmp/example".parse().unwrap();
assert_eq!(path.as_os_str(), OsStr::new("tmp/example"));
}
}
Loading