From 74023a07a4b3d8e99645217b04683c0e54e23be8 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Wed, 20 Mar 2024 22:36:02 +0200 Subject: refactor(tvix/castore/*): drop utils.rs and grpc directorysvc tests This drops pretty much all of castore/utils.rs. There were only two things left in there, both a bit messy and only used for tests: Some `gen_*_service()` helper functions. These can be expressed by `from_addr("memory://")`. The other thing was some plumbing code to test the gRPC layer, by exposing a in-memory implementation via gRPC, and then connecting to that channel via a gRPC client again. Previous CLs moved the connection setup code to {directory,blob}service::tests::utils, close to where we exercise them, the new rstest-based tests. The tests interacting directly on the gRPC types are removed, all scenarios that were in there show now be covered through the rstest ones on the trait level. Change-Id: I450ccccf983b4c62145a25d81c36a40846664814 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11223 Reviewed-by: Connor Brewster Tested-by: BuildkiteCI --- tvix/castore/src/utils.rs | 89 ----------------------------------------------- 1 file changed, 89 deletions(-) delete mode 100644 tvix/castore/src/utils.rs (limited to 'tvix/castore/src/utils.rs') diff --git a/tvix/castore/src/utils.rs b/tvix/castore/src/utils.rs deleted file mode 100644 index ca68f9f26c5a..000000000000 --- a/tvix/castore/src/utils.rs +++ /dev/null @@ -1,89 +0,0 @@ -//! A crate containing constructors to provide instances of a BlobService and -//! DirectoryService. Only used for testing purposes, but across crates. -//! Should be removed once we have a better concept of a "Service registry". -use tonic::transport::{Channel, Endpoint, Server, Uri}; - -use crate::{ - blobservice::{BlobService, MemoryBlobService}, - directoryservice::{DirectoryService, MemoryDirectoryService}, - proto::{ - blob_service_client::BlobServiceClient, blob_service_server::BlobServiceServer, - directory_service_client::DirectoryServiceClient, - directory_service_server::DirectoryServiceServer, GRPCBlobServiceWrapper, - GRPCDirectoryServiceWrapper, - }, -}; - -pub fn gen_blob_service() -> Box { - Box::::default() -} - -pub fn gen_directory_service() -> Box { - Box::::default() -} - -/// This will spawn the a gRPC server with a DirectoryService client, connect a -/// gRPC DirectoryService client and return it. -#[allow(dead_code)] -pub(crate) async fn gen_directorysvc_grpc_client() -> DirectoryServiceClient { - let (left, right) = tokio::io::duplex(64); - - // spin up a server, which will only connect once, to the left side. - tokio::spawn(async { - // spin up a new DirectoryService - let mut server = Server::builder(); - let router = server.add_service(DirectoryServiceServer::new( - GRPCDirectoryServiceWrapper::new(gen_directory_service()), - )); - - router - .serve_with_incoming(tokio_stream::once(Ok::<_, std::io::Error>(left))) - .await - }); - - // Create a client, connecting to the right side. The URI is unused. - let mut maybe_right = Some(right); - DirectoryServiceClient::new( - Endpoint::try_from("http://[::]:50051") - .unwrap() - .connect_with_connector(tower::service_fn(move |_: Uri| { - let right = maybe_right.take().unwrap(); - async move { Ok::<_, std::io::Error>(right) } - })) - .await - .unwrap(), - ) -} - -/// This will spawn the a gRPC server with a BlobService client, connect a -/// gRPC BlobService client and return it. -#[allow(dead_code)] -pub(crate) async fn gen_blobsvc_grpc_client() -> BlobServiceClient { - let (left, right) = tokio::io::duplex(64); - - // spin up a server, which will only connect once, to the left side. - tokio::spawn(async { - // spin up a new DirectoryService - let mut server = Server::builder(); - let router = server.add_service(BlobServiceServer::new(GRPCBlobServiceWrapper::new( - gen_blob_service(), - ))); - - router - .serve_with_incoming(tokio_stream::once(Ok::<_, std::io::Error>(left))) - .await - }); - - // Create a client, connecting to the right side. The URI is unused. - let mut maybe_right = Some(right); - BlobServiceClient::new( - Endpoint::try_from("http://[::]:50051") - .unwrap() - .connect_with_connector(tower::service_fn(move |_: Uri| { - let right = maybe_right.take().unwrap(); - async move { Ok::<_, std::io::Error>(right) } - })) - .await - .unwrap(), - ) -} -- cgit 1.4.1