Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
bf3c370
futures: tests/abortable.rs: Guard against compile failures w/o features
kentfredric Mar 14, 2020
0007d04
futures: tests/arc_wake.rs: Guard against compile failures w/o alloc
kentfredric Mar 14, 2020
2be900d
futures: tests/async_await_macros.rs: Guard against failures w/o feat…
kentfredric Mar 14, 2020
c2fab65
futures: tests/atomic_waker.rs: Guard against failures w/o executor
kentfredric Mar 14, 2020
7324624
futures: tests/buffer_unordered.rs: Guard against compile fails w/o f…
kentfredric Mar 14, 2020
761d72a
futures: tests/eager_drop.rs: Fix compiling w/o "alloc"
kentfredric Mar 14, 2020
d57949d
futures: tests/eventual.rs : Disable w/o executor + thread-pool
kentfredric Mar 14, 2020
89ccf12
futures: tests/futures_ordered.rs : Guard against failures w/o features
kentfredric Mar 14, 2020
e7b2d94
futures: tests/futures_unordered.rs: Guard against compile failures w…
kentfredric Mar 14, 2020
334a6bf
futures: tests/future_try_flatten_stream.rs: Avoid compile failures
kentfredric Mar 14, 2020
6198c75
futures: tests/inspect.rs: Avoid failures w/o "executor"
kentfredric Mar 14, 2020
f39ee19
futures: tests/io_buf_reader.rs: Avoid compile failures w/o features
kentfredric Mar 15, 2020
310ef8d
futures: tests/io_buf_writer.rs : Avoid compile failures w/o features
kentfredric Mar 15, 2020
2dcfe07
futures: tests/io_cursor.rs : Avoid breaking w/o features
kentfredric Mar 15, 2020
108c9f4
futures: tests/io_lines.rs : Avoid compile failures w/o features
kentfredric Mar 15, 2020
a7ebba8
futures: tests/io_read_exact.rs: Don't fail w/o executor
kentfredric Mar 15, 2020
89fcf19
futures: tests/io_read_line.rs: Don't break w/o features
kentfredric Mar 15, 2020
c6807c1
futures: tests/io_read.rs: Don't break w/o "std"
kentfredric Mar 15, 2020
3898293
futures: tests/io_read_to_string.rs: Don't break w/o features
kentfredric Mar 15, 2020
7475a90
futures: tests/io_read_until.rs: Don't break w/o features
kentfredric Mar 15, 2020
fcc9264
futures: tests/io_read_until.rs: Disable w/o "std"
kentfredric Mar 15, 2020
cb9e2ae
futures: tests/io_write.rs: Don't break w/o features
kentfredric Mar 15, 2020
f08ccb2
futures: tests/join_all.rs: Don't break w/o "executor" feature
kentfredric Mar 15, 2020
1e37927
futures: tests/macro_comma_support.rs: Don't break w/o features
kentfredric Mar 15, 2020
cda90ce
futures: tests/mutex.rs: Don't break w/o features
kentfredric Mar 15, 2020
cf630b9
futures: tests/object_safety.rs: Don't break w/o "std"
kentfredric Mar 15, 2020
cf3929d
futures: tests/oneshot.rs: Don't break w/o "alloc"
kentfredric Mar 15, 2020
80011bb
futures: tests/ready_queue.rs: Don't break w/o features
kentfredric Mar 15, 2020
086b831
futures: tests/ready_queue.rs: Don't break w/o "executor"
kentfredric Mar 15, 2020
67cc501
futures: tests/select_all.rs: Don't break w/o "executor"
kentfredric Mar 15, 2020
320d123
futures: tests/select_ok.rs: Don't break w/o "executor"
kentfredric Mar 15, 2020
f39481c
futures: tests/shared.rs: Don't break w/o features
kentfredric Mar 15, 2020
450221d
futures: tests/sink_fanout.rs: Don't break w/o features
kentfredric Mar 15, 2020
8cc87d1
futures: tests/sink.rs: Don't break w/o features
kentfredric Mar 15, 2020
7651ede
futures: tests/split.rs: Don't break w/o "executor"
kentfredric Mar 15, 2020
5972712
futures: tests/stream_catch_unwind.rs: Don't break w/o "executor"
kentfredric Mar 15, 2020
1f7eb52
futures: tests/stream_into_async_read.rs: Don't break w/o "std"
kentfredric Mar 15, 2020
02ad75a
futures: tests/stream_peekable.rs: Don't break w/o "executor"
kentfredric Mar 15, 2020
0e54f94
futures: tests/stream.rs: Don't break w/o "executor"
kentfredric Mar 15, 2020
da0ff8b
futures: tests/stream_select_all.rs: Don't break w/o features
kentfredric Mar 15, 2020
f7e2880
futures: tests/stream_select_next_some.rs: Don't break w/o features
kentfredric Mar 15, 2020
59a2ac4
futures: tests/try_join_all.rs: Don't break w/o "executor"
kentfredric Mar 15, 2020
e18ee1c
futures: tests/try_join.rs: Don't break w/o features
kentfredric Mar 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions futures/tests/abortable.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
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;

#[cfg(all(feature = "alloc", feature = "executor"))]
#[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);

abort_handle.abort();
assert_eq!(Err(Aborted), block_on(abortable_rx));
}

#[cfg(all(feature = "alloc", feature = "executor"))]
#[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 @@ -28,8 +33,12 @@ fn abortable_awakens() {
assert_eq!(Poll::Ready(Err(Aborted)), abortable_rx.poll_unpin(&mut cx));
}

#[cfg(all(feature = "alloc", feature = "executor"))]
#[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
107 changes: 57 additions & 50 deletions futures/tests/arc_wake.rs
Original file line number Diff line number Diff line change
@@ -1,60 +1,79 @@
use futures::task::{self, ArcWake, Waker};
use std::sync::{Arc, Mutex};
#[cfg(feature = "alloc")]
mod countingwaker {
use futures::task::{self, ArcWake, Waker};
use std::sync::{Arc, Mutex};

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

impl CountingWaker {
fn new() -> CountingWaker {
CountingWaker {
nr_wake: Mutex::new(0),
impl CountingWaker {
fn new() -> CountingWaker {
CountingWaker {
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_waker_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));
}

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

impl ArcWake for PanicWaker {
fn wake_by_ref(_arc_self: &Arc<Self>) {
panic!("WAKE UP");
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));
}
}

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

struct PanicWaker;

impl ArcWake for PanicWaker {
fn wake_by_ref(_arc_self: &Arc<Self>) {
panic!("WAKE UP");
}
}

let some_w = Arc::new(PanicWaker);

let w1: Waker = task::waker(some_w.clone());
Expand All @@ -63,15 +82,3 @@ fn proper_refcount_on_wake_panic() {
drop(w1);
assert_eq!(1, Arc::strong_count(&some_w)); // some_w
}

#[test]
fn waker_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();

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