Skip to content
Open
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
12 changes: 10 additions & 2 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ fn cargo(project: &Project) -> Command {

pub fn build_dependencies(project: &Project) -> Result<()> {
let status = cargo(project)
.arg(if project.has_run_at_least { "build" } else { "check" })
.arg(if project.has_run_at_least {
"build"
} else {
"check"
})
.arg("--bin")
.arg(&project.name)
.status()
Expand All @@ -55,7 +59,11 @@ pub fn build_test(project: &Project, name: &Name) -> Result<Output> {
.status();

cargo(project)
.arg(if project.has_run_at_least { "build" } else { "check" })
.arg(if project.has_run_at_least {
"build"
} else {
"check"
})
.arg("--bin")
.arg(name)
.args(features(project))
Expand Down
9 changes: 2 additions & 7 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum Error {
TomlSer(toml::ser::Error),
UpdateVar(OsString),
WriteStderr(io::Error),
Shrink(proptest::test_runner::TestError<isize>)
Shrink(proptest::test_runner::TestError<isize>),
}

pub type Result<T> = std::result::Result<T, Error>;
Expand Down Expand Up @@ -53,11 +53,7 @@ impl Display for Error {
}
TomlDe(e) => write!(f, "{}", e),
TomlSer(e) => write!(f, "{}", e),
UpdateVar(var) => write!(
f,
"unrecognized value of KAOS: {:?}",
var.to_string_lossy(),
),
UpdateVar(var) => write!(f, "unrecognized value of KAOS: {:?}", var.to_string_lossy(),),
WriteStderr(e) => write!(f, "failed to write stderr file: {}", e),
Shrink(e) => write!(f, "test failed with a randomization: {}", e),
}
Expand Down Expand Up @@ -105,7 +101,6 @@ impl From<toml::ser::Error> for Error {
}
}


impl From<proptest::test_runner::TestError<isize>> for Error {
fn from(err: proptest::test_runner::TestError<isize>) -> Self {
Error::Shrink(err)
Expand Down
16 changes: 6 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

//! #### &emsp;Chaotic testing harness
//!
//! **Kaos** is a chaotic testing harness to test your services against random failures.
Expand Down Expand Up @@ -126,9 +125,7 @@
//! Instead of being compiler-like test harness, it has diverged to be chaos engineering
//! oriented harness.

#![doc(
html_logo_url = "https://raw.githubusercontent.com/vertexclique/kaos/master/img/chaos.png"
)]
#![doc(html_logo_url = "https://raw.githubusercontent.com/vertexclique/kaos/master/img/chaos.png")]

extern crate humantime;

Expand All @@ -144,25 +141,24 @@ mod diff;
mod env;
mod error;
mod features;
mod macros;
mod manifest;
mod message;
mod normalize;
mod run;
mod rustflags;
mod macros;

use std::cell::RefCell;
use std::path::{Path, PathBuf};
use std::{time::Duration, thread};
use std::{thread, time::Duration};

#[doc(hidden)]
pub use fail::eval as flunker;
#[doc(hidden)]
pub use fail::cfg as flunker_cfg;
#[doc(hidden)]
pub use fail::eval as flunker;
#[doc(hidden)]
pub use fail::FailScenario as KaosFailScenario;


pub use macros::*;

///
Expand All @@ -188,7 +184,7 @@ struct Test {
#[derive(Copy, Clone, Debug)]
enum Expected {
Available,
Chaotic
Chaotic,
}

impl Runs {
Expand Down
1 change: 0 additions & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ macro_rules! kaostest {
}};
}


#[cfg(test)]
mod macro_tests {
#[test]
Expand Down
7 changes: 5 additions & 2 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use crate::error::Error;
use crate::normalize;
use crate::term;

use humantime::format_duration;
use std::env;
use std::path::Path;
use std::process::Output;
use humantime::format_duration;

pub(crate) enum Level {
Fail,
Expand Down Expand Up @@ -72,7 +72,10 @@ pub(crate) fn begin_test(test: &Test, show_expected: bool) {

if show_expected {
match test.expected {
Expected::Available => print!(" [should survive at least {}]", format_duration(test.duration.unwrap()).to_string()),
Expected::Available => print!(
" [should survive at least {}]",
format_duration(test.duration.unwrap()).to_string()
),
Expected::Chaotic => print!(" [should survive from chaos]"),
}
}
Expand Down
27 changes: 13 additions & 14 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use std::collections::BTreeMap as Map;
use std::env;
use std::ffi::{OsStr, OsString};
use std::fs::{self, File};
use std::{time::{Instant, Duration}, path::{Path, PathBuf}};
use std::{
path::{Path, PathBuf},
time::{Duration, Instant},
};

use super::{Expected, Runner, Test};
use crate::cargo;
Expand All @@ -14,9 +17,9 @@ use crate::manifest::{Bin, Build, Config, Manifest, Name, Package, Workspace};
use crate::message::{self, Fail, Warn};
use crate::normalize::{self, Context, Variations};
use crate::rustflags;
use std::convert::TryInto;
use proptest::test_runner::{TestRunner, TestCaseError};
use humantime::format_duration;
use proptest::test_runner::{TestCaseError, TestRunner};
use std::convert::TryInto;

#[derive(Debug)]
pub struct Project {
Expand Down Expand Up @@ -83,11 +86,9 @@ impl Runner {
}
}

let surges: Vec<isize> =
tests.iter().map(|t| t.test.max_surge).collect();
let surges: Vec<isize> = tests.iter().map(|t| t.test.max_surge).collect();

let mut static_durations: Vec<Option<Duration>> =
vec![None; surges.len()];
let mut static_durations: Vec<Option<Duration>> = vec![None; surges.len()];

surges
.iter()
Expand Down Expand Up @@ -296,13 +297,11 @@ impl Test {
let res = check(self, project, name, success, stdout, stderr);
let elapsed = now.elapsed();
if elapsed < duration {
Err(Error::ChaosTestFailed(
format!(
"availability is low. Expected at least: {}, Found: {}",
format_duration(duration).to_string(),
format_duration(elapsed).to_string()
)
))
Err(Error::ChaosTestFailed(format!(
"availability is low. Expected at least: {}, Found: {}",
format_duration(duration).to_string(),
format_duration(elapsed).to_string()
)))
} else {
res
}
Expand Down