Hello, I'm trying to test a basic iroh setup which is just a direct 1-host 1-client setup. I have the following in my test:
#[tokio::test]
async fn send_recv() {
const PAYLOAD: [u8; 8] = [1,2,3,4,5,6,7,8];
let (server, server_addr) = Node::host().await.unwrap();
// Needed so discovery doesn't fail
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
tokio::join!{
async {
let mut client = Node::connect(server_addr).await.unwrap();
client.write(&PAYLOAD).await.unwrap();
client // return this so it isn't dropped
},
async move {
let mut server = server.await.unwrap();
let recv = server.read().await.unwrap();
assert_eq!(PAYLOAD, recv.as_slice());
}
};
}
Node::host is as follows:
pub async fn host() -> Result<(impl Future<Output = Result<Self, HostError>>, NodeId), HostError> {
let endpoint = Endpoint::builder()
.alpns(vec![ALPN.to_vec()])
.discovery_n0()
.bind().await?;
let id = endpoint.node_id();
let s = async move {
let conn = endpoint.accept().await
.expect("endpoint closed")
.await?;
println!("accepted");
let (send, recv) = conn.accept_bi().await?;
println!("accepted bi");
Ok(Self::new(send, recv, endpoint))
};
Ok((s, id))
}
If I remove (or reduce) the sleep that I marked in the first codeblock then the test fails. I assume this is due to needing adequate time to register the iroh node (however that works behind the scenes), but I feel like there should be some awaitable way to do that without sleep guesswork. Am I missing something here?
, iroh team member here ✌️ every now and then I look for iroh messages in other discords, but I don't actively watch this discord.