diff options
Diffstat (limited to 'vendor/tokio/tests/sync_mutex.rs')
-rw-r--r-- | vendor/tokio/tests/sync_mutex.rs | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/vendor/tokio/tests/sync_mutex.rs b/vendor/tokio/tests/sync_mutex.rs index 0ddb203d8..1e35a558c 100644 --- a/vendor/tokio/tests/sync_mutex.rs +++ b/vendor/tokio/tests/sync_mutex.rs @@ -1,13 +1,19 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(feature = "sync")] + +#[cfg(tokio_wasm_not_wasi)] +use wasm_bindgen_test::wasm_bindgen_test as test; +#[cfg(tokio_wasm_not_wasi)] +use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; + +#[cfg(not(tokio_wasm_not_wasi))] +use tokio::test as maybe_tokio_test; use tokio::sync::Mutex; -use tokio::time::{interval, timeout}; use tokio_test::task::spawn; use tokio_test::{assert_pending, assert_ready}; use std::sync::Arc; -use std::time::Duration; #[test] fn straight_execution() { @@ -47,7 +53,7 @@ fn readiness() { // But once g unlocks, we can acquire it drop(g); assert!(t2.is_woken()); - assert_ready!(t2.poll()); + let _t2 = assert_ready!(t2.poll()); } /* @@ -82,10 +88,14 @@ fn lock() { } */ -#[tokio::test] /// Ensure a mutex is unlocked if a future holding the lock /// is aborted prematurely. +#[tokio::test] +#[cfg(feature = "full")] async fn aborted_future_1() { + use std::time::Duration; + use tokio::time::{interval, timeout}; + let m1: Arc<Mutex<usize>> = Arc::new(Mutex::new(0)); { let m2 = m1.clone(); @@ -93,7 +103,7 @@ async fn aborted_future_1() { timeout(Duration::from_millis(1u64), async move { let iv = interval(Duration::from_millis(1000)); tokio::pin!(iv); - m2.lock().await; + let _g = m2.lock().await; iv.as_mut().tick().await; iv.as_mut().tick().await; }) @@ -102,16 +112,20 @@ async fn aborted_future_1() { } // This should succeed as there is no lock left for the mutex. timeout(Duration::from_millis(1u64), async move { - m1.lock().await; + let _g = m1.lock().await; }) .await .expect("Mutex is locked"); } -#[tokio::test] /// This test is similar to `aborted_future_1` but this time the /// aborted future is waiting for the lock. +#[tokio::test] +#[cfg(feature = "full")] async fn aborted_future_2() { + use std::time::Duration; + use tokio::time::timeout; + let m1: Arc<Mutex<usize>> = Arc::new(Mutex::new(0)); { // Lock mutex @@ -120,7 +134,7 @@ async fn aborted_future_2() { let m2 = m1.clone(); // Try to lock mutex in a future that is aborted prematurely timeout(Duration::from_millis(1u64), async move { - m2.lock().await; + let _g = m2.lock().await; }) .await .unwrap_err(); @@ -128,7 +142,7 @@ async fn aborted_future_2() { } // This should succeed as there is no lock left for the mutex. timeout(Duration::from_millis(1u64), async move { - m1.lock().await; + let _g = m1.lock().await; }) .await .expect("Mutex is locked"); @@ -139,22 +153,22 @@ fn try_lock() { let m: Mutex<usize> = Mutex::new(0); { let g1 = m.try_lock(); - assert_eq!(g1.is_ok(), true); + assert!(g1.is_ok()); let g2 = m.try_lock(); - assert_eq!(g2.is_ok(), false); + assert!(g2.is_err()); } let g3 = m.try_lock(); - assert_eq!(g3.is_ok(), true); + assert!(g3.is_ok()); } -#[tokio::test] +#[maybe_tokio_test] async fn debug_format() { let s = "debug"; let m = Mutex::new(s.to_string()); assert_eq!(format!("{:?}", s), format!("{:?}", m.lock().await)); } -#[tokio::test] +#[maybe_tokio_test] async fn mutex_debug() { let s = "data"; let m = Mutex::new(s.to_string()); |