futures: tests/mutex.rs: Don't break w/o features
Symbols/Imports pushed down / localised
Tests gated with cfg()
Tests now build and pass with all valid feature combinations
See previous commits for details and rationale
-use futures::channel::mpsc;
-use futures::executor::block_on;
-use futures::future::{ready, FutureExt};
-use futures::lock::Mutex;
-use futures::stream::StreamExt;
-use futures::task::{Context, SpawnExt};
-use futures_test::future::FutureTestExt;
-use futures_test::task::{new_count_waker, panic_context};
-use std::sync::Arc;
-
+#[cfg(all(feature = "alloc", feature = "std"))]
#[test]
fn mutex_acquire_uncontested() {
+ use futures::future::FutureExt;
+ use futures::lock::Mutex;
+ use futures_test::task::panic_context;
+
let mutex = Mutex::new(());
for _ in 0..10 {
assert!(mutex.lock().poll_unpin(&mut panic_context()).is_ready());
}
}
+#[cfg(all(feature = "alloc", feature = "std"))]
#[test]
fn mutex_wakes_waiters() {
+ use futures::future::FutureExt;
+ use futures::lock::Mutex;
+ use futures::task::Context;
+ use futures_test::task::{new_count_waker, panic_context};
+
let mutex = Mutex::new(());
let (waker, counter) = new_count_waker();
let lock = mutex.lock().poll_unpin(&mut panic_context());
@@ -34,8 +35,18 @@ fn mutex_wakes_waiters() {
assert!(waiter.poll_unpin(&mut panic_context()).is_ready());
}
+#[cfg(feature = "thread-pool")]
#[test]
fn mutex_contested() {
+ use futures::channel::mpsc;
+ use futures::executor::block_on;
+ use futures::future::ready;
+ use futures::lock::Mutex;
+ use futures::stream::StreamExt;
+ use futures::task::SpawnExt;
+ use futures_test::future::FutureTestExt;
+ use std::sync::Arc;
+
let (tx, mut rx) = mpsc::unbounded();
let pool = futures::executor::ThreadPool::builder()
.pool_size(16)
