refactor(tvix/store/pathinfo/grpc): simplify pingpong
We already have the same code in make_grpc_path_info_service_client. Change-Id: Ibcd60831af8a061a2c3bb2f960f52a43d06cf6fa Reviewed-on: https://cl.tvl.fyi/c/depot/+/11615 Reviewed-by: Connor Brewster <cbrewster@hey.com> Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
2cdf8346a9
commit
73c848a18f
2 changed files with 7 additions and 76 deletions
|
@ -128,85 +128,16 @@ impl PathInfoService for GRPCPathInfoService {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::sync::Arc;
|
use crate::pathinfoservice::tests::make_grpc_path_info_service_client;
|
||||||
use std::time::Duration;
|
use crate::tests::fixtures;
|
||||||
|
|
||||||
use rstest::*;
|
|
||||||
use tempfile::TempDir;
|
|
||||||
use tokio::net::UnixListener;
|
|
||||||
use tokio_retry::strategy::ExponentialBackoff;
|
|
||||||
use tokio_retry::Retry;
|
|
||||||
use tokio_stream::wrappers::UnixListenerStream;
|
|
||||||
use tvix_castore::blobservice::BlobService;
|
|
||||||
use tvix_castore::directoryservice::DirectoryService;
|
|
||||||
|
|
||||||
use crate::pathinfoservice::MemoryPathInfoService;
|
|
||||||
use crate::proto::path_info_service_client::PathInfoServiceClient;
|
|
||||||
use crate::proto::GRPCPathInfoServiceWrapper;
|
|
||||||
use crate::tests::fixtures::{self, blob_service, directory_service};
|
|
||||||
|
|
||||||
use super::GRPCPathInfoService;
|
|
||||||
use super::PathInfoService;
|
|
||||||
|
|
||||||
/// This ensures connecting via gRPC works as expected.
|
/// This ensures connecting via gRPC works as expected.
|
||||||
#[rstest]
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_valid_unix_path_ping_pong(
|
async fn test_valid_unix_path_ping_pong() {
|
||||||
blob_service: Arc<dyn BlobService>,
|
let (_blob_service, _directory_service, path_info_service) =
|
||||||
directory_service: Arc<dyn DirectoryService>,
|
make_grpc_path_info_service_client().await;
|
||||||
) {
|
|
||||||
let tmpdir = TempDir::new().unwrap();
|
|
||||||
let socket_path = tmpdir.path().join("daemon");
|
|
||||||
|
|
||||||
let path_clone = socket_path.clone();
|
let path_info = path_info_service
|
||||||
|
|
||||||
// Spin up a server
|
|
||||||
tokio::spawn(async {
|
|
||||||
let uds = UnixListener::bind(path_clone).unwrap();
|
|
||||||
let uds_stream = UnixListenerStream::new(uds);
|
|
||||||
|
|
||||||
// spin up a new server
|
|
||||||
let mut server = tonic::transport::Server::builder();
|
|
||||||
let router = server.add_service(
|
|
||||||
crate::proto::path_info_service_server::PathInfoServiceServer::new(
|
|
||||||
GRPCPathInfoServiceWrapper::new(Box::new(MemoryPathInfoService::new(
|
|
||||||
blob_service,
|
|
||||||
directory_service,
|
|
||||||
))
|
|
||||||
as Box<dyn PathInfoService>),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
router.serve_with_incoming(uds_stream).await
|
|
||||||
});
|
|
||||||
|
|
||||||
// wait for the socket to be created
|
|
||||||
Retry::spawn(
|
|
||||||
ExponentialBackoff::from_millis(20).max_delay(Duration::from_secs(10)),
|
|
||||||
|| async {
|
|
||||||
if socket_path.exists() {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(())
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.expect("failed to wait for socket");
|
|
||||||
|
|
||||||
// prepare a client
|
|
||||||
let grpc_client = {
|
|
||||||
let url = url::Url::parse(&format!("grpc+unix://{}", socket_path.display()))
|
|
||||||
.expect("must parse");
|
|
||||||
let client = PathInfoServiceClient::new(
|
|
||||||
tvix_castore::tonic::channel_from_url(&url)
|
|
||||||
.await
|
|
||||||
.expect("must succeed"),
|
|
||||||
);
|
|
||||||
|
|
||||||
GRPCPathInfoService::from_client(client)
|
|
||||||
};
|
|
||||||
|
|
||||||
let path_info = grpc_client
|
|
||||||
.get(fixtures::DUMMY_PATH_DIGEST)
|
.get(fixtures::DUMMY_PATH_DIGEST)
|
||||||
.await
|
.await
|
||||||
.expect("must not be error");
|
.expect("must not be error");
|
||||||
|
|
|
@ -13,7 +13,7 @@ use crate::proto::PathInfo;
|
||||||
use crate::tests::fixtures::DUMMY_PATH_DIGEST;
|
use crate::tests::fixtures::DUMMY_PATH_DIGEST;
|
||||||
|
|
||||||
mod utils;
|
mod utils;
|
||||||
use self::utils::make_grpc_path_info_service_client;
|
pub use self::utils::make_grpc_path_info_service_client;
|
||||||
|
|
||||||
/// Convenience type alias batching all three servives together.
|
/// Convenience type alias batching all three servives together.
|
||||||
#[allow(clippy::upper_case_acronyms)]
|
#[allow(clippy::upper_case_acronyms)]
|
||||||
|
|
Loading…
Reference in a new issue