From c0aa14b682def38a5d796c9f868b131e93024a3e Mon Sep 17 00:00:00 2001 From: Bruno Dutra Date: Sun, 13 Feb 2022 20:41:16 +0100 Subject: [PATCH] run tests on miri on CI --- .github/workflows/ci.yml | 23 +++++++++++++++ src/buffer.rs | 13 +++++---- src/channel.rs | 60 +++++++++++++++++++++++----------------- src/control.rs | 2 +- src/waitlist.rs | 9 +++--- 5 files changed, 71 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a392ca..9c0be40 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/src/buffer.rs b/src/buffer.rs index 76e8547..5e48bbd 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -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, - #[strategy(1..=100usize)] capacity: usize, + #[any(size_range(1..=10).lift())] items: Vec, + #[strategy(1..=10usize)] capacity: usize, ) { let buffer = RingBuffer::new(capacity); @@ -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)); diff --git a/src/channel.rs b/src/channel.rs index 26ad442..229c3cc 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -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, + #[strategy(1..=10usize)] capacity: usize, + #[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec, ) { let rt = runtime::Builder::new_multi_thread().build()?; let (tx, _rx) = ring_channel(NonZeroUsize::try_from(capacity)?); @@ -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, + #[strategy(1..=10usize)] capacity: usize, + #[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec, ) { let rt = runtime::Builder::new_multi_thread().build()?; let (tx, _) = ring_channel(NonZeroUsize::try_from(capacity)?); @@ -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, + #[strategy(1..=10usize)] capacity: usize, + #[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec, ) { let rt = runtime::Builder::new_multi_thread().build()?; let (tx, rx) = ring_channel(NonZeroUsize::try_from(capacity)?); @@ -413,7 +413,7 @@ mod tests { #[proptest] fn try_recv_succeeds_on_non_empty_connected_channel( - #[any(((1..=100).into(), "[[:ascii:]]".into()))] msgs: Vec, + #[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec, ) { let rt = runtime::Builder::new_multi_thread().build()?; let (tx, rx) = ring_channel(NonZeroUsize::try_from(msgs.len())?); @@ -436,7 +436,7 @@ mod tests { #[proptest] fn try_recv_succeeds_on_non_empty_disconnected_channel( - #[any(((1..=100).into(), "[[:ascii:]]".into()))] msgs: Vec, + #[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec, ) { let rt = runtime::Builder::new_multi_thread().build()?; let (_, rx) = ring_channel(NonZeroUsize::try_from(msgs.len())?); @@ -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)?); @@ -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)?); @@ -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, + #[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec, ) { let rt = runtime::Builder::new_multi_thread().build()?; let (tx, rx) = ring_channel(NonZeroUsize::try_from(msgs.len())?); @@ -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, + #[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec, ) { let rt = runtime::Builder::new_multi_thread().build()?; let (_, rx) = ring_channel(NonZeroUsize::try_from(msgs.len())?); @@ -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)?); @@ -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))) @@ -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(); @@ -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, + #[strategy(1..=10usize)] capacity: usize, + #[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec, ) { let rt = runtime::Builder::new_multi_thread().build()?; let (mut tx, mut rx) = ring_channel(NonZeroUsize::try_from(capacity)?); @@ -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, + #[strategy(1..=10usize)] capacity: usize, + #[any(((1..=10).into(), "[[:ascii:]]".into()))] msgs: Vec, ) { let rt = runtime::Builder::new_multi_thread().build()?; let (tx, rx) = ring_channel(NonZeroUsize::try_from(capacity)?); @@ -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) }) @@ -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()?; diff --git a/src/control.rs b/src/control.rs index e183d6f..2345016 100644 --- a/src/control.rs +++ b/src/control.rs @@ -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); } diff --git a/src/waitlist.rs b/src/waitlist.rs index 626f654..c3314cb 100644 --- a/src/waitlist.rs +++ b/src/waitlist.rs @@ -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, + #[any(size_range(1..=10).lift())] items: Vec, ) { let waitlist = Waitlist::new(); @@ -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, + #[any(size_range(1..=10).lift())] items: Vec, ) { let waitlist = Waitlist::new(); @@ -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());