diff --git a/tests/integration_tests/Cargo.toml b/tests/integration_tests/Cargo.toml index 8a6b86a22..96863abba 100644 --- a/tests/integration_tests/Cargo.toml +++ b/tests/integration_tests/Cargo.toml @@ -12,7 +12,7 @@ version = "0.1.0" bytes = "1.0" futures-util = "0.3" prost = "0.9" -tokio = {version = "1.0", features = ["fs", "macros", "rt-multi-thread", "net"]} +tokio = {version = "1.0", features = ["macros", "rt-multi-thread", "net"]} tonic = {path = "../../tonic"} [dev-dependencies] diff --git a/tests/integration_tests/tests/connect_info.rs b/tests/integration_tests/tests/connect_info.rs index 2a4cf7f10..cc57f6b6b 100644 --- a/tests/integration_tests/tests/connect_info.rs +++ b/tests/integration_tests/tests/connect_info.rs @@ -51,7 +51,7 @@ async fn getting_connect_info() { #[cfg(unix)] pub mod unix { - use std::{convert::TryFrom as _, path::Path}; + use std::convert::TryFrom as _; use futures_util::FutureExt; use tokio::{ @@ -86,12 +86,10 @@ pub mod unix { #[tokio::test] async fn getting_connect_info() { - let unix_socket_path = "/tmp/tonic/uds-integration-test"; - tokio::fs::create_dir_all(Path::new(unix_socket_path).parent().unwrap()) - .await - .unwrap(); + let mut unix_socket_path = std::env::temp_dir(); + unix_socket_path.push("uds-integration-test"); - let uds = UnixListener::bind(unix_socket_path).unwrap(); + let uds = UnixListener::bind(&unix_socket_path).unwrap(); let uds_stream = UnixListenerStream::new(uds); let service = test_server::TestServer::new(Svc {}); @@ -105,11 +103,12 @@ pub mod unix { .unwrap(); }); + // Take a copy before moving into the `service_fn` closure so that the closure + // can implement `FnMut`. + let path = unix_socket_path.clone(); let channel = Endpoint::try_from("http://[::]:50051") .unwrap() - .connect_with_connector(service_fn(move |_: Uri| { - UnixStream::connect(unix_socket_path) - })) + .connect_with_connector(service_fn(move |_: Uri| UnixStream::connect(path.clone()))) .await .unwrap(); @@ -120,8 +119,6 @@ pub mod unix { tx.send(()).unwrap(); jh.await.unwrap(); - // tokio's `UnixListener` does not cleanup the socket automatically - we need to manually - // remove the file at the end of the test. - tokio::fs::remove_file(unix_socket_path).await.unwrap(); + std::fs::remove_file(unix_socket_path).unwrap(); } }