mirror of
https://github.com/Noratrieb/icefun.git
synced 2026-01-16 05:35:02 +01:00
loop
This commit is contained in:
parent
7af1274587
commit
189f24e53b
58 changed files with 1489 additions and 12529 deletions
|
|
@ -119,35 +119,20 @@ impl Body {
|
|||
/// ```
|
||||
#[inline]
|
||||
pub fn empty() -> Body {
|
||||
Body::new(Kind::Once(None))
|
||||
loop {}
|
||||
}
|
||||
/// Create a `Body` stream with an associated sender half.
|
||||
///
|
||||
/// Useful when wanting to stream chunks from another thread.
|
||||
#[inline]
|
||||
pub(crate) fn channel() -> (Sender, Body) {
|
||||
Self::new_channel(DecodedLength::CHUNKED, false)
|
||||
loop {}
|
||||
}
|
||||
pub(crate) fn new_channel(
|
||||
content_length: DecodedLength,
|
||||
wanter: bool,
|
||||
) -> (Sender, Body) {
|
||||
let (data_tx, data_rx) = mpsc::channel(0);
|
||||
let (trailers_tx, trailers_rx) = oneshot::channel();
|
||||
let want = if wanter { WANT_PENDING } else { WANT_READY };
|
||||
let (want_tx, want_rx) = watch::channel(want);
|
||||
let tx = Sender {
|
||||
want_rx,
|
||||
data_tx,
|
||||
trailers_tx: Some(trailers_tx),
|
||||
};
|
||||
let rx = Body::new(Kind::Chan {
|
||||
content_length,
|
||||
want_tx,
|
||||
data_rx,
|
||||
trailers_rx,
|
||||
});
|
||||
(tx, rx)
|
||||
loop {}
|
||||
}
|
||||
/// Wrap a futures `Stream` in a box inside `Body`.
|
||||
///
|
||||
|
|
@ -178,11 +163,10 @@ impl Body {
|
|||
O: Into<Bytes> + 'static,
|
||||
E: Into<Box<dyn StdError + Send + Sync>> + 'static,
|
||||
{
|
||||
let mapped = stream.map_ok(Into::into).map_err(Into::into);
|
||||
Body::new(Kind::Wrapped(SyncWrapper::new(Box::pin(mapped))))
|
||||
loop {}
|
||||
}
|
||||
fn new(kind: Kind) -> Body {
|
||||
Body { kind, extra: None }
|
||||
loop {}
|
||||
}
|
||||
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
|
||||
pub(crate) fn h2(
|
||||
|
|
@ -190,144 +174,46 @@ impl Body {
|
|||
mut content_length: DecodedLength,
|
||||
ping: ping::Recorder,
|
||||
) -> Self {
|
||||
if !content_length.is_exact() && recv.is_end_stream() {
|
||||
content_length = DecodedLength::ZERO;
|
||||
}
|
||||
let body = Body::new(Kind::H2 {
|
||||
ping,
|
||||
content_length,
|
||||
recv,
|
||||
});
|
||||
body
|
||||
loop {}
|
||||
}
|
||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
||||
#[cfg(feature = "client")]
|
||||
pub(crate) fn delayed_eof(&mut self, fut: DelayEofUntil) {
|
||||
self.extra_mut().delayed_eof = Some(DelayEof::NotEof(fut));
|
||||
loop {}
|
||||
}
|
||||
fn take_delayed_eof(&mut self) -> Option<DelayEof> {
|
||||
self.extra.as_mut().and_then(|extra| extra.delayed_eof.take())
|
||||
loop {}
|
||||
}
|
||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
||||
fn extra_mut(&mut self) -> &mut Extra {
|
||||
self.extra.get_or_insert_with(|| Box::new(Extra { delayed_eof: None }))
|
||||
loop {}
|
||||
}
|
||||
fn poll_eof(
|
||||
&mut self,
|
||||
cx: &mut task::Context<'_>,
|
||||
) -> Poll<Option<crate::Result<Bytes>>> {
|
||||
match self.take_delayed_eof() {
|
||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
||||
#[cfg(feature = "client")]
|
||||
Some(DelayEof::NotEof(mut delay)) => {
|
||||
match self.poll_inner(cx) {
|
||||
ok @ Poll::Ready(Some(Ok(..))) | ok @ Poll::Pending => {
|
||||
self.extra_mut().delayed_eof = Some(DelayEof::NotEof(delay));
|
||||
ok
|
||||
}
|
||||
Poll::Ready(None) => {
|
||||
match Pin::new(&mut delay).poll(cx) {
|
||||
Poll::Ready(Ok(never)) => match never {}
|
||||
Poll::Pending => {
|
||||
self.extra_mut().delayed_eof = Some(DelayEof::Eof(delay));
|
||||
Poll::Pending
|
||||
}
|
||||
Poll::Ready(Err(_done)) => Poll::Ready(None),
|
||||
}
|
||||
}
|
||||
Poll::Ready(Some(Err(e))) => Poll::Ready(Some(Err(e))),
|
||||
}
|
||||
}
|
||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
||||
#[cfg(feature = "client")]
|
||||
Some(DelayEof::Eof(mut delay)) => {
|
||||
match Pin::new(&mut delay).poll(cx) {
|
||||
Poll::Ready(Ok(never)) => match never {}
|
||||
Poll::Pending => {
|
||||
self.extra_mut().delayed_eof = Some(DelayEof::Eof(delay));
|
||||
Poll::Pending
|
||||
}
|
||||
Poll::Ready(Err(_done)) => Poll::Ready(None),
|
||||
}
|
||||
}
|
||||
#[cfg(
|
||||
any(
|
||||
not(any(feature = "http1", feature = "http2")),
|
||||
not(feature = "client")
|
||||
)
|
||||
)]
|
||||
Some(delay_eof) => match delay_eof {}
|
||||
None => self.poll_inner(cx),
|
||||
}
|
||||
loop {}
|
||||
}
|
||||
#[cfg(feature = "ffi")]
|
||||
pub(crate) fn as_ffi_mut(&mut self) -> &mut crate::ffi::UserBody {
|
||||
match self.kind {
|
||||
Kind::Ffi(ref mut body) => return body,
|
||||
_ => {
|
||||
self.kind = Kind::Ffi(crate::ffi::UserBody::new());
|
||||
}
|
||||
}
|
||||
match self.kind {
|
||||
Kind::Ffi(ref mut body) => body,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
loop {}
|
||||
}
|
||||
fn poll_inner(
|
||||
&mut self,
|
||||
cx: &mut task::Context<'_>,
|
||||
) -> Poll<Option<crate::Result<Bytes>>> {
|
||||
match self.kind {
|
||||
Kind::Once(ref mut val) => Poll::Ready(val.take().map(Ok)),
|
||||
Kind::Chan {
|
||||
content_length: ref mut len,
|
||||
ref mut data_rx,
|
||||
ref mut want_tx,
|
||||
..
|
||||
} => {
|
||||
want_tx.send(WANT_READY);
|
||||
match ready!(Pin::new(data_rx).poll_next(cx) ?) {
|
||||
Some(chunk) => {
|
||||
len.sub_if(chunk.len() as u64);
|
||||
Poll::Ready(Some(Ok(chunk)))
|
||||
}
|
||||
None => Poll::Ready(None),
|
||||
}
|
||||
}
|
||||
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
|
||||
Kind::H2 { ref ping, recv: ref mut h2, content_length: ref mut len } => {
|
||||
match ready!(h2.poll_data(cx)) {
|
||||
Some(Ok(bytes)) => {
|
||||
let _ = h2.flow_control().release_capacity(bytes.len());
|
||||
len.sub_if(bytes.len() as u64);
|
||||
ping.record_data(bytes.len());
|
||||
Poll::Ready(Some(Ok(bytes)))
|
||||
}
|
||||
Some(Err(e)) => Poll::Ready(Some(Err(crate::Error::new_body(e)))),
|
||||
None => Poll::Ready(None),
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "ffi")]
|
||||
Kind::Ffi(ref mut body) => body.poll_data(cx),
|
||||
#[cfg(feature = "stream")]
|
||||
Kind::Wrapped(ref mut s) => {
|
||||
match ready!(s.get_mut().as_mut().poll_next(cx)) {
|
||||
Some(res) => Poll::Ready(Some(res.map_err(crate::Error::new_body))),
|
||||
None => Poll::Ready(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
loop {}
|
||||
}
|
||||
#[cfg(feature = "http1")]
|
||||
pub(super) fn take_full_data(&mut self) -> Option<Bytes> {
|
||||
if let Kind::Once(ref mut chunk) = self.kind { chunk.take() } else { None }
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
impl Default for Body {
|
||||
/// Returns `Body::empty()`.
|
||||
#[inline]
|
||||
fn default() -> Body {
|
||||
Body::empty()
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
impl HttpBody for Body {
|
||||
|
|
@ -337,7 +223,7 @@ impl HttpBody for Body {
|
|||
mut self: Pin<&mut Self>,
|
||||
cx: &mut task::Context<'_>,
|
||||
) -> Poll<Option<Result<Self::Data, Self::Error>>> {
|
||||
self.poll_eof(cx)
|
||||
loop {}
|
||||
}
|
||||
fn poll_trailers(
|
||||
#[cfg_attr(not(feature = "http2"), allow(unused_mut))]
|
||||
|
|
@ -345,75 +231,18 @@ impl HttpBody for Body {
|
|||
#[cfg_attr(not(feature = "http2"), allow(unused))]
|
||||
cx: &mut task::Context<'_>,
|
||||
) -> Poll<Result<Option<HeaderMap>, Self::Error>> {
|
||||
match self.kind {
|
||||
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
|
||||
Kind::H2 { recv: ref mut h2, ref ping, .. } => {
|
||||
match ready!(h2.poll_trailers(cx)) {
|
||||
Ok(t) => {
|
||||
ping.record_non_data();
|
||||
Poll::Ready(Ok(t))
|
||||
}
|
||||
Err(e) => Poll::Ready(Err(crate::Error::new_h2(e))),
|
||||
}
|
||||
}
|
||||
Kind::Chan { ref mut trailers_rx, .. } => {
|
||||
match ready!(Pin::new(trailers_rx).poll(cx)) {
|
||||
Ok(t) => Poll::Ready(Ok(Some(t))),
|
||||
Err(_) => Poll::Ready(Ok(None)),
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "ffi")]
|
||||
Kind::Ffi(ref mut body) => body.poll_trailers(cx),
|
||||
_ => Poll::Ready(Ok(None)),
|
||||
}
|
||||
loop {}
|
||||
}
|
||||
fn is_end_stream(&self) -> bool {
|
||||
match self.kind {
|
||||
Kind::Once(ref val) => val.is_none(),
|
||||
Kind::Chan { content_length, .. } => content_length == DecodedLength::ZERO,
|
||||
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
|
||||
Kind::H2 { recv: ref h2, .. } => h2.is_end_stream(),
|
||||
#[cfg(feature = "ffi")]
|
||||
Kind::Ffi(..) => false,
|
||||
#[cfg(feature = "stream")]
|
||||
Kind::Wrapped(..) => false,
|
||||
}
|
||||
loop {}
|
||||
}
|
||||
fn size_hint(&self) -> SizeHint {
|
||||
macro_rules! opt_len {
|
||||
($content_length:expr) => {
|
||||
{ let mut hint = SizeHint::default(); if let Some(content_length) =
|
||||
$content_length .into_opt() { hint.set_exact(content_length); } hint }
|
||||
};
|
||||
}
|
||||
match self.kind {
|
||||
Kind::Once(Some(ref val)) => SizeHint::with_exact(val.len() as u64),
|
||||
Kind::Once(None) => SizeHint::with_exact(0),
|
||||
#[cfg(feature = "stream")]
|
||||
Kind::Wrapped(..) => SizeHint::default(),
|
||||
Kind::Chan { content_length, .. } => opt_len!(content_length),
|
||||
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
|
||||
Kind::H2 { content_length, .. } => opt_len!(content_length),
|
||||
#[cfg(feature = "ffi")]
|
||||
Kind::Ffi(..) => SizeHint::default(),
|
||||
}
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
impl fmt::Debug for Body {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
#[derive(Debug)]
|
||||
struct Streaming;
|
||||
#[derive(Debug)]
|
||||
struct Empty;
|
||||
#[derive(Debug)]
|
||||
struct Full<'a>(&'a Bytes);
|
||||
let mut builder = f.debug_tuple("Body");
|
||||
match self.kind {
|
||||
Kind::Once(None) => builder.field(&Empty),
|
||||
Kind::Once(Some(ref chunk)) => builder.field(&Full(chunk)),
|
||||
_ => builder.field(&Streaming),
|
||||
};
|
||||
builder.finish()
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
/// # Optional
|
||||
|
|
@ -427,7 +256,7 @@ impl Stream for Body {
|
|||
self: Pin<&mut Self>,
|
||||
cx: &mut task::Context<'_>,
|
||||
) -> Poll<Option<Self::Item>> {
|
||||
HttpBody::poll_data(self, cx)
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
/// # Optional
|
||||
|
|
@ -443,55 +272,49 @@ for Body {
|
|||
dyn Stream<Item = Result<Bytes, Box<dyn StdError + Send + Sync>>> + Send,
|
||||
>,
|
||||
) -> Body {
|
||||
Body::new(Kind::Wrapped(SyncWrapper::new(stream.into())))
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
impl From<Bytes> for Body {
|
||||
#[inline]
|
||||
fn from(chunk: Bytes) -> Body {
|
||||
if chunk.is_empty() { Body::empty() } else { Body::new(Kind::Once(Some(chunk))) }
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
impl From<Vec<u8>> for Body {
|
||||
#[inline]
|
||||
fn from(vec: Vec<u8>) -> Body {
|
||||
Body::from(Bytes::from(vec))
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
impl From<&'static [u8]> for Body {
|
||||
#[inline]
|
||||
fn from(slice: &'static [u8]) -> Body {
|
||||
Body::from(Bytes::from(slice))
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
impl From<Cow<'static, [u8]>> for Body {
|
||||
#[inline]
|
||||
fn from(cow: Cow<'static, [u8]>) -> Body {
|
||||
match cow {
|
||||
Cow::Borrowed(b) => Body::from(b),
|
||||
Cow::Owned(o) => Body::from(o),
|
||||
}
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
impl From<String> for Body {
|
||||
#[inline]
|
||||
fn from(s: String) -> Body {
|
||||
Body::from(Bytes::from(s.into_bytes()))
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
impl From<&'static str> for Body {
|
||||
#[inline]
|
||||
fn from(slice: &'static str) -> Body {
|
||||
Body::from(Bytes::from(slice.as_bytes()))
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
impl From<Cow<'static, str>> for Body {
|
||||
#[inline]
|
||||
fn from(cow: Cow<'static, str>) -> Body {
|
||||
match cow {
|
||||
Cow::Borrowed(b) => Body::from(b),
|
||||
Cow::Owned(o) => Body::from(o),
|
||||
}
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
impl Sender {
|
||||
|
|
@ -500,35 +323,24 @@ impl Sender {
|
|||
&mut self,
|
||||
cx: &mut task::Context<'_>,
|
||||
) -> Poll<crate::Result<()>> {
|
||||
ready!(self.poll_want(cx) ?);
|
||||
self.data_tx.poll_ready(cx).map_err(|_| crate::Error::new_closed())
|
||||
loop {}
|
||||
}
|
||||
fn poll_want(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
|
||||
match self.want_rx.load(cx) {
|
||||
WANT_READY => Poll::Ready(Ok(())),
|
||||
WANT_PENDING => Poll::Pending,
|
||||
watch::CLOSED => Poll::Ready(Err(crate::Error::new_closed())),
|
||||
unexpected => unreachable!("want_rx value: {}", unexpected),
|
||||
}
|
||||
loop {}
|
||||
}
|
||||
async fn ready(&mut self) -> crate::Result<()> {
|
||||
futures_util::future::poll_fn(|cx| self.poll_ready(cx)).await
|
||||
loop {}
|
||||
}
|
||||
/// Send data on data channel when it is ready.
|
||||
pub(crate) async fn send_data(&mut self, chunk: Bytes) -> crate::Result<()> {
|
||||
self.ready().await?;
|
||||
self.data_tx.try_send(Ok(chunk)).map_err(|_| crate::Error::new_closed())
|
||||
loop {}
|
||||
}
|
||||
/// Send trailers on trailers channel.
|
||||
pub(crate) async fn send_trailers(
|
||||
&mut self,
|
||||
trailers: HeaderMap,
|
||||
) -> crate::Result<()> {
|
||||
let tx = match self.trailers_tx.take() {
|
||||
Some(tx) => tx,
|
||||
None => return Err(crate::Error::new_closed()),
|
||||
};
|
||||
tx.send(trailers).map_err(|_| crate::Error::new_closed())
|
||||
loop {}
|
||||
}
|
||||
/// Try to send data on this channel.
|
||||
///
|
||||
|
|
@ -543,34 +355,20 @@ impl Sender {
|
|||
/// that doesn't have an async context. If in an async context, prefer
|
||||
/// `send_data()` instead.
|
||||
pub(crate) fn try_send_data(&mut self, chunk: Bytes) -> Result<(), Bytes> {
|
||||
self.data_tx
|
||||
.try_send(Ok(chunk))
|
||||
.map_err(|err| err.into_inner().expect("just sent Ok"))
|
||||
loop {}
|
||||
}
|
||||
/// Aborts the body in an abnormal fashion.
|
||||
pub(crate) fn abort(self) {
|
||||
let _ = self
|
||||
.data_tx
|
||||
.clone()
|
||||
.try_send(Err(crate::Error::new_body_write_aborted()));
|
||||
loop {}
|
||||
}
|
||||
#[cfg(feature = "http1")]
|
||||
pub(crate) fn send_error(&mut self, err: crate::Error) {
|
||||
let _ = self.data_tx.try_send(Err(err));
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
impl fmt::Debug for Sender {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
#[derive(Debug)]
|
||||
struct Open;
|
||||
#[derive(Debug)]
|
||||
struct Closed;
|
||||
let mut builder = f.debug_tuple("Sender");
|
||||
match self.want_rx.peek() {
|
||||
watch::CLOSED => builder.field(&Closed),
|
||||
_ => builder.field(&Open),
|
||||
};
|
||||
builder.finish()
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
|
|
@ -580,96 +378,38 @@ mod tests {
|
|||
use super::{Body, DecodedLength, HttpBody, Sender, SizeHint};
|
||||
#[test]
|
||||
fn test_size_of() {
|
||||
let body_size = mem::size_of::<Body>();
|
||||
let body_expected_size = mem::size_of::<u64>() * 6;
|
||||
assert!(
|
||||
body_size <= body_expected_size, "Body size = {} <= {}", body_size,
|
||||
body_expected_size,
|
||||
);
|
||||
assert_eq!(body_size, mem::size_of::< Option < Body >> (), "Option<Body>");
|
||||
assert_eq!(
|
||||
mem::size_of::< Sender > (), mem::size_of::< usize > () * 5, "Sender"
|
||||
);
|
||||
assert_eq!(
|
||||
mem::size_of::< Sender > (), mem::size_of::< Option < Sender >> (),
|
||||
"Option<Sender>"
|
||||
);
|
||||
loop {}
|
||||
}
|
||||
#[test]
|
||||
fn size_hint() {
|
||||
fn eq(body: Body, b: SizeHint, note: &str) {
|
||||
let a = body.size_hint();
|
||||
assert_eq!(a.lower(), b.lower(), "lower for {:?}", note);
|
||||
assert_eq!(a.upper(), b.upper(), "upper for {:?}", note);
|
||||
}
|
||||
eq(Body::from("Hello"), SizeHint::with_exact(5), "from str");
|
||||
eq(Body::empty(), SizeHint::with_exact(0), "empty");
|
||||
eq(Body::channel().1, SizeHint::new(), "channel");
|
||||
eq(
|
||||
Body::new_channel(DecodedLength::new(4), false).1,
|
||||
SizeHint::with_exact(4),
|
||||
"channel with length",
|
||||
);
|
||||
loop {}
|
||||
}
|
||||
#[tokio::test]
|
||||
async fn channel_abort() {
|
||||
let (tx, mut rx) = Body::channel();
|
||||
tx.abort();
|
||||
let err = rx.data().await.unwrap().unwrap_err();
|
||||
assert!(err.is_body_write_aborted(), "{:?}", err);
|
||||
loop {}
|
||||
}
|
||||
#[tokio::test]
|
||||
async fn channel_abort_when_buffer_is_full() {
|
||||
let (mut tx, mut rx) = Body::channel();
|
||||
tx.try_send_data("chunk 1".into()).expect("send 1");
|
||||
tx.abort();
|
||||
let chunk1 = rx.data().await.expect("item 1").expect("chunk 1");
|
||||
assert_eq!(chunk1, "chunk 1");
|
||||
let err = rx.data().await.unwrap().unwrap_err();
|
||||
assert!(err.is_body_write_aborted(), "{:?}", err);
|
||||
loop {}
|
||||
}
|
||||
#[test]
|
||||
fn channel_buffers_one() {
|
||||
let (mut tx, _rx) = Body::channel();
|
||||
tx.try_send_data("chunk 1".into()).expect("send 1");
|
||||
let chunk2 = tx.try_send_data("chunk 2".into()).expect_err("send 2");
|
||||
assert_eq!(chunk2, "chunk 2");
|
||||
loop {}
|
||||
}
|
||||
#[tokio::test]
|
||||
async fn channel_empty() {
|
||||
let (_, mut rx) = Body::channel();
|
||||
assert!(rx.data().await.is_none());
|
||||
loop {}
|
||||
}
|
||||
#[test]
|
||||
fn channel_ready() {
|
||||
let (mut tx, _rx) = Body::new_channel(DecodedLength::CHUNKED, false);
|
||||
let mut tx_ready = tokio_test::task::spawn(tx.ready());
|
||||
assert!(tx_ready.poll().is_ready(), "tx is ready immediately");
|
||||
loop {}
|
||||
}
|
||||
#[test]
|
||||
fn channel_wanter() {
|
||||
let (mut tx, mut rx) = Body::new_channel(DecodedLength::CHUNKED, true);
|
||||
let mut tx_ready = tokio_test::task::spawn(tx.ready());
|
||||
let mut rx_data = tokio_test::task::spawn(rx.data());
|
||||
assert!(
|
||||
tx_ready.poll().is_pending(), "tx isn't ready before rx has been polled"
|
||||
);
|
||||
assert!(rx_data.poll().is_pending(), "poll rx.data");
|
||||
assert!(tx_ready.is_woken(), "rx poll wakes tx");
|
||||
assert!(tx_ready.poll().is_ready(), "tx is ready after rx has been polled");
|
||||
loop {}
|
||||
}
|
||||
#[test]
|
||||
fn channel_notices_closure() {
|
||||
let (mut tx, rx) = Body::new_channel(DecodedLength::CHUNKED, true);
|
||||
let mut tx_ready = tokio_test::task::spawn(tx.ready());
|
||||
assert!(
|
||||
tx_ready.poll().is_pending(), "tx isn't ready before rx has been polled"
|
||||
);
|
||||
drop(rx);
|
||||
assert!(tx_ready.is_woken(), "dropping rx wakes tx");
|
||||
match tx_ready.poll() {
|
||||
Poll::Ready(Err(ref e)) if e.is_closed() => {}
|
||||
unexpected => panic!("tx poll ready unexpected: {:?}", unexpected),
|
||||
}
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue