This commit is contained in:
fakeshadow 2021-03-25 22:43:31 +08:00
parent a92601964f
commit e8ea2441a4
1 changed files with 41 additions and 7 deletions

View File

@ -404,9 +404,18 @@ where
#[cfg(test)]
mod test {
use std::net;
use std::{
future::Future,
net,
pin::Pin,
task::{Context, Poll},
time::{Duration, Instant},
};
use actix_rt::net::TcpStream;
use actix_rt::{
net::TcpStream,
time::{interval, Interval},
};
use super::*;
@ -430,11 +439,36 @@ mod test {
drop(conn);
actix_rt::task::yield_now().await;
struct DropCheck {
sender: h2::client::SendRequest<Bytes>,
interval: Interval,
start_from: Instant,
}
match sender.ready().await {
Ok(_) => panic!("connection should be gone and can not be ready"),
Err(e) => assert!(e.is_io()),
};
impl Future for DropCheck {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.get_mut();
match futures_core::ready!(this.sender.poll_ready(cx)) {
Ok(()) => {
if this.start_from.elapsed() > Duration::from_secs(10) {
panic!("connection should be gone and can not be ready");
} else {
let _ = this.interval.poll_tick(cx);
Poll::Pending
}
}
Err(_) => Poll::Ready(()),
}
}
}
DropCheck {
sender,
interval: interval(Duration::from_millis(100)),
start_from: Instant::now(),
}
.await;
}
}