This commit is contained in:
Nikolay Kim 2025-03-28 10:01:38 +01:00
parent d9c14ef9da
commit b60d4dda6c

View file

@ -438,25 +438,22 @@ impl Drop for SetOnDrop {
async fn test_h2_client_drop() -> io::Result<()> { async fn test_h2_client_drop() -> io::Result<()> {
let count = Arc::new(AtomicUsize::new(0)); let count = Arc::new(AtomicUsize::new(0));
let count2 = count.clone(); let count2 = count.clone();
let (tx, _rx) = ::oneshot::channel(); let (tx, rx) = ::oneshot::channel();
let tx = Arc::new(Mutex::new(Some(tx))); let tx = Arc::new(Mutex::new(Some(tx)));
let (tx2, rx2) = ::oneshot::channel();
let tx2 = Arc::new(Mutex::new(Some(tx2)));
let srv = test_server(move || { let srv = test_server(move || {
let tx = tx.clone(); let tx = tx.clone();
let tx2 = tx2.clone();
let count = count2.clone(); let count = count2.clone();
HttpService::build() HttpService::build()
.h2(move |req: Request| { .h2(move |req: Request| {
let tx = tx.clone(); let st = SetOnDrop(count.clone(), tx.clone());
let _ = tx2.lock().unwrap().take().unwrap().send(());
let count = count.clone();
async move { async move {
let _st = SetOnDrop(count, tx);
assert!(req.peer_addr().is_some()); assert!(req.peer_addr().is_some());
assert_eq!(req.version(), Version::HTTP_2); assert_eq!(req.version(), Version::HTTP_2);
sleep(Seconds(100)).await; sleep(Seconds(30)).await;
drop(st);
panic!();
#[allow(unreachable_code)]
Ok::<_, io::Error>(Response::Ok().finish()) Ok::<_, io::Error>(Response::Ok().finish())
} }
}) })
@ -464,13 +461,9 @@ async fn test_h2_client_drop() -> io::Result<()> {
.map_err(|_| ()) .map_err(|_| ())
}); });
let task = rt::spawn(timeout(Millis(150), srv.srequest(Method::GET, "/").send())); let result = timeout(Millis(150), srv.srequest(Method::GET, "/").send()).await;
let _ = rx2.await;
let result = task.await.unwrap();
assert!(result.is_err()); assert!(result.is_err());
//let _ = _rx.await; let _ = timeout(Millis(1000), rx).await;
sleep(Millis(150)).await;
assert_eq!(count.load(Ordering::Relaxed), 1); assert_eq!(count.load(Ordering::Relaxed), 1);
Ok(()) Ok(())
} }