From ac6428fbd891381ebfc07941ca492931d593fa44 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Tue, 20 Feb 2024 11:46:46 +0100 Subject: [PATCH] Poll receiver once to register waker --- neqo-common/Cargo.toml | 2 ++ neqo-common/src/udp.rs | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/neqo-common/Cargo.toml b/neqo-common/Cargo.toml index 080df3d1c..26c167b29 100644 --- a/neqo-common/Cargo.toml +++ b/neqo-common/Cargo.toml @@ -20,6 +20,8 @@ time = { version = "0.3", features = ["formatting"] } tokio = { version = "1", features = ["net", "time", "macros", "rt", "rt-multi-thread"], optional = true } [dev-dependencies] +# TODO: Needed? +futures = "0.3" test-fixture = { path = "../test-fixture" } [features] diff --git a/neqo-common/src/udp.rs b/neqo-common/src/udp.rs index aad8ae1e9..d2b4bb919 100644 --- a/neqo-common/src/udp.rs +++ b/neqo-common/src/udp.rs @@ -123,9 +123,10 @@ impl Socket { #[cfg(test)] mod tests { - use std::time::Duration; + use std::{time::Duration, task::Poll, pin::Pin}; use tokio::time::sleep; + use futures::{future::FutureExt, Future}; use super::*; use crate::{IpTos, IpTosDscp, IpTosEcn}; @@ -137,6 +138,12 @@ mod tests { let receiver_addr: SocketAddr = "127.0.0.1:0".parse().unwrap(); let receiver = Socket::bind(receiver_addr)?; println!("receiver bind"); + futures::future::poll_fn(|cx| { + let mut p = std::pin::pin!(receiver.readable()); + assert!(p.as_mut().poll(cx).is_pending()); + Poll::Ready(()) + }).await; + println!("receiver polled pending"); sleep(Duration::from_millis(100)).await; @@ -156,8 +163,8 @@ mod tests { sleep(Duration::from_millis(100)).await; - // receiver.readable().await?; - // println!("readable"); + receiver.readable().await?; + println!("readable"); let received_datagram = receiver .recv(&receiver_addr) .expect("receive to succeed")