-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use bolero-generator for rand backend
- Loading branch information
Showing
17 changed files
with
289 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "bach-tests" | ||
version = "0.0.0" | ||
edition = "2021" | ||
license = "MIT" | ||
publish = false | ||
|
||
[dependencies] | ||
mimalloc = { version = "0.1", default-features = false } | ||
|
||
[dev-dependencies] | ||
bach = { path = "../bach", features = ["coop"] } | ||
bolero.workspace = true | ||
insta = "1" | ||
tracing = "0.1" | ||
tracing-subscriber = { version = "0.3", features = ["env-filter"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::sync::Mutex; | ||
|
||
use bach::{environment::default::Runtime, ext::*, sync::queue::vec_deque::Queue}; | ||
|
||
fn sim(f: impl Fn()) -> impl Fn() { | ||
crate::testing::init_tracing(); | ||
move || { | ||
let mut rt = Runtime::new().with_coop(true).with_rand(None); | ||
rt.run(&f); | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
#[allow(dead_code)] | ||
enum Event { | ||
Start, | ||
Message { group: u8, actor: u8 }, | ||
} | ||
|
||
#[test] | ||
fn interleavings() { | ||
static LOG: Mutex<Vec<Event>> = Mutex::new(vec![]); | ||
|
||
bolero::check!().exhaustive().run(sim(|| { | ||
LOG.lock().unwrap().push(Event::Start); | ||
|
||
for group in 0..2 { | ||
let (sender, receiver) = Queue::builder().with_capacity(Some(20)).build().channel(); | ||
|
||
async move { | ||
while let Ok(actor) = receiver.pop().await { | ||
LOG.lock().unwrap().push(Event::Message { group, actor }); | ||
} | ||
} | ||
.primary() | ||
.spawn_named(format!("[{group}] server")); | ||
|
||
for id in 0..2 { | ||
let sender = sender.clone(); | ||
async move { | ||
for _ in 0..1 { | ||
sender.push(id).await.unwrap(); | ||
} | ||
} | ||
.primary() | ||
.spawn_named(format!("[{group}] client{id}")); | ||
} | ||
} | ||
})); | ||
|
||
insta::assert_debug_snapshot!(LOG.lock().unwrap()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#[global_allocator] | ||
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; | ||
|
||
#[cfg(test)] | ||
mod coop; | ||
#[cfg(test)] | ||
mod queue; | ||
#[cfg(test)] | ||
mod testing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use crate::{ | ||
use bach::{ | ||
environment::default::Runtime, | ||
ext::*, | ||
sync::{duplex::Duplex, queue::vec_deque}, | ||
|
40 changes: 40 additions & 0 deletions
40
bach-tests/src/snapshots/bach_tests__coop__interleavings.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
source: bach-tests/src/coop.rs | ||
expression: LOG.lock().unwrap() | ||
--- | ||
[ | ||
Start, | ||
Message { | ||
group: 0, | ||
actor: 0, | ||
}, | ||
Message { | ||
group: 1, | ||
actor: 0, | ||
}, | ||
Message { | ||
group: 0, | ||
actor: 1, | ||
}, | ||
Message { | ||
group: 1, | ||
actor: 1, | ||
}, | ||
Start, | ||
Message { | ||
group: 0, | ||
actor: 1, | ||
}, | ||
Message { | ||
group: 1, | ||
actor: 1, | ||
}, | ||
Message { | ||
group: 0, | ||
actor: 0, | ||
}, | ||
Message { | ||
group: 1, | ||
actor: 0, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.