Skip to content

Commit

Permalink
Simplify cfg for import of wasm_bindgen_test::wasm_bindgen_test
Browse files Browse the repository at this point in the history
Co-authored-by: Taiki Endo <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
  • Loading branch information
NobodyXu and taiki-e committed Jul 25, 2023
1 parent 4be9109 commit 128f411
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 48 deletions.
10 changes: 3 additions & 7 deletions tokio/src/runtime/coop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,14 @@ cfg_coop! {
mod test {
use super::*;

cfg_is_wasm_not_wasi! {
use wasm_bindgen_test::wasm_bindgen_test as test;
}

#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))]
use std::prelude::v1::test;
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
use wasm_bindgen_test::wasm_bindgen_test as test;

fn get() -> Budget {
context::budget(|cell| cell.get()).unwrap_or(Budget::unconstrained())
}

#[self::test]
#[test]
fn budgeting() {
use futures::future::poll_fn;
use tokio_test::*;
Expand Down
14 changes: 5 additions & 9 deletions tokio/src/sync/tests/atomic_waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ impl AssertSync for AtomicWaker {}
impl AssertSend for Waker {}
impl AssertSync for Waker {}

cfg_is_wasm_not_wasi! {
use wasm_bindgen_test::wasm_bindgen_test as test;
}

#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))]
use std::prelude::v1::test;
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[self::test]
#[test]
fn basic_usage() {
let mut waker = task::spawn(AtomicWaker::new());

Expand All @@ -29,7 +25,7 @@ fn basic_usage() {
assert!(waker.is_woken());
}

#[self::test]
#[test]
fn wake_without_register() {
let mut waker = task::spawn(AtomicWaker::new());
waker.wake();
Expand All @@ -40,7 +36,7 @@ fn wake_without_register() {
assert!(!waker.is_woken());
}

#[self::test]
#[test]
#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding
fn atomic_waker_panic_safe() {
use std::panic;
Expand Down
16 changes: 6 additions & 10 deletions tokio/src/sync/tests/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ use std::future::Future;
use std::sync::Arc;
use std::task::{Context, RawWaker, RawWakerVTable, Waker};

cfg_is_wasm_not_wasi! {
use wasm_bindgen_test::wasm_bindgen_test as test;
}

#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))]
use std::prelude::v1::test;
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[self::test]
#[test]
fn notify_clones_waker_before_lock() {
const VTABLE: &RawWakerVTable = &RawWakerVTable::new(clone_w, wake, wake_by_ref, drop_w);

Expand Down Expand Up @@ -50,7 +46,7 @@ fn notify_clones_waker_before_lock() {
}

#[cfg(panic = "unwind")]
#[self::test]
#[test]
fn notify_waiters_handles_panicking_waker() {
use futures::task::ArcWake;

Expand Down Expand Up @@ -88,7 +84,7 @@ fn notify_waiters_handles_panicking_waker() {
}
}

#[self::test]
#[test]
fn notify_simple() {
let notify = Notify::new();

Expand All @@ -104,7 +100,7 @@ fn notify_simple() {
assert!(fut2.poll().is_ready());
}

#[self::test]
#[test]
#[cfg(not(target_family = "wasm"))]
fn watch_test() {
let rt = crate::runtime::Builder::new_current_thread()
Expand Down
40 changes: 18 additions & 22 deletions tokio/src/sync/tests/semaphore_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ use tokio_test::*;

const MAX_PERMITS: usize = crate::sync::Semaphore::MAX_PERMITS;

cfg_is_wasm_not_wasi! {
use wasm_bindgen_test::wasm_bindgen_test as test;
}

#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))]
use std::prelude::v1::test;
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[self::test]
#[test]
fn poll_acquire_one_available() {
let s = Semaphore::new(100);
assert_eq!(s.available_permits(), 100);
Expand All @@ -20,7 +16,7 @@ fn poll_acquire_one_available() {
assert_eq!(s.available_permits(), 99);
}

#[self::test]
#[test]
fn poll_acquire_many_available() {
let s = Semaphore::new(100);
assert_eq!(s.available_permits(), 100);
Expand All @@ -33,7 +29,7 @@ fn poll_acquire_many_available() {
assert_eq!(s.available_permits(), 90);
}

#[self::test]
#[test]
fn try_acquire_one_available() {
let s = Semaphore::new(100);
assert_eq!(s.available_permits(), 100);
Expand All @@ -45,7 +41,7 @@ fn try_acquire_one_available() {
assert_eq!(s.available_permits(), 98);
}

#[self::test]
#[test]
fn try_acquire_many_available() {
let s = Semaphore::new(100);
assert_eq!(s.available_permits(), 100);
Expand All @@ -57,7 +53,7 @@ fn try_acquire_many_available() {
assert_eq!(s.available_permits(), 90);
}

#[self::test]
#[test]
fn poll_acquire_one_unavailable() {
let s = Semaphore::new(1);

Expand All @@ -81,7 +77,7 @@ fn poll_acquire_one_unavailable() {
assert_eq!(s.available_permits(), 1);
}

#[self::test]
#[test]
fn poll_acquire_many_unavailable() {
let s = Semaphore::new(5);

Expand Down Expand Up @@ -118,7 +114,7 @@ fn poll_acquire_many_unavailable() {
assert_ready_ok!(acquire_3.poll());
}

#[self::test]
#[test]
fn try_acquire_one_unavailable() {
let s = Semaphore::new(1);

Expand All @@ -137,7 +133,7 @@ fn try_acquire_one_unavailable() {
assert_eq!(s.available_permits(), 1);
}

#[self::test]
#[test]
fn try_acquire_many_unavailable() {
let s = Semaphore::new(5);

Expand All @@ -159,7 +155,7 @@ fn try_acquire_many_unavailable() {
assert_eq!(s.available_permits(), 2);
}

#[self::test]
#[test]
fn poll_acquire_one_zero_permits() {
let s = Semaphore::new(0);
assert_eq!(s.available_permits(), 0);
Expand All @@ -174,19 +170,19 @@ fn poll_acquire_one_zero_permits() {
assert_ready_ok!(acquire.poll());
}

#[self::test]
#[test]
fn max_permits_doesnt_panic() {
Semaphore::new(MAX_PERMITS);
}

#[self::test]
#[test]
#[should_panic]
#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding
fn validates_max_permits() {
Semaphore::new(MAX_PERMITS + 1);
}

#[self::test]
#[test]
fn close_semaphore_prevents_acquire() {
let s = Semaphore::new(5);
s.close();
Expand All @@ -200,7 +196,7 @@ fn close_semaphore_prevents_acquire() {
assert_eq!(5, s.available_permits());
}

#[self::test]
#[test]
fn close_semaphore_notifies_permit1() {
let s = Semaphore::new(0);
let mut acquire = task::spawn(s.acquire(1));
Expand All @@ -213,7 +209,7 @@ fn close_semaphore_notifies_permit1() {
assert_ready_err!(acquire.poll());
}

#[self::test]
#[test]
fn close_semaphore_notifies_permit2() {
let s = Semaphore::new(2);

Expand Down Expand Up @@ -247,7 +243,7 @@ fn close_semaphore_notifies_permit2() {
assert_eq!(2, s.available_permits());
}

#[self::test]
#[test]
fn cancel_acquire_releases_permits() {
let s = Semaphore::new(10);
s.try_acquire(4).expect("uncontended try_acquire succeeds");
Expand All @@ -263,7 +259,7 @@ fn cancel_acquire_releases_permits() {
assert_ok!(s.try_acquire(6));
}

#[self::test]
#[test]
fn release_permits_at_drop() {
use crate::sync::semaphore::*;
use futures::task::ArcWake;
Expand Down

0 comments on commit 128f411

Please sign in to comment.