Skip to content

Commit a3bc6e8

Browse files
committed
Run more tests with Miri
1 parent 800fab0 commit a3bc6e8

File tree

15 files changed

+64
-55
lines changed

15 files changed

+64
-55
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ jobs:
273273
- uses: actions/checkout@v2
274274
- name: Install Rust
275275
run: rustup toolchain install nightly --component miri && rustup default nightly
276-
# futures-executor uses boxed futures so many tests trigger https://github.com/rust-lang/miri/issues/1038
277-
- run: cargo miri test --workspace --exclude futures-executor --all-features
276+
- run: cargo miri test --workspace --all-features --no-fail-fast
278277
env:
279278
MIRIFLAGS: -Zmiri-check-number-validity -Zmiri-symbolic-alignment-check -Zmiri-tag-raw-pointers -Zmiri-disable-isolation
279+
RUSTFLAGS: ${{ env.RUSTFLAGS }} -Z randomize-layout
280280

281281
san:
282282
name: cargo test -Z sanitizer=${{ matrix.sanitizer }}

futures-executor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ futures-util = { path = "../futures-util", version = "=0.4.0-alpha.0", default-f
2222
num_cpus = { version = "1.8.0", optional = true }
2323

2424
[dev-dependencies]
25-
futures = { path = "../futures" }
25+
futures = { path = "../futures", features = ["thread-pool"] }
2626

2727
[package.metadata.docs.rs]
2828
all-features = true

futures-executor/src/thread_pool.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,15 @@ impl ThreadPool {
108108
/// completion.
109109
///
110110
/// ```
111+
/// # {
111112
/// use futures::executor::ThreadPool;
112113
///
113114
/// let pool = ThreadPool::new().unwrap();
114115
///
115116
/// let future = async { /* ... */ };
116117
/// pool.spawn_ok(future);
118+
/// # }
119+
/// # std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
117120
/// ```
118121
///
119122
/// > **Note**: This method is similar to `SpawnExt::spawn`, except that
@@ -359,16 +362,19 @@ mod tests {
359362

360363
#[test]
361364
fn test_drop_after_start() {
362-
let (tx, rx) = mpsc::sync_channel(2);
363-
let _cpu_pool = ThreadPoolBuilder::new()
364-
.pool_size(2)
365-
.after_start(move |_| tx.send(1).unwrap())
366-
.create()
367-
.unwrap();
368-
369-
// After ThreadPoolBuilder is deconstructed, the tx should be dropped
370-
// so that we can use rx as an iterator.
371-
let count = rx.into_iter().count();
372-
assert_eq!(count, 2);
365+
{
366+
let (tx, rx) = mpsc::sync_channel(2);
367+
let _cpu_pool = ThreadPoolBuilder::new()
368+
.pool_size(2)
369+
.after_start(move |_| tx.send(1).unwrap())
370+
.create()
371+
.unwrap();
372+
373+
// After ThreadPoolBuilder is deconstructed, the tx should be dropped
374+
// so that we can use rx as an iterator.
375+
let count = rx.into_iter().count();
376+
assert_eq!(count, 2);
377+
}
378+
std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
373379
}
374380
}

futures-executor/tests/local_pool.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ 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))]
291294
const ITER: usize = 200;
292295
const PER_ITER: usize = 3;
293296

