Add more proper cleanup for the server
Some checks failed
Build library & run tests / build (unix) (push) Failing after 34s
Build library & run tests / build (tcp) (push) Successful in 35s
Build library & run tests / docs (push) Successful in 37s

This commit is contained in:
2024-06-25 11:39:07 +02:00
parent 267b741ac4
commit 84f7009ad2
3 changed files with 21 additions and 16 deletions

View File

@@ -73,9 +73,8 @@ async fn e2e() {
};
#[cfg(feature = "tcp")]
let address = format!("127.0.0.1:{}", 10000 + rand::random::<u64>() % 1000);
let server_task = tokio::spawn(TestProtocolServer::bind(TrivialServer, address.clone()));
// Wait for the server to start, the developer is responsible for this in production
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
let server = TestProtocolServer::bind(TrivialServer, address.clone()).await;
tokio::time::sleep(tokio::time::Duration::from_millis(10)).await; // Wait for the server to start
let client = TestProtocolClient::connect(address).await.unwrap();
assert_eq!(client.addition(2, 5).await.unwrap(), 7);
assert_eq!(
@@ -90,5 +89,5 @@ async fn e2e() {
"The number is 42"
);
client.void().await.unwrap();
server_task.abort();
server.close().await;
}