diff options
author | Florian Klink <flokli@flokli.de> | 2024-03-23T22·37+0100 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-03-24T20·03+0000 |
commit | fe6ae58ba5c16bbf8348c083a0b1b79635b39c53 (patch) | |
tree | 132150f2a1e89a4bacaf30846c9f43fc3f2a0776 /tvix/castore/src/blobservice/tests/utils.rs | |
parent | f5cf6592455d5178e829984c76f2df5037319272 (diff) |
feat(tvix/castore): add rstest-based BlobService tests r/7779
Change-Id: Ifae9c41e1e3fa5e96f9b7e188181a44650ff8a04 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11250 Autosubmit: flokli <flokli@flokli.de> Reviewed-by: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/castore/src/blobservice/tests/utils.rs')
-rw-r--r-- | tvix/castore/src/blobservice/tests/utils.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tvix/castore/src/blobservice/tests/utils.rs b/tvix/castore/src/blobservice/tests/utils.rs new file mode 100644 index 000000000000..706c4b5e4319 --- /dev/null +++ b/tvix/castore/src/blobservice/tests/utils.rs @@ -0,0 +1,41 @@ +use crate::blobservice::{BlobService, MemoryBlobService}; +use crate::proto::blob_service_client::BlobServiceClient; +use crate::proto::GRPCBlobServiceWrapper; +use crate::{blobservice::GRPCBlobService, proto::blob_service_server::BlobServiceServer}; +use tonic::transport::{Endpoint, Server, Uri}; + +/// Constructs and returns a gRPC BlobService. +/// The server part is a [MemoryBlobService], exposed via the +/// [GRPCBlobServiceWrapper], and connected through a DuplexStream +pub async fn make_grpc_blob_service_client() -> Box<dyn BlobService> { + let (left, right) = tokio::io::duplex(64); + + // spin up a server, which will only connect once, to the left side. + tokio::spawn(async { + let blob_service = Box::<MemoryBlobService>::default() as Box<dyn BlobService>; + + // spin up a new DirectoryService + let mut server = Server::builder(); + let router = server.add_service(BlobServiceServer::new(GRPCBlobServiceWrapper::new( + 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); + + Box::new(GRPCBlobService::from_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(), + ))) +} |