diff options
Diffstat (limited to 'tests/sync_mutex_owned.rs')
-rw-r--r-- | tests/sync_mutex_owned.rs | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/tests/sync_mutex_owned.rs b/tests/sync_mutex_owned.rs index 898bf35..ba472fe 100644 --- a/tests/sync_mutex_owned.rs +++ b/tests/sync_mutex_owned.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() { @@ -49,10 +55,14 @@ fn readiness() { assert_ready!(t2.poll()); } -#[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(); @@ -75,10 +85,14 @@ async fn aborted_future_1() { .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 @@ -108,13 +122,13 @@ fn try_lock_owned() { let g1 = m.clone().try_lock_owned(); assert!(g1.is_ok()); let g2 = m.clone().try_lock_owned(); - assert!(!g2.is_ok()); + assert!(g2.is_err()); } let g3 = m.try_lock_owned(); assert!(g3.is_ok()); } -#[tokio::test] +#[maybe_tokio_test] async fn debug_format() { let s = "debug"; let m = Arc::new(Mutex::new(s.to_string())); |