Skip to content

Commit

Permalink
fixup! tests: add integration test for UdsConnectInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
agreen17 committed Jan 13, 2022
1 parent f0d3309 commit 288a9a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/integration_tests/Cargo.toml
Expand Up @@ -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]
Expand Down
21 changes: 9 additions & 12 deletions tests/integration_tests/tests/connect_info.rs
Expand Up @@ -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::{
Expand Down Expand Up @@ -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 {});
Expand All @@ -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();

Expand All @@ -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();
}
}

0 comments on commit 288a9a7

Please sign in to comment.