Skip to content

Commit

Permalink
Revert import changes in tests
Browse files Browse the repository at this point in the history
After rust-lang#2216, these redundant imports are unneeded.
This reverts almost all of rust-lang#2101.
This also includes some minor cleanup of imports in tests.
  • Loading branch information
taiki-e committed Feb 26, 2021
1 parent c03ad8b commit 25cab70
Show file tree
Hide file tree
Showing 43 changed files with 968 additions and 1,492 deletions.
18 changes: 6 additions & 12 deletions futures/tests/abortable.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use futures::channel::oneshot;
use futures::executor::block_on;
use futures::future::{abortable, Aborted, FutureExt};
use futures::task::{Context, Poll};
use futures_test::task::new_count_waker;

#[test]
fn abortable_works() {
use futures::channel::oneshot;
use futures::future::{abortable, Aborted};
use futures::executor::block_on;

let (_tx, a_rx) = oneshot::channel::<()>();
let (abortable_rx, abort_handle) = abortable(a_rx);

Expand All @@ -13,11 +15,6 @@ fn abortable_works() {

#[test]
fn abortable_awakens() {
use futures::channel::oneshot;
use futures::future::{abortable, Aborted, FutureExt};
use futures::task::{Context, Poll};
use futures_test::task::new_count_waker;

let (_tx, a_rx) = oneshot::channel::<()>();
let (mut abortable_rx, abort_handle) = abortable(a_rx);

Expand All @@ -33,9 +30,6 @@ fn abortable_awakens() {

#[test]
fn abortable_resolves() {
use futures::channel::oneshot;
use futures::future::abortable;
use futures::executor::block_on;
let (tx, a_rx) = oneshot::channel::<()>();
let (abortable_rx, _abort_handle) = abortable(a_rx);

Expand Down
98 changes: 50 additions & 48 deletions futures/tests/arc_wake.rs
Original file line number Diff line number Diff line change
@@ -1,69 +1,65 @@
mod countingwaker {
use futures::task::{self, ArcWake, Waker};
use std::sync::{Arc, Mutex};
use futures::task::{self, ArcWake, Waker};
use std::panic;
use std::sync::{Arc, Mutex};

struct CountingWaker {
nr_wake: Mutex<i32>,
}
struct CountingWaker {
nr_wake: Mutex<i32>,
}

impl CountingWaker {
fn new() -> Self {
Self {
nr_wake: Mutex::new(0),
}
impl CountingWaker {
fn new() -> Self {
Self {
nr_wake: Mutex::new(0),
}
}

fn wakes(&self) -> i32 {
*self.nr_wake.lock().unwrap()
}
fn wakes(&self) -> i32 {
*self.nr_wake.lock().unwrap()
}
}

impl ArcWake for CountingWaker {
fn wake_by_ref(arc_self: &Arc<Self>) {
let mut lock = arc_self.nr_wake.lock().unwrap();
*lock += 1;
}
impl ArcWake for CountingWaker {
fn wake_by_ref(arc_self: &Arc<Self>) {
let mut lock = arc_self.nr_wake.lock().unwrap();
*lock += 1;
}
}

#[test]
fn create_from_arc() {
let some_w = Arc::new(CountingWaker::new());
#[test]
fn create_from_arc() {
let some_w = Arc::new(CountingWaker::new());

let w1: Waker = task::waker(some_w.clone());
assert_eq!(2, Arc::strong_count(&some_w));
w1.wake_by_ref();
assert_eq!(1, some_w.wakes());
let w1: Waker = task::waker(some_w.clone());
assert_eq!(2, Arc::strong_count(&some_w));
w1.wake_by_ref();
assert_eq!(1, some_w.wakes());

let w2 = w1.clone();
assert_eq!(3, Arc::strong_count(&some_w));
let w2 = w1.clone();
assert_eq!(3, Arc::strong_count(&some_w));

w2.wake_by_ref();
assert_eq!(2, some_w.wakes());
w2.wake_by_ref();
assert_eq!(2, some_w.wakes());

drop(w2);
assert_eq!(2, Arc::strong_count(&some_w));
drop(w1);
assert_eq!(1, Arc::strong_count(&some_w));
}
drop(w2);
assert_eq!(2, Arc::strong_count(&some_w));
drop(w1);
assert_eq!(1, Arc::strong_count(&some_w));
}

#[test]
fn ref_wake_same() {
let some_w = Arc::new(CountingWaker::new());
#[test]
fn ref_wake_same() {
let some_w = Arc::new(CountingWaker::new());

let w1: Waker = task::waker(some_w.clone());
let w2 = task::waker_ref(&some_w);
let w3 = w2.clone();
let w1: Waker = task::waker(some_w.clone());
let w2 = task::waker_ref(&some_w);
let w3 = w2.clone();

assert!(w1.will_wake(&w2));
assert!(w2.will_wake(&w3));
}
assert!(w1.will_wake(&w2));
assert!(w2.will_wake(&w3));
}

#[test]
fn proper_refcount_on_wake_panic() {
use futures::task::{self, ArcWake, Waker};
use std::sync::Arc;

struct PanicWaker;

impl ArcWake for PanicWaker {
Expand All @@ -75,7 +71,13 @@ fn proper_refcount_on_wake_panic() {
let some_w = Arc::new(PanicWaker);

let w1: Waker = task::waker(some_w.clone());
assert_eq!("WAKE UP", *std::panic::catch_unwind(|| w1.wake_by_ref()).unwrap_err().downcast::<&str>().unwrap());
assert_eq!(
"WAKE UP",
*panic::catch_unwind(|| w1.wake_by_ref())
.unwrap_err()
.downcast::<&str>()
.unwrap()
);
assert_eq!(2, Arc::strong_count(&some_w)); // some_w + w1
drop(w1);
assert_eq!(1, Arc::strong_count(&some_w)); // some_w
Expand Down
Loading

0 comments on commit 25cab70

Please sign in to comment.