diff options
author | Florian Klink <flokli@flokli.de> | 2023-03-01T17·55+0100 |
---|---|---|
committer | flokli <flokli@flokli.de> | 2023-03-10T10·58+0000 |
commit | a4f6c4181aa7f975b1c3aad8d3fb30021388e014 (patch) | |
tree | ee2f0a3911503ccb66f29d5b47dbdd763c02b026 /tvix/store/src/proto | |
parent | 535e1b15ab457c9015baebf14bd7b50a38edadb4 (diff) |
feat(tvix/store): add new_temporary for all Sled services r/5934
This provides a service using /dev/shm, that's deleted once the reference is dropped. Refactor all tests to use these, which allows getting rid of most TempDir usage in the tests. The only place where we still use TempDir is in the importer tests, which work on a filesystem path. Change-Id: I08a950aa774bf9b46d9f5c92edf5efba36053242 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8193 Reviewed-by: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/store/src/proto')
-rw-r--r-- | tvix/store/src/proto/tests/grpc_blobservice.rs | 18 | ||||
-rw-r--r-- | tvix/store/src/proto/tests/grpc_directoryservice.rs | 17 | ||||
-rw-r--r-- | tvix/store/src/proto/tests/grpc_pathinfoservice.rs | 18 |
3 files changed, 21 insertions, 32 deletions
diff --git a/tvix/store/src/proto/tests/grpc_blobservice.rs b/tvix/store/src/proto/tests/grpc_blobservice.rs index 4ea367cbdc86..88eb21e30241 100644 --- a/tvix/store/src/proto/tests/grpc_blobservice.rs +++ b/tvix/store/src/proto/tests/grpc_blobservice.rs @@ -5,24 +5,20 @@ use crate::proto::blob_service_server::BlobService as GRPCBlobService; use crate::proto::{BlobChunk, GRPCBlobServiceWrapper, ReadBlobRequest, StatBlobRequest}; use crate::tests::fixtures::{BLOB_A, BLOB_A_DIGEST, BLOB_B, BLOB_B_DIGEST}; use crate::tests::utils::{gen_blob_service, gen_chunk_service}; -use std::path::Path; -use tempfile::TempDir; -fn gen_grpc_blob_service( - p: &Path, -) -> GRPCBlobServiceWrapper< +fn gen_grpc_blob_service() -> GRPCBlobServiceWrapper< impl BlobService + Send + Sync + Clone + 'static, impl ChunkService + Send + Sync + Clone + 'static, > { - let blob_service = gen_blob_service(p); - let chunk_service = gen_chunk_service(p); + let blob_service = gen_blob_service(); + let chunk_service = gen_chunk_service(); GRPCBlobServiceWrapper::new(blob_service, chunk_service) } /// Trying to read a non-existent blob should return a not found error. #[tokio::test] async fn not_found_read() { - let service = gen_grpc_blob_service(TempDir::new().unwrap().path()); + let service = gen_grpc_blob_service(); let resp = service .read(tonic::Request::new(ReadBlobRequest { @@ -37,7 +33,7 @@ async fn not_found_read() { /// Trying to stat a non-existent blob should return a not found error. #[tokio::test] async fn not_found_stat() { - let service = gen_grpc_blob_service(TempDir::new().unwrap().path()); + let service = gen_grpc_blob_service(); let resp = service .stat(tonic::Request::new(StatBlobRequest { @@ -55,7 +51,7 @@ async fn not_found_stat() { /// won't get split into multiple chunks. #[tokio::test] async fn put_read_stat() { - let service = gen_grpc_blob_service(TempDir::new().unwrap().path()); + let service = gen_grpc_blob_service(); // Send blob A. let put_resp = service @@ -117,7 +113,7 @@ async fn put_read_stat() { /// `read()` method. #[tokio::test] async fn put_read_stat_large() { - let service = gen_grpc_blob_service(TempDir::new().unwrap().path()); + let service = gen_grpc_blob_service(); // split up BLOB_B into BlobChunks containing 1K bytes each. let blob_b_blobchunks: Vec<BlobChunk> = BLOB_B diff --git a/tvix/store/src/proto/tests/grpc_directoryservice.rs b/tvix/store/src/proto/tests/grpc_directoryservice.rs index 6d9851111f17..464c25f33d75 100644 --- a/tvix/store/src/proto/tests/grpc_directoryservice.rs +++ b/tvix/store/src/proto/tests/grpc_directoryservice.rs @@ -5,15 +5,12 @@ use crate::proto::{Directory, DirectoryNode, SymlinkNode}; use crate::proto::{GRPCDirectoryServiceWrapper, GetDirectoryRequest}; use crate::tests::fixtures::{DIRECTORY_A, DIRECTORY_B, DIRECTORY_C}; use crate::tests::utils::gen_directory_service; -use std::path::Path; -use tempfile::TempDir; use tokio_stream::StreamExt; use tonic::Status; fn gen_grpc_service( - p: &Path, ) -> GRPCDirectoryServiceWrapper<impl DirectoryService + Send + Sync + Clone + 'static> { - let directory_service = gen_directory_service(p); + let directory_service = gen_directory_service(); GRPCDirectoryServiceWrapper::from(directory_service) } @@ -43,7 +40,7 @@ async fn get_directories<S: GRPCDirectoryService>( /// Trying to get a non-existent Directory should return a not found error. #[tokio::test] async fn not_found() { - let service = gen_grpc_service(TempDir::new().unwrap().path()); + let service = gen_grpc_service(); let resp = service .get(tonic::Request::new(GetDirectoryRequest { @@ -69,7 +66,7 @@ async fn not_found() { /// Put a Directory into the store, get it back. #[tokio::test] async fn put_get() { - let service = gen_grpc_service(TempDir::new().unwrap().path()); + let service = gen_grpc_service(); let streaming_request = tonic_mock::streaming_request(vec![DIRECTORY_A.clone()]); let put_resp = service @@ -98,7 +95,7 @@ async fn put_get() { /// Put multiple Directories into the store, and get them back #[tokio::test] async fn put_get_multiple() { - let service = gen_grpc_service(TempDir::new().unwrap().path()); + let service = gen_grpc_service(); // sending "b" (which refers to "a") without sending "a" first should fail. let put_resp = service @@ -151,7 +148,7 @@ async fn put_get_multiple() { /// Put multiple Directories into the store, and omit duplicates. #[tokio::test] async fn put_get_dedup() { - let service = gen_grpc_service(TempDir::new().unwrap().path()); + let service = gen_grpc_service(); // Send "A", then "C", which refers to "A" two times // Pretend we're a dumb client sending A twice. @@ -184,7 +181,7 @@ async fn put_get_dedup() { /// Trying to upload a Directory failing validation should fail. #[tokio::test] async fn put_reject_failed_validation() { - let service = gen_grpc_service(TempDir::new().unwrap().path()); + let service = gen_grpc_service(); // construct a broken Directory message that fails validation let broken_directory = Directory { @@ -208,7 +205,7 @@ async fn put_reject_failed_validation() { /// Trying to upload a Directory with wrong size should fail. #[tokio::test] async fn put_reject_wrong_size() { - let service = gen_grpc_service(TempDir::new().unwrap().path()); + let service = gen_grpc_service(); // Construct a directory referring to DIRECTORY_A, but with wrong size. let broken_parent_directory = Directory { diff --git a/tvix/store/src/proto/tests/grpc_pathinfoservice.rs b/tvix/store/src/proto/tests/grpc_pathinfoservice.rs index ce74711cb555..f74c3fda0213 100644 --- a/tvix/store/src/proto/tests/grpc_pathinfoservice.rs +++ b/tvix/store/src/proto/tests/grpc_pathinfoservice.rs @@ -9,8 +9,6 @@ use crate::tests::fixtures::DUMMY_OUTPUT_HASH; use crate::tests::utils::{ gen_blob_service, gen_chunk_service, gen_directory_service, gen_pathinfo_service, }; -use std::path::Path; -use tempfile::TempDir; use tonic::Request; /// generates a GRPCPathInfoService out of blob, chunk, directory and pathinfo services. @@ -18,13 +16,13 @@ use tonic::Request; /// We only interact with it via the PathInfo GRPC interface. /// It uses the NonCachingNARCalculationService NARCalculationService to /// calculate NARs. -fn gen_grpc_service(p: &Path) -> impl GRPCPathInfoService { +fn gen_grpc_service() -> impl GRPCPathInfoService { GRPCPathInfoServiceWrapper::new( - gen_pathinfo_service(p), + gen_pathinfo_service(), NonCachingNARCalculationService::new( - gen_blob_service(p), - gen_chunk_service(p), - gen_directory_service(p), + gen_blob_service(), + gen_chunk_service(), + gen_directory_service(), ), ) } @@ -32,8 +30,7 @@ fn gen_grpc_service(p: &Path) -> impl GRPCPathInfoService { /// Trying to get a non-existent PathInfo should return a not found error. #[tokio::test] async fn not_found() { - let tmpdir = TempDir::new().unwrap(); - let service = gen_grpc_service(tmpdir.path()); + let service = gen_grpc_service(); let resp = service .get(Request::new(GetPathInfoRequest { @@ -48,8 +45,7 @@ async fn not_found() { /// Put a PathInfo into the store, get it back. #[tokio::test] async fn put_get() { - let tmpdir = TempDir::new().unwrap(); - let service = gen_grpc_service(tmpdir.path()); + let service = gen_grpc_service(); let path_info = PathInfo { node: Some(Node { |