futures-util/src/task/spawn.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ pub trait SpawnExt: Spawn {
3434
/// today. Feel free to use this method in the meantime.
3535
///
3636
/// ```
37-
/// # if cfg!(miri) { return; } // https://github.com/rust-lang/miri/issues/1038
37+
/// # {
3838
/// use futures::executor::ThreadPool;
3939
/// use futures::task::SpawnExt;
4040
///
4141
/// let executor = ThreadPool::new().unwrap();
4242
///
4343
/// let future = async { /* ... */ };
4444
/// executor.spawn(future).unwrap();
45+
/// # }
46+
/// # std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
4547
/// ```
4648
#[cfg(feature = "alloc")]
4749
fn spawn<Fut>(&self, future: Fut) -> Result<(), SpawnError>
@@ -59,7 +61,7 @@ pub trait SpawnExt: Spawn {
5961
/// resolves to the output of the spawned future.
6062
///
6163
/// ```
62-
/// # if cfg!(miri) { return; } // https://github.com/rust-lang/miri/issues/1038
64+
/// # {
6365
/// use futures::executor::{block_on, ThreadPool};
6466
/// use futures::future;
6567
/// use futures::task::SpawnExt;
@@ -69,6 +71,8 @@ pub trait SpawnExt: Spawn {
6971
/// let future = future::ready(1);
7072
/// let join_handle_fut = executor.spawn_with_handle(future).unwrap();
7173
/// assert_eq!(block_on(join_handle_fut), 1);
74+
/// # }
75+
/// # std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
7276
/// ```
7377
#[cfg(feature = "channel")]
7478
#[cfg_attr(docsrs, doc(cfg(feature = "channel")))]
@@ -138,7 +142,6 @@ pub trait LocalSpawnExt: LocalSpawn {
138142
/// resolves to the output of the spawned future.
139143
///
140144
/// ```
141-
/// # if cfg!(miri) { return; } // https://github.com/rust-lang/miri/issues/1038
142145
/// use futures::executor::LocalPool;
143146
/// use futures::task::LocalSpawnExt;
144147
///

futures/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
//! within macros and keywords such as async and await!.
2626
//!
2727
//! ```rust
28-
//! # if cfg!(miri) { return; } // https://github.com/rust-lang/miri/issues/1038
2928
//! # use futures::channel::mpsc;
3029
//! # use futures::executor; ///standard executors to provide a context for futures and streams
3130
//! # use futures::executor::ThreadPool;
3231
//! # use futures::StreamExt;
3332
//! #
3433
//! fn main() {
34+
//! # {
3535
//! let pool = ThreadPool::new().expect("Failed to build pool");
3636
//! let (tx, rx) = mpsc::unbounded::<i32>();
3737
//!
@@ -73,6 +73,8 @@
7373
//! let values: Vec<i32> = executor::block_on(fut_values);
7474
//!
7575
//! println!("Values={:?}", values);
76+
//! # }
77+
//! # std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
7678
//! }
7779
//! ```
7880
//!

futures/tests/eventual.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg(not(miri))] // https://github.com/rust-lang/miri/issues/1038
2-
31
use futures::channel::oneshot;
42
use futures::executor::ThreadPool;
53
use futures::future::{self, ok, Future, FutureExt, TryFutureExt};
@@ -136,6 +134,11 @@ fn select3() {
136134

137135
#[test]
138136
fn select4() {
137+
#[cfg(miri)]
138+
const N: usize = 100;
139+
#[cfg(not(miri))]
140+
const N: usize = 10000;
141+
139142
let (tx, rx) = mpsc::channel::<oneshot::Sender<i32>>();
140143

141144
let t = thread::spawn(move || {
@@ -145,7 +148,7 @@ fn select4() {
145148
});
146149

147150
let (tx2, rx2) = mpsc::channel();
148-
for _ in 0..10000 {
151+
for _ in 0..N {
149152
let (c1, p1) = oneshot::channel::<i32>();
150153
let (c2, p2) = oneshot::channel::<i32>();
151154

futures/tests/future_shared.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ fn drop_in_poll() {
9797
assert_eq!(block_on(future1), 1);
9898
}
9999

100-
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
101100
#[test]
102101
fn peek() {
103102
let mut local_pool = LocalPool::new();

futures/tests/lock_mutex.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,36 @@ fn mutex_wakes_waiters() {
3434
assert!(waiter.poll_unpin(&mut panic_context()).is_ready());
3535
}
3636

37-
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
3837
#[test]
3938
fn mutex_contested() {
40-
let (tx, mut rx) = mpsc::unbounded();
41-
let pool = ThreadPool::builder().pool_size(16).create().unwrap();
39+
{
40+
let (tx, mut rx) = mpsc::unbounded();
41+
let pool = ThreadPool::builder().pool_size(16).create().unwrap();
4242

43-
let tx = Arc::new(tx);
44-
let mutex = Arc::new(Mutex::new(0));
43+
let tx = Arc::new(tx);
44+
let mutex = Arc::new(Mutex::new(0));
4545

46-
let num_tasks = 1000;
47-
for _ in 0..num_tasks {
48-
let tx = tx.clone();
49-
let mutex = mutex.clone();
50-
pool.spawn(async move {
51-
let mut lock = mutex.lock().await;
52-
ready(()).pending_once().await;
53-
*lock += 1;
54-
tx.unbounded_send(()).unwrap();
55-
drop(lock);
56-
})
57-
.unwrap();
58-
}
59-
60-
block_on(async {
46+
let num_tasks = 1000;
6147
for _ in 0..num_tasks {
62-
rx.next().await.unwrap();
48+
let tx = tx.clone();
49+
let mutex = mutex.clone();
50+
pool.spawn(async move {
51+
let mut lock = mutex.lock().await;
52+
ready(()).pending_once().await;
53+
*lock += 1;
54+
tx.unbounded_send(()).unwrap();
55+
drop(lock);
56+
})
57+
.unwrap();
6358
}
64-
let lock = mutex.lock().await;
65-
assert_eq!(num_tasks, *lock);
66-
})
59+
60+
block_on(async {
61+
for _ in 0..num_tasks {
62+
rx.next().await.unwrap();
63+
}
64+
let lock = mutex.lock().await;
65+
assert_eq!(num_tasks, *lock);
66+
});
67+
}
68+
std::thread::sleep(std::time::Duration::from_secs(1)); // wait for background threads closed
6769
}

futures/tests/macro_comma_support.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ fn ready() {
1414
}))
1515
}
1616

17-
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
1817
#[test]
1918
fn poll() {
2019
use futures::poll;

futures/tests/recurse.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use futures::future::{self, BoxFuture, FutureExt};
33
use std::sync::mpsc;
44
use std::thread;
55

6-
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
76
#[test]
87
fn lots() {
98
#[cfg(not(futures_sanitizer))]

futures/tests/sink.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ fn mpsc_blocking_start_send() {
288288

289289
// test `flush` by using `with` to make the first insertion into a sink block
290290
// until a oneshot is completed
291-
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
292291
#[test]
293292
fn with_flush() {
294293
let (tx, rx) = oneshot::channel();

futures/tests/stream_futures_ordered.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ fn works_1() {
2626
assert_eq!(None, iter.next());
2727
}
2828

29-
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
3029
#[test]
3130
fn works_2() {
3231
let (a_tx, a_rx) = oneshot::channel::<i32>();
@@ -55,7 +54,6 @@ fn from_iterator() {
5554
assert_eq!(block_on(stream.collect::<Vec<_>>()), vec![1, 2, 3]);
5655
}
5756

58-
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
5957
#[test]
6058
fn queue_never_unblocked() {
6159
let (_a_tx, a_rx) = oneshot::channel::<Box<dyn Any + Send>>();

futures/tests/stream_futures_unordered.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ fn works_1() {
5656
assert_eq!(None, iter.next());
5757
}
5858

59-
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
6059
#[test]
6160
fn works_2() {
6261
let (a_tx, a_rx) = oneshot::channel::<i32>();
@@ -86,7 +85,6 @@ fn from_iterator() {
8685
assert_eq!(block_on(stream.collect::<Vec<_>>()), vec![1, 2, 3]);
8786
}
8887

89-
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
9088
#[test]
9189
fn finished_future() {
9290
let (_a_tx, a_rx) = oneshot::channel::<i32>();

futures/tests/stream_try_stream.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg(not(miri))] // https://github.com/rust-lang/miri/issues/1038
2-
31
use futures::{
42
stream::{self, StreamExt, TryStreamExt},
53
task::Poll,

0 commit comments

Comments
 (0)