Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proptests for children #91

Merged
merged 2 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions bastion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ lazy_static = "1.4"
lightproc = { version = "= 0.3.3-alpha.1", path = "../lightproc" }
qutex = { version = "0.2", features = ["async_await"] }
uuid = { version = "0.8", features = ["v4"] }

[dev-dependencies]
proptest = "0.9"
41 changes: 41 additions & 0 deletions bastion/tests/prop_children_broadcast.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use bastion::prelude::*;
use proptest::prelude::*;

use std::sync::Once;

static START: Once = Once::new();

proptest! {
#![proptest_config(ProptestConfig::with_cases(1_000))]
#[test]
fn proptest_bcast_message(message in "\\PC*") {
START.call_once(|| {
Bastion::init();
});
Bastion::start();

match Bastion::children(|children: Children| {
children
.with_exec(move |ctx: BastionContext| {
async move {
msg! { ctx.recv().await?,
ref msg: &'static str => {
;
};
// This won't happen because this example
// only "asks" a `&'static str`...
_: _ => ();
}

Ok(())
}
})
}) {
Ok(_chrn) => {
let message: &'static str = Box::leak(message.into_boxed_str());
Bastion::broadcast(message).expect("broadcast failed");
},
_ => (),
}
}
}
52 changes: 52 additions & 0 deletions bastion/tests/prop_children_message.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use bastion::prelude::*;
use proptest::prelude::*;
use std::sync::Arc;
use std::sync::Once;

static START: Once = Once::new();

proptest! {
#![proptest_config(ProptestConfig::with_cases(1_000))]
#[test]
fn proptest_intra_message(message in "\\PC*") {
START.call_once(|| {
Bastion::init();
});
Bastion::start();

let message = Arc::new(message);

match Bastion::children(|children| {
children
.with_exec(move |ctx: BastionContext| {
let message = (*message).clone();
async move {
let message: &'static str = Box::leak(message.into_boxed_str());
let answer = ctx
.current()
.ask(message)
.expect("Couldn't send the message.");

msg! { ctx.recv().await?,
msg: &'static str =!> {
let _ = answer!(msg);
};
_: _ => ();
}

msg! { answer.await?,
msg: &'static str => {
;
};
_: _ => ();
}

Ok(())
}
})
}) {
Ok(_) => (),
_ => (),
}
}
}
19 changes: 19 additions & 0 deletions bastion/tests/prop_children_redundancy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use bastion::prelude::*;
use proptest::prelude::*;

proptest! {
#[test]
fn proptest_redundancy(r in std::usize::MIN..std::usize::MAX) {
Bastion::children(|children| {
children
// shrink over the redundancy
.with_redundancy(r)
.with_exec(|_ctx: BastionContext| {
async move {
loop {}
Ok(())
}
})
});
}
}