Skip to content

Commit 4c09638

Browse files
committed
Run more tests with Miri (#2624)
1 parent 11c386b commit 4c09638

File tree

11 files changed

+19
-52
lines changed

11 files changed

+19
-52
lines changed

futures-channel/tests/mpsc.rs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,7 @@ fn tx_close_gets_none() {
200200

201201
#[test]
202202
fn stress_shared_unbounded() {
203-
#[cfg(miri)]
204-
const AMT: u32 = 100;
205-
#[cfg(not(miri))]
206-
const AMT: u32 = 10000;
203+
const AMT: u32 = if cfg!(miri) { 100 } else { 10000 };
207204
const NTHREADS: u32 = 8;
208205
let (tx, rx) = mpsc::unbounded::<i32>();
209206

@@ -232,10 +229,7 @@ fn stress_shared_unbounded() {
232229

233230
#[test]
234231
fn stress_shared_bounded_hard() {
235-
#[cfg(miri)]
236-
const AMT: u32 = 100;
237-
#[cfg(not(miri))]
238-
const AMT: u32 = 10000;
232+
const AMT: u32 = if cfg!(miri) { 100 } else { 10000 };
239233
const NTHREADS: u32 = 8;
240234
let (tx, rx) = mpsc::channel::<i32>(0);
241235

@@ -265,10 +259,7 @@ fn stress_shared_bounded_hard() {
265259
#[allow(clippy::same_item_push)]
266260
#[test]
267261
fn stress_receiver_multi_task_bounded_hard() {
268-
#[cfg(miri)]
269-
const AMT: usize = 100;
270-
#[cfg(not(miri))]
271-
const AMT: usize = 10_000;
262+
const AMT: usize = if cfg!(miri) { 100 } else { 10_000 };
272263
const NTHREADS: u32 = 2;
273264

274265
let (mut tx, rx) = mpsc::channel::<usize>(0);
@@ -336,10 +327,7 @@ fn stress_receiver_multi_task_bounded_hard() {
336327
/// after sender dropped.
337328
#[test]
338329
fn stress_drop_sender() {
339-
#[cfg(miri)]
340-
const ITER: usize = 100;
341-
#[cfg(not(miri))]
342-
const ITER: usize = 10000;
330+
const ITER: usize = if cfg!(miri) { 100 } else { 10000 };
343331

344332
fn list() -> impl Stream<Item = i32> {
345333
let (tx, rx) = mpsc::channel(1);
@@ -394,10 +382,9 @@ fn stress_close_receiver_iter() {
394382
}
395383
}
396384

397-
#[cfg_attr(miri, ignore)] // Miri is too slow
398385
#[test]
399386
fn stress_close_receiver() {
400-
const ITER: usize = 10000;
387+
const ITER: usize = if cfg!(miri) { 50 } else { 10000 };
401388

402389
for _ in 0..ITER {
403390
stress_close_receiver_iter();
@@ -414,10 +401,7 @@ async fn stress_poll_ready_sender(mut sender: mpsc::Sender<u32>, count: u32) {
414401
#[allow(clippy::same_item_push)]
415402
#[test]
416403
fn stress_poll_ready() {
417-
#[cfg(miri)]
418-
const AMT: u32 = 100;
419-
#[cfg(not(miri))]
420-
const AMT: u32 = 1000;
404+
const AMT: u32 = if cfg!(miri) { 100 } else { 1000 };
421405
const NTHREADS: u32 = 8;
422406

423407
/// Run a stress test using the specified channel capacity.
@@ -444,10 +428,9 @@ fn stress_poll_ready() {
444428
stress(16);
445429
}
446430

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

453436
let t = thread::spawn(move || {

futures-channel/tests/oneshot.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ fn cancel_notifies() {
3535

3636
#[test]
3737
fn cancel_lots() {
38-
#[cfg(miri)]
39-
const N: usize = 100;
40-
#[cfg(not(miri))]
41-
const N: usize = 20000;
38+
const N: usize = if cfg!(miri) { 100 } else { 20000 };
4239

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

107104
#[test]
108105
fn cancel_sends() {
109-
#[cfg(miri)]
110-
const N: usize = 100;
111-
#[cfg(not(miri))]
112-
const N: usize = 20000;
106+
const N: usize = if cfg!(miri) { 100 } else { 20000 };
113107

114108
let (tx, rx) = mpsc::channel::<Sender<_>>();
115109
let t = thread::spawn(move || {

futures-executor/src/thread_pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl ThreadPool {
116116
/// let future = async { /* ... */ };
117117
/// pool.spawn_ok(future);
118118
/// # }
119-
/// # std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
119+
/// # std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371
120120
/// ```
121121
///
122122
/// > **Note**: This method is similar to `SpawnExt::spawn`, except that
@@ -375,6 +375,6 @@ mod tests {
375375
let count = rx.into_iter().count();
376376
assert_eq!(count, 2);
377377
}
378-
std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
378+
std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371
379379
}
380380
}

futures-executor/tests/local_pool.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,7 @@ fn run_until_stalled_runs_spawned_sub_futures() {
288288

289289
#[test]
290290
fn run_until_stalled_executes_all_ready() {
291-
#[cfg(miri)]
292-
const ITER: usize = 50;
293-
#[cfg(not(miri))]
294-
const ITER: usize = 200;
291+
const ITER: usize = if cfg!(miri) { 50 } else { 200 };
295292
const PER_ITER: usize = 3;
296293

297294
let cnt = Rc::new(Cell::new(0));

futures-test/src/future/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub trait FutureTestExt: Future {
6868
///
6969
/// assert_eq!(rx.await, Ok(5));
7070
/// # });
71-
/// # std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
71+
/// # std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371
7272
/// ```
7373
fn run_in_background(self)
7474
where

futures-util/src/task/spawn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub trait SpawnExt: Spawn {
4343
/// let future = async { /* ... */ };
4444
/// executor.spawn(future).unwrap();
4545
/// # }
46-
/// # std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
46+
/// # std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371
4747
/// ```
4848
#[cfg(feature = "alloc")]
4949
fn spawn<Fut>(&self, future: Fut) -> Result<(), SpawnError>
@@ -72,7 +72,7 @@ pub trait SpawnExt: Spawn {
7272
/// let join_handle_fut = executor.spawn_with_handle(future).unwrap();
7373
/// assert_eq!(block_on(join_handle_fut), 1);
7474
/// # }
75-
/// # std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
75+
/// # std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371
7676
/// ```
7777
#[cfg(feature = "channel")]
7878
#[cfg_attr(docsrs, doc(cfg(feature = "channel")))]

futures/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
//!
7575
//! println!("Values={:?}", values);
7676
//! # }
77-
//! # std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
77+
//! # std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371
7878
//! }
7979
//! ```
8080
//!

futures/tests/eventual.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,7 @@ fn select3() {
134134

135135
#[test]
136136
fn select4() {
137-
#[cfg(miri)]
138-
const N: usize = 100;
139-
#[cfg(not(miri))]
140-
const N: usize = 10000;
137+
const N: usize = if cfg!(miri) { 100 } else { 10000 };
141138

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

futures/tests/lock_mutex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ fn mutex_contested() {
6565
assert_eq!(num_tasks, *lock);
6666
});
6767
}
68-
std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
68+
std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371
6969
}

futures/tests/ready_queue.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ fn dropping_ready_queue() {
9393

9494
#[test]
9595
fn stress() {
96-
#[cfg(miri)]
97-
const ITER: usize = 30;
98-
#[cfg(not(miri))]
99-
const ITER: usize = 300;
96+
const ITER: usize = if cfg!(miri) { 30 } else { 300 };
10097

10198
for i in 0..ITER {
10299
let n = (i % 10) + 1;

0 commit comments

Comments
 (0)