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

Run more tests with Miri #2624

Merged
merged 1 commit into from
Jul 22, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 7 additions & 24 deletions futures-channel/tests/mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,7 @@ fn tx_close_gets_none() {

#[test]
fn stress_shared_unbounded() {
#[cfg(miri)]
const AMT: u32 = 100;
#[cfg(not(miri))]
const AMT: u32 = 10000;
const AMT: u32 = if cfg!(miri) { 100 } else { 10000 };
const NTHREADS: u32 = 8;
let (tx, rx) = mpsc::unbounded::<i32>();

Expand Down Expand Up @@ -232,10 +229,7 @@ fn stress_shared_unbounded() {

#[test]
fn stress_shared_bounded_hard() {
#[cfg(miri)]
const AMT: u32 = 100;
#[cfg(not(miri))]
const AMT: u32 = 10000;
const AMT: u32 = if cfg!(miri) { 100 } else { 10000 };
const NTHREADS: u32 = 8;
let (tx, rx) = mpsc::channel::<i32>(0);

Expand Down Expand Up @@ -264,10 +258,7 @@ fn stress_shared_bounded_hard() {

#[test]
fn stress_receiver_multi_task_bounded_hard() {
#[cfg(miri)]
const AMT: usize = 100;
#[cfg(not(miri))]
const AMT: usize = 10_000;
const AMT: usize = if cfg!(miri) { 100 } else { 10_000 };
const NTHREADS: u32 = 2;

let (mut tx, rx) = mpsc::channel::<usize>(0);
Expand Down Expand Up @@ -335,10 +326,7 @@ fn stress_receiver_multi_task_bounded_hard() {
/// after sender dropped.
#[test]
fn stress_drop_sender() {
#[cfg(miri)]
const ITER: usize = 100;
#[cfg(not(miri))]
const ITER: usize = 10000;
const ITER: usize = if cfg!(miri) { 100 } else { 10000 };

fn list() -> impl Stream<Item = i32> {
let (tx, rx) = mpsc::channel(1);
Expand Down Expand Up @@ -393,10 +381,9 @@ fn stress_close_receiver_iter() {
}
}

#[cfg_attr(miri, ignore)] // Miri is too slow
#[test]
fn stress_close_receiver() {
const ITER: usize = 10000;
const ITER: usize = if cfg!(miri) { 50 } else { 10000 };

for _ in 0..ITER {
stress_close_receiver_iter();
Expand All @@ -412,10 +399,7 @@ async fn stress_poll_ready_sender(mut sender: mpsc::Sender<u32>, count: u32) {
/// Tests that after `poll_ready` indicates capacity a channel can always send without waiting.
#[test]
fn stress_poll_ready() {
#[cfg(miri)]
const AMT: u32 = 100;
#[cfg(not(miri))]
const AMT: u32 = 1000;
const AMT: u32 = if cfg!(miri) { 100 } else { 1000 };
const NTHREADS: u32 = 8;

/// Run a stress test using the specified channel capacity.
Expand All @@ -442,10 +426,9 @@ fn stress_poll_ready() {
stress(16);
}

#[cfg_attr(miri, ignore)] // Miri is too slow
#[test]
fn try_send_1() {
const N: usize = 3000;
const N: usize = if cfg!(miri) { 100 } else { 3000 };
let (mut tx, rx) = mpsc::channel(0);

let t = thread::spawn(move || {
Expand Down
10 changes: 2 additions & 8 deletions futures-channel/tests/oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ fn cancel_notifies() {

#[test]
fn cancel_lots() {
#[cfg(miri)]
const N: usize = 100;
#[cfg(not(miri))]
const N: usize = 20000;
const N: usize = if cfg!(miri) { 100 } else { 20000 };

let (tx, rx) = mpsc::channel::<(Sender<_>, mpsc::Sender<_>)>();
let t = thread::spawn(move || {
Expand Down Expand Up @@ -106,10 +103,7 @@ fn is_canceled() {

#[test]
fn cancel_sends() {
#[cfg(miri)]
const N: usize = 100;
#[cfg(not(miri))]
const N: usize = 20000;
const N: usize = if cfg!(miri) { 100 } else { 20000 };

let (tx, rx) = mpsc::channel::<Sender<_>>();
let t = thread::spawn(move || {
Expand Down
4 changes: 2 additions & 2 deletions futures-executor/src/thread_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl ThreadPool {
/// let future = async { /* ... */ };
/// pool.spawn_ok(future);
/// # }
/// # std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
/// # std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371
/// ```
///
/// > **Note**: This method is similar to `SpawnExt::spawn`, except that
Expand Down Expand Up @@ -375,6 +375,6 @@ mod tests {
let count = rx.into_iter().count();
assert_eq!(count, 2);
}
std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371
}
}
5 changes: 1 addition & 4 deletions futures-executor/tests/local_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,7 @@ fn run_until_stalled_runs_spawned_sub_futures() {

#[test]
fn run_until_stalled_executes_all_ready() {
#[cfg(miri)]
const ITER: usize = 50;
#[cfg(not(miri))]
const ITER: usize = 200;
const ITER: usize = if cfg!(miri) { 50 } else { 200 };
const PER_ITER: usize = 3;

let cnt = Rc::new(Cell::new(0));
Expand Down
2 changes: 1 addition & 1 deletion futures-test/src/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub trait FutureTestExt: Future {
///
/// assert_eq!(rx.await, Ok(5));
/// # });
/// # std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
/// # std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371
/// ```
fn run_in_background(self)
where
Expand Down
4 changes: 2 additions & 2 deletions futures-util/src/task/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub trait SpawnExt: Spawn {
/// let future = async { /* ... */ };
/// executor.spawn(future).unwrap();
/// # }
/// # std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
/// # std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371
/// ```
#[cfg(feature = "alloc")]
fn spawn<Fut>(&self, future: Fut) -> Result<(), SpawnError>
Expand Down Expand Up @@ -72,7 +72,7 @@ pub trait SpawnExt: Spawn {
/// let join_handle_fut = executor.spawn_with_handle(future).unwrap();
/// assert_eq!(block_on(join_handle_fut), 1);
/// # }
/// # std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
/// # std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371
/// ```
#[cfg(feature = "channel")]
#[cfg_attr(docsrs, doc(cfg(feature = "channel")))]
Expand Down
2 changes: 1 addition & 1 deletion futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
//!
//! println!("Values={:?}", values);
//! # }
//! # std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
//! # std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371
//! }
//! ```
//!
Expand Down
5 changes: 1 addition & 4 deletions futures/tests/eventual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ fn select3() {

#[test]
fn select4() {
#[cfg(miri)]
const N: usize = 100;
#[cfg(not(miri))]
const N: usize = 10000;
const N: usize = if cfg!(miri) { 100 } else { 10000 };

let (tx, rx) = mpsc::channel::<oneshot::Sender<i32>>();

Expand Down
2 changes: 1 addition & 1 deletion futures/tests/lock_mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ fn mutex_contested() {
assert_eq!(num_tasks, *lock);
});
}
std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371
}
5 changes: 1 addition & 4 deletions futures/tests/ready_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ fn dropping_ready_queue() {

#[test]
fn stress() {
#[cfg(miri)]
const ITER: usize = 30;
#[cfg(not(miri))]
const ITER: usize = 300;
const ITER: usize = if cfg!(miri) { 30 } else { 300 };

for i in 0..ITER {
let n = (i % 10) + 1;
Expand Down
1 change: 0 additions & 1 deletion futures/tests/task_atomic_waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::thread;

#[cfg_attr(miri, ignore)] // Miri is too slow
#[test]
fn basic() {
let atomic_waker = Arc::new(AtomicWaker::new());
Expand Down