Skip to content

Commit

Permalink
run tests on miri on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocodutra committed Feb 16, 2022
1 parent b568c37 commit c0aa14b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 36 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -113,6 +113,29 @@ jobs:
command: test
args: --no-default-features --features futures_api

miri:
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
with:
override: true
profile: minimal
toolchain: nightly
components: miri, rust-src
- uses: actions-rs/cargo@v1
with:
command: miri
args: setup
- uses: actions-rs/cargo@v1
with:
command: miri
args: test --all-features
env:
MIRIFLAGS: "-Zmiri-disable-isolation"
PROPTEST_CASES: 1

sanitize:
needs: [test]
runs-on: ubuntu-latest
Expand Down
13 changes: 7 additions & 6 deletions src/buffer.rs
Expand Up @@ -94,15 +94,15 @@ mod tests {
}

#[proptest]
fn capacity_returns_the_maximum_buffer_size(#[strategy(1..=100usize)] capacity: usize) {
fn capacity_returns_the_maximum_buffer_size(#[strategy(1..=10usize)] capacity: usize) {
let buffer = RingBuffer::<()>::new(capacity);
assert_eq!(buffer.capacity(), capacity);
}

#[proptest]
fn oldest_items_are_overwritten_on_overflow(
#[any(size_range(1..=100).lift())] items: Vec<char>,
#[strategy(1..=100usize)] capacity: usize,
#[any(size_range(1..=10).lift())] items: Vec<char>,
#[strategy(1..=10usize)] capacity: usize,
) {
let buffer = RingBuffer::new(capacity);

Expand All @@ -119,11 +119,12 @@ mod tests {
}
}

#[cfg(not(miri))] // https://github.com/rust-lang/miri/issues/1388
#[proptest]
fn buffer_is_thread_safe(
#[strategy(1..=100usize)] m: usize,
#[strategy(1..=100usize)] n: usize,
#[strategy(1..=100usize)] capacity: usize,
#[strategy(1..=10usize)] m: usize,
#[strategy(1..=10usize)] n: usize,
#[strategy(1..=10usize)] capacity: usize,
) {
let rt = runtime::Builder::new_multi_thread().build()?;
let buffer = Arc::new(RingBuffer::new(capacity));
Expand Down
60 changes: 35 additions & 25 deletions src/channel.rs
Expand Up @@ -363,8 +363,8 @@ mod tests {

#[proptest]
fn send_succeeds_on_connected_channel(
#[strategy(1..=100usize)] capacity: usize,
#[any(((1..=100).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
#[strategy(1..=10usize)] capacity: usize,
#[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
) {
let rt = runtime::Builder::new_multi_thread().build()?;
let (tx, _rx) = ring_channel(NonZeroUsize::try_from(capacity)?);
Expand All @@ -377,8 +377,8 @@ mod tests {

#[proptest]
fn send_fails_on_disconnected_channel(
#[strategy(1..=100usize)] capacity: usize,
#[any(((1..=100).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
#[strategy(1..=10usize)] capacity: usize,
#[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
) {
let rt = runtime::Builder::new_multi_thread().build()?;
let (tx, _) = ring_channel(NonZeroUsize::try_from(capacity)?);
Expand All @@ -393,8 +393,8 @@ mod tests {

#[proptest]
fn send_overwrites_old_messages(
#[strategy(1..=100usize)] capacity: usize,
#[any(((1..=100).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
#[strategy(1..=10usize)] capacity: usize,
#[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
) {
let rt = runtime::Builder::new_multi_thread().build()?;
let (tx, rx) = ring_channel(NonZeroUsize::try_from(capacity)?);
Expand All @@ -413,7 +413,7 @@ mod tests {

#[proptest]
fn try_recv_succeeds_on_non_empty_connected_channel(
#[any(((1..=100).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
#[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
) {
let rt = runtime::Builder::new_multi_thread().build()?;
let (tx, rx) = ring_channel(NonZeroUsize::try_from(msgs.len())?);
Expand All @@ -436,7 +436,7 @@ mod tests {

#[proptest]
fn try_recv_succeeds_on_non_empty_disconnected_channel(
#[any(((1..=100).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
#[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
) {
let rt = runtime::Builder::new_multi_thread().build()?;
let (_, rx) = ring_channel(NonZeroUsize::try_from(msgs.len())?);
Expand All @@ -459,8 +459,8 @@ mod tests {

#[proptest]
fn try_recv_fails_on_empty_connected_channel(
#[strategy(1..=100usize)] capacity: usize,
#[strategy(1..=100usize)] n: usize,
#[strategy(1..=10usize)] capacity: usize,
#[strategy(1..=10usize)] n: usize,
) {
let rt = runtime::Builder::new_multi_thread().build()?;
let (_tx, rx) = ring_channel::<()>(NonZeroUsize::try_from(capacity)?);
Expand All @@ -477,8 +477,8 @@ mod tests {

#[proptest]
fn try_recv_fails_on_empty_disconnected_channel(
#[strategy(1..=100usize)] capacity: usize,
#[strategy(1..=100usize)] n: usize,
#[strategy(1..=10usize)] capacity: usize,
#[strategy(1..=10usize)] n: usize,
) {
let rt = runtime::Builder::new_multi_thread().build()?;
let (_, rx) = ring_channel::<()>(NonZeroUsize::try_from(capacity)?);
Expand All @@ -498,7 +498,7 @@ mod tests {
#[cfg(feature = "futures_api")]
#[proptest]
fn recv_succeeds_on_non_empty_connected_channel(
#[any(((1..=100).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
#[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
) {
let rt = runtime::Builder::new_multi_thread().build()?;
let (tx, rx) = ring_channel(NonZeroUsize::try_from(msgs.len())?);
Expand All @@ -522,7 +522,7 @@ mod tests {
#[cfg(feature = "futures_api")]
#[proptest]
fn recv_succeeds_on_non_empty_disconnected_channel(
#[any(((1..=100).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
#[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
) {
let rt = runtime::Builder::new_multi_thread().build()?;
let (_, rx) = ring_channel(NonZeroUsize::try_from(msgs.len())?);
Expand All @@ -546,8 +546,8 @@ mod tests {
#[cfg(feature = "futures_api")]
#[proptest]
fn recv_fails_on_empty_disconnected_channel(
#[strategy(1..=100usize)] capacity: usize,
#[strategy(1..=100usize)] n: usize,
#[strategy(1..=10usize)] capacity: usize,
#[strategy(1..=10usize)] n: usize,
) {
let rt = runtime::Builder::new_multi_thread().build()?;
let (_, rx) = ring_channel::<()>(NonZeroUsize::try_from(capacity)?);
Expand All @@ -563,14 +563,18 @@ mod tests {
}

#[cfg(feature = "futures_api")]
#[cfg(not(miri))] // https://github.com/rust-lang/miri/issues/1388
#[proptest]
fn recv_wakes_on_disconnect(#[strategy(1..=100usize)] n: usize) {
fn recv_wakes_on_disconnect(
#[strategy(1..=10usize)] m: usize,
#[strategy(1..=10usize)] n: usize,
) {
let rt = runtime::Builder::new_multi_thread().build()?;
let (tx, rx) = ring_channel::<()>(NonZeroUsize::try_from(1)?);

rt.block_on(try_join(
repeat(rx)
.take(n)
.take(m)
.map(Ok)
.try_for_each_concurrent(None, |mut rx| {
spawn_blocking(move || assert_eq!(rx.recv(), Err(RecvError::Disconnected)))
Expand All @@ -583,8 +587,9 @@ mod tests {
}

#[cfg(feature = "futures_api")]
#[cfg(not(miri))] // https://github.com/rust-lang/miri/issues/1388
#[proptest]
fn recv_wakes_on_send(#[strategy(1..=100usize)] n: usize) {
fn recv_wakes_on_send(#[strategy(1..=10usize)] n: usize) {
let rt = runtime::Builder::new_multi_thread().build()?;
let (tx, rx) = ring_channel(NonZeroUsize::try_from(n)?);
let _prevent_disconnection = tx.clone();
Expand All @@ -608,8 +613,8 @@ mod tests {
#[cfg(feature = "futures_api")]
#[proptest]
fn sink(
#[strategy(1..=100usize)] capacity: usize,
#[any(((1..=100).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
#[strategy(1..=10usize)] capacity: usize,
#[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
) {
let rt = runtime::Builder::new_multi_thread().build()?;
let (mut tx, mut rx) = ring_channel(NonZeroUsize::try_from(capacity)?);
Expand All @@ -628,8 +633,8 @@ mod tests {
#[cfg(feature = "futures_api")]
#[proptest]
fn stream(
#[strategy(1..=100usize)] capacity: usize,
#[any(((1..=100).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
#[strategy(1..=10usize)] capacity: usize,
#[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec<String>,
) {
let rt = runtime::Builder::new_multi_thread().build()?;
let (tx, rx) = ring_channel(NonZeroUsize::try_from(capacity)?);
Expand All @@ -649,14 +654,18 @@ mod tests {
}

#[cfg(feature = "futures_api")]
#[cfg(not(miri))] // https://github.com/rust-lang/miri/issues/1388
#[proptest]
fn stream_wakes_on_disconnect(#[strategy(1..=100usize)] n: usize) {
fn stream_wakes_on_disconnect(
#[strategy(1..=10usize)] m: usize,
#[strategy(1..=10usize)] n: usize,
) {
let rt = runtime::Builder::new_multi_thread().build()?;
let (tx, rx) = ring_channel::<()>(NonZeroUsize::try_from(1)?);

rt.block_on(try_join(
repeat(rx)
.take(n)
.take(m)
.map(Ok)
.try_for_each_concurrent(None, |mut rx| {
spawn(async move { assert_eq!(rx.next().await, None) })
Expand All @@ -671,6 +680,7 @@ mod tests {
}

#[cfg(feature = "futures_api")]
#[cfg(not(miri))] // https://github.com/rust-lang/miri/issues/1388
#[proptest]
fn stream_wakes_on_sink(#[strategy(1..=100usize)] n: usize) {
let rt = runtime::Builder::new_multi_thread().build()?;
Expand Down
2 changes: 1 addition & 1 deletion src/control.rs
Expand Up @@ -89,7 +89,7 @@ mod tests {
}

#[proptest]
fn control_block_allocates_buffer_given_capacity(#[strategy(1..=100usize)] capacity: usize) {
fn control_block_allocates_buffer_given_capacity(#[strategy(1..=10usize)] capacity: usize) {
let ctrl = ControlBlock::<()>::new(capacity);
assert_eq!(ctrl.buffer.capacity(), capacity);
}
Expand Down
9 changes: 5 additions & 4 deletions src/waitlist.rs
Expand Up @@ -72,7 +72,7 @@ mod tests {

#[proptest]
fn push_inserts_item_at_the_back_of_the_queue(
#[any(size_range(1..=100).lift())] items: Vec<char>,
#[any(size_range(1..=10).lift())] items: Vec<char>,
) {
let waitlist = Waitlist::new();

Expand All @@ -86,7 +86,7 @@ mod tests {

#[proptest]
fn drain_removes_items_from_the_queue_in_fifo_order(
#[any(size_range(1..=100).lift())] items: Vec<char>,
#[any(size_range(1..=10).lift())] items: Vec<char>,
) {
let waitlist = Waitlist::new();

Expand All @@ -99,10 +99,11 @@ mod tests {
assert_eq!(waitlist.queue.len(), 0);
}

#[cfg(not(miri))] // https://github.com/rust-lang/miri/issues/1388
#[proptest]
fn waitlist_is_thread_safe(
#[strategy(1..=100usize)] m: usize,
#[strategy(1..=100usize)] n: usize,
#[strategy(1..=10usize)] m: usize,
#[strategy(1..=10usize)] n: usize,
) {
let rt = runtime::Builder::new_multi_thread().build()?;
let waitlist = Arc::new(Waitlist::new());
Expand Down

0 comments on commit c0aa14b

Please sign in to comment.