diff options
author | Florian Klink <flokli@flokli.de> | 2023-10-08T09·31+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-10-08T21·53+0000 |
commit | c847cc32d99d214a8454df0d0c17c5f6ad9e6bd8 (patch) | |
tree | f6704f18db8546d35bfdb1eb68945f12a6e76071 /tvix/castore/src/utils.rs | |
parent | e778a33710c01d1320e2cd36c0ebcf668ea0fcc4 (diff) |
refactor(tvix/castore): move tests to grpc client, rm tonic-mock r/6735
Similar to gen_directorysvc_grpc_client, introduce a gen_blobsvc_grpc_client function that provides a gRPC client connected to a blobservice. The test is update to use that client to test against, rather than the server trait, removing the last usage of tonic_mock, so it's removed as well. Fixes b/243. Change-Id: If746e8600588da247eb53a63b70fe72f139e9e77 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9564 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su> Reviewed-by: Connor Brewster <cbrewster@hey.com> Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/castore/src/utils.rs')
-rw-r--r-- | tvix/castore/src/utils.rs | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/tvix/castore/src/utils.rs b/tvix/castore/src/utils.rs index 1444351a5644..d9a967598841 100644 --- a/tvix/castore/src/utils.rs +++ b/tvix/castore/src/utils.rs @@ -12,8 +12,10 @@ 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, GRPCDirectoryServiceWrapper, + directory_service_server::DirectoryServiceServer, GRPCBlobServiceWrapper, + GRPCDirectoryServiceWrapper, }, }; @@ -34,9 +36,8 @@ pin_project! { } } -/// This will spawn the a gRPC server with a DirectoryService client, and -/// connect a gRPC DirectoryService client. -/// The client is returned. +/// 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<Channel> { let (left, right) = tokio::io::duplex(64); @@ -69,3 +70,38 @@ pub(crate) async fn gen_directorysvc_grpc_client() -> DirectoryServiceClient<Cha grpc_client } + +/// 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<Channel> { + 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::from( + 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); + let grpc_client = 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(), + ); + + grpc_client +} |