Trait futures_test::sink::SinkTestExt
source · [−]pub trait SinkTestExt<Item>: Sink<Item> {
fn assert_unmoved_sink(self) -> AssertUnmoved<Self>ⓘNotable traits for AssertUnmoved<Fut>impl<Fut: Future> Future for AssertUnmoved<Fut> type Output = Fut::Output;
where
Self: Sized,
{ ... }
fn interleave_pending_sink(self) -> InterleavePending<Self>ⓘNotable traits for InterleavePending<Fut>impl<Fut: Future> Future for InterleavePending<Fut> type Output = Fut::Output;
where
Self: Sized,
{ ... }
fn track_closed(self) -> TrackClosed<Self>
where
Self: Sized,
{ ... }
}
Expand description
Additional combinators for testing sinks.
Provided methods
fn assert_unmoved_sink(self) -> AssertUnmoved<Self>ⓘNotable traits for AssertUnmoved<Fut>impl<Fut: Future> Future for AssertUnmoved<Fut> type Output = Fut::Output;
where
Self: Sized,
fn assert_unmoved_sink(self) -> AssertUnmoved<Self>ⓘNotable traits for AssertUnmoved<Fut>impl<Fut: Future> Future for AssertUnmoved<Fut> type Output = Fut::Output;
where
Self: Sized,
Asserts that the given is not moved after being polled.
A check for movement is performed each time the sink is polled
and when Drop
is called.
Aside from keeping track of the location at which the sink was first polled and providing assertions, this sink adds no runtime behavior and simply delegates to the child sink.
fn interleave_pending_sink(self) -> InterleavePending<Self>ⓘNotable traits for InterleavePending<Fut>impl<Fut: Future> Future for InterleavePending<Fut> type Output = Fut::Output;
where
Self: Sized,
fn interleave_pending_sink(self) -> InterleavePending<Self>ⓘNotable traits for InterleavePending<Fut>impl<Fut: Future> Future for InterleavePending<Fut> type Output = Fut::Output;
where
Self: Sized,
Introduces an extra Poll::Pending
in between each operation on the sink.
fn track_closed(self) -> TrackClosed<Self> where
Self: Sized,
fn track_closed(self) -> TrackClosed<Self> where
Self: Sized,
Track whether this sink has been closed and panics if it is used after closing.
Examples
use futures::sink::{SinkExt, drain};
use futures_test::sink::SinkTestExt;
let mut sink = drain::<i32>().track_closed();
sink.send(1).await?;
assert!(!sink.is_closed());
sink.close().await?;
assert!(sink.is_closed());
Note: Unlike AsyncWriteTestExt::track_closed
when
used as a sink the adaptor will panic if closed too early as there’s no easy way to
integrate as an error.
use std::panic::AssertUnwindSafe;
use futures::{sink::{SinkExt, drain}, future::FutureExt};
use futures_test::sink::SinkTestExt;
let mut sink = drain::<i32>().track_closed();
sink.close().await?;
assert!(AssertUnwindSafe(sink.send(1)).catch_unwind().await.is_err());