refactor(tvix/castore/tests): let gen_*_service return Boxes
Only convert to and reuse an Arc<…> where needed. Change-Id: I2c1bc69cca5a4a3ebd3bdb33d6e28e1f5fb86cb9 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10514 Tested-by: BuildkiteCI Autosubmit: flokli <flokli@flokli.de> Reviewed-by: raitobezarius <tvl@lahfa.xyz>
This commit is contained in:
parent
09a92b78d2
commit
597a6b6205
8 changed files with 63 additions and 37 deletions
|
@ -86,7 +86,9 @@ where
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::directoryservice::DirectoryService;
|
||||||
use crate::fixtures::{DIRECTORY_COMPLICATED, DIRECTORY_WITH_KEEP};
|
use crate::fixtures::{DIRECTORY_COMPLICATED, DIRECTORY_WITH_KEEP};
|
||||||
use crate::utils::gen_directory_service;
|
use crate::utils::gen_directory_service;
|
||||||
|
|
||||||
|
@ -94,7 +96,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_descend_to() {
|
async fn test_descend_to() {
|
||||||
let directory_service = gen_directory_service();
|
let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into();
|
||||||
|
|
||||||
let mut handle = directory_service.put_multiple_start();
|
let mut handle = directory_service.put_multiple_start();
|
||||||
handle
|
handle
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
|
use crate::blobservice::BlobService;
|
||||||
|
use crate::directoryservice::DirectoryService;
|
||||||
use crate::fixtures::*;
|
use crate::fixtures::*;
|
||||||
use crate::import::ingest_path;
|
use crate::import::ingest_path;
|
||||||
use crate::proto;
|
use crate::proto;
|
||||||
use crate::utils::{gen_blob_service, gen_directory_service};
|
use crate::utils::{gen_blob_service, gen_directory_service};
|
||||||
|
use std::sync::Arc;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
|
@ -10,6 +13,9 @@ use std::os::unix::ffi::OsStrExt;
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn symlink() {
|
async fn symlink() {
|
||||||
|
let blob_service: Arc<dyn BlobService> = gen_blob_service().into();
|
||||||
|
let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into();
|
||||||
|
|
||||||
let tmpdir = TempDir::new().unwrap();
|
let tmpdir = TempDir::new().unwrap();
|
||||||
|
|
||||||
std::fs::create_dir_all(&tmpdir).unwrap();
|
std::fs::create_dir_all(&tmpdir).unwrap();
|
||||||
|
@ -20,8 +26,8 @@ async fn symlink() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let root_node = ingest_path(
|
let root_node = ingest_path(
|
||||||
gen_blob_service(),
|
blob_service,
|
||||||
gen_directory_service(),
|
directory_service,
|
||||||
tmpdir.path().join("doesntmatter"),
|
tmpdir.path().join("doesntmatter"),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -38,15 +44,16 @@ async fn symlink() {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn single_file() {
|
async fn single_file() {
|
||||||
|
let blob_service: Arc<dyn BlobService> = gen_blob_service().into();
|
||||||
|
let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into();
|
||||||
|
|
||||||
let tmpdir = TempDir::new().unwrap();
|
let tmpdir = TempDir::new().unwrap();
|
||||||
|
|
||||||
std::fs::write(tmpdir.path().join("root"), HELLOWORLD_BLOB_CONTENTS).unwrap();
|
std::fs::write(tmpdir.path().join("root"), HELLOWORLD_BLOB_CONTENTS).unwrap();
|
||||||
|
|
||||||
let blob_service = gen_blob_service();
|
|
||||||
|
|
||||||
let root_node = ingest_path(
|
let root_node = ingest_path(
|
||||||
blob_service.clone(),
|
blob_service.clone(),
|
||||||
gen_directory_service(),
|
directory_service,
|
||||||
tmpdir.path().join("root"),
|
tmpdir.path().join("root"),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -69,6 +76,9 @@ async fn single_file() {
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn complicated() {
|
async fn complicated() {
|
||||||
|
let blob_service: Arc<dyn BlobService> = gen_blob_service().into();
|
||||||
|
let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into();
|
||||||
|
|
||||||
let tmpdir = TempDir::new().unwrap();
|
let tmpdir = TempDir::new().unwrap();
|
||||||
|
|
||||||
// File ``.keep`
|
// File ``.keep`
|
||||||
|
@ -80,9 +90,6 @@ async fn complicated() {
|
||||||
// File ``keep/.keep`
|
// File ``keep/.keep`
|
||||||
std::fs::write(tmpdir.path().join("keep").join(".keep"), vec![]).unwrap();
|
std::fs::write(tmpdir.path().join("keep").join(".keep"), vec![]).unwrap();
|
||||||
|
|
||||||
let blob_service = gen_blob_service();
|
|
||||||
let directory_service = gen_directory_service();
|
|
||||||
|
|
||||||
let root_node = ingest_path(
|
let root_node = ingest_path(
|
||||||
blob_service.clone(),
|
blob_service.clone(),
|
||||||
directory_service.clone(),
|
directory_service.clone(),
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
//! A crate containing constructors to provide instances of a BlobService and
|
//! A crate containing constructors to provide instances of a BlobService and
|
||||||
//! DirectoryService. Only used for testing purposes, but across crates.
|
//! DirectoryService. Only used for testing purposes, but across crates.
|
||||||
//! Should be removed once we have a better concept of a "Service registry".
|
//! Should be removed once we have a better concept of a "Service registry".
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use tonic::transport::{Channel, Endpoint, Server, Uri};
|
use tonic::transport::{Channel, Endpoint, Server, Uri};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -16,12 +14,12 @@ use crate::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn gen_blob_service() -> Arc<dyn BlobService> {
|
pub fn gen_blob_service() -> Box<dyn BlobService> {
|
||||||
Arc::new(MemoryBlobService::default())
|
Box::<MemoryBlobService>::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gen_directory_service() -> Arc<dyn DirectoryService> {
|
pub fn gen_directory_service() -> Box<dyn DirectoryService> {
|
||||||
Arc::new(MemoryDirectoryService::default())
|
Box::<MemoryDirectoryService>::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This will spawn the a gRPC server with a DirectoryService client, connect a
|
/// This will spawn the a gRPC server with a DirectoryService client, connect a
|
||||||
|
|
|
@ -220,8 +220,11 @@ where
|
||||||
mod test {
|
mod test {
|
||||||
use crate::nar::read_nar;
|
use crate::nar::read_nar;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use tokio_stream::StreamExt;
|
use tokio_stream::StreamExt;
|
||||||
|
use tvix_castore::blobservice::BlobService;
|
||||||
|
use tvix_castore::directoryservice::DirectoryService;
|
||||||
use tvix_castore::fixtures::{
|
use tvix_castore::fixtures::{
|
||||||
DIRECTORY_COMPLICATED, DIRECTORY_WITH_KEEP, EMPTY_BLOB_DIGEST, HELLOWORLD_BLOB_CONTENTS,
|
DIRECTORY_COMPLICATED, DIRECTORY_WITH_KEEP, EMPTY_BLOB_DIGEST, HELLOWORLD_BLOB_CONTENTS,
|
||||||
HELLOWORLD_BLOB_DIGEST,
|
HELLOWORLD_BLOB_DIGEST,
|
||||||
|
@ -235,8 +238,8 @@ mod test {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn single_symlink() {
|
async fn single_symlink() {
|
||||||
let blob_service = gen_blob_service();
|
let blob_service: Arc<dyn BlobService> = gen_blob_service().into();
|
||||||
let directory_service = gen_directory_service();
|
let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into();
|
||||||
|
|
||||||
let handle = tokio::runtime::Handle::current();
|
let handle = tokio::runtime::Handle::current();
|
||||||
|
|
||||||
|
@ -263,8 +266,8 @@ mod test {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn single_file() {
|
async fn single_file() {
|
||||||
let blob_service = gen_blob_service();
|
let blob_service: Arc<dyn BlobService> = gen_blob_service().into();
|
||||||
let directory_service = gen_directory_service();
|
let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into();
|
||||||
|
|
||||||
let handle = tokio::runtime::Handle::current();
|
let handle = tokio::runtime::Handle::current();
|
||||||
|
|
||||||
|
@ -299,8 +302,8 @@ mod test {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn complicated() {
|
async fn complicated() {
|
||||||
let blob_service = gen_blob_service();
|
let blob_service: Arc<dyn BlobService> = gen_blob_service().into();
|
||||||
let directory_service = gen_directory_service();
|
let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into();
|
||||||
|
|
||||||
let handle = tokio::runtime::Handle::current();
|
let handle = tokio::runtime::Handle::current();
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,12 @@ mod tests {
|
||||||
#[test_case("grpc+http://localhost/some-path", false; "grpc valid invalid host and path")]
|
#[test_case("grpc+http://localhost/some-path", false; "grpc valid invalid host and path")]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_from_addr_tokio(uri_str: &str, is_ok: bool) {
|
async fn test_from_addr_tokio(uri_str: &str, is_ok: bool) {
|
||||||
let resp = from_addr(uri_str, gen_blob_service(), gen_directory_service()).await;
|
let resp = from_addr(
|
||||||
|
uri_str,
|
||||||
|
gen_blob_service().into(),
|
||||||
|
gen_directory_service().into(),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
assert_eq!(resp.is_ok(), is_ok);
|
assert_eq!(resp.is_ok(), is_ok);
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,8 +151,8 @@ mod tests {
|
||||||
let router = server.add_service(
|
let router = server.add_service(
|
||||||
crate::proto::path_info_service_server::PathInfoServiceServer::new(
|
crate::proto::path_info_service_server::PathInfoServiceServer::new(
|
||||||
GRPCPathInfoServiceWrapper::new(Box::new(MemoryPathInfoService::new(
|
GRPCPathInfoServiceWrapper::new(Box::new(MemoryPathInfoService::new(
|
||||||
gen_blob_service(),
|
gen_blob_service().into(),
|
||||||
gen_directory_service(),
|
gen_directory_service().into(),
|
||||||
))
|
))
|
||||||
as Box<dyn PathInfoService>),
|
as Box<dyn PathInfoService>),
|
||||||
),
|
),
|
||||||
|
|
|
@ -22,8 +22,8 @@ fn gen_grpc_service(
|
||||||
let blob_service = gen_blob_service();
|
let blob_service = gen_blob_service();
|
||||||
let directory_service = gen_directory_service();
|
let directory_service = gen_directory_service();
|
||||||
Arc::new(GRPCPathInfoServiceWrapper::new(gen_pathinfo_service(
|
Arc::new(GRPCPathInfoServiceWrapper::new(gen_pathinfo_service(
|
||||||
blob_service,
|
blob_service.into(),
|
||||||
directory_service,
|
directory_service.into(),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,16 @@ use crate::tests::fixtures::*;
|
||||||
use crate::tests::utils::*;
|
use crate::tests::utils::*;
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::sync::Arc;
|
||||||
use tokio::io::sink;
|
use tokio::io::sink;
|
||||||
|
use tvix_castore::blobservice::BlobService;
|
||||||
|
use tvix_castore::directoryservice::DirectoryService;
|
||||||
use tvix_castore::proto as castorepb;
|
use tvix_castore::proto as castorepb;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn single_symlink() {
|
async fn single_symlink() {
|
||||||
|
let blob_service: Arc<dyn BlobService> = gen_blob_service().into();
|
||||||
|
let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into();
|
||||||
let mut buf: Vec<u8> = vec![];
|
let mut buf: Vec<u8> = vec![];
|
||||||
|
|
||||||
write_nar(
|
write_nar(
|
||||||
|
@ -18,8 +23,8 @@ async fn single_symlink() {
|
||||||
target: "/nix/store/somewhereelse".into(),
|
target: "/nix/store/somewhereelse".into(),
|
||||||
}),
|
}),
|
||||||
// don't put anything in the stores, as we don't actually do any requests.
|
// don't put anything in the stores, as we don't actually do any requests.
|
||||||
gen_blob_service(),
|
blob_service,
|
||||||
gen_directory_service(),
|
directory_service,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("must succeed");
|
.expect("must succeed");
|
||||||
|
@ -30,6 +35,9 @@ async fn single_symlink() {
|
||||||
/// Make sure the NARRenderer fails if a referred blob doesn't exist.
|
/// Make sure the NARRenderer fails if a referred blob doesn't exist.
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn single_file_missing_blob() {
|
async fn single_file_missing_blob() {
|
||||||
|
let blob_service: Arc<dyn BlobService> = gen_blob_service().into();
|
||||||
|
let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into();
|
||||||
|
|
||||||
let e = write_nar(
|
let e = write_nar(
|
||||||
sink(),
|
sink(),
|
||||||
&castorepb::node::Node::File(castorepb::FileNode {
|
&castorepb::node::Node::File(castorepb::FileNode {
|
||||||
|
@ -39,8 +47,8 @@ async fn single_file_missing_blob() {
|
||||||
executable: false,
|
executable: false,
|
||||||
}),
|
}),
|
||||||
// the blobservice is empty intentionally, to provoke the error.
|
// the blobservice is empty intentionally, to provoke the error.
|
||||||
gen_blob_service(),
|
blob_service,
|
||||||
gen_directory_service(),
|
directory_service,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect_err("must fail");
|
.expect_err("must fail");
|
||||||
|
@ -57,7 +65,7 @@ async fn single_file_missing_blob() {
|
||||||
/// than specified in the proto node.
|
/// than specified in the proto node.
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn single_file_wrong_blob_size() {
|
async fn single_file_wrong_blob_size() {
|
||||||
let blob_service = gen_blob_service();
|
let blob_service: Arc<dyn BlobService> = gen_blob_service().into();
|
||||||
|
|
||||||
// insert blob into the store
|
// insert blob into the store
|
||||||
let mut writer = blob_service.open_write().await;
|
let mut writer = blob_service.open_write().await;
|
||||||
|
@ -75,6 +83,7 @@ async fn single_file_wrong_blob_size() {
|
||||||
let bs = blob_service.clone();
|
let bs = blob_service.clone();
|
||||||
// Test with a root FileNode of a too big size
|
// Test with a root FileNode of a too big size
|
||||||
{
|
{
|
||||||
|
let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into();
|
||||||
let e = write_nar(
|
let e = write_nar(
|
||||||
sink(),
|
sink(),
|
||||||
&castorepb::node::Node::File(castorepb::FileNode {
|
&castorepb::node::Node::File(castorepb::FileNode {
|
||||||
|
@ -84,7 +93,7 @@ async fn single_file_wrong_blob_size() {
|
||||||
executable: false,
|
executable: false,
|
||||||
}),
|
}),
|
||||||
bs,
|
bs,
|
||||||
gen_directory_service(),
|
directory_service,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect_err("must fail");
|
.expect_err("must fail");
|
||||||
|
@ -100,6 +109,7 @@ async fn single_file_wrong_blob_size() {
|
||||||
let bs = blob_service.clone();
|
let bs = blob_service.clone();
|
||||||
// Test with a root FileNode of a too small size
|
// Test with a root FileNode of a too small size
|
||||||
{
|
{
|
||||||
|
let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into();
|
||||||
let e = write_nar(
|
let e = write_nar(
|
||||||
sink(),
|
sink(),
|
||||||
&castorepb::node::Node::File(castorepb::FileNode {
|
&castorepb::node::Node::File(castorepb::FileNode {
|
||||||
|
@ -109,7 +119,7 @@ async fn single_file_wrong_blob_size() {
|
||||||
executable: false,
|
executable: false,
|
||||||
}),
|
}),
|
||||||
bs,
|
bs,
|
||||||
gen_directory_service(),
|
directory_service,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect_err("must fail");
|
.expect_err("must fail");
|
||||||
|
@ -125,7 +135,8 @@ async fn single_file_wrong_blob_size() {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn single_file() {
|
async fn single_file() {
|
||||||
let blob_service = gen_blob_service();
|
let blob_service: Arc<dyn BlobService> = gen_blob_service().into();
|
||||||
|
let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into();
|
||||||
|
|
||||||
// insert blob into the store
|
// insert blob into the store
|
||||||
let mut writer = blob_service.open_write().await;
|
let mut writer = blob_service.open_write().await;
|
||||||
|
@ -149,7 +160,7 @@ async fn single_file() {
|
||||||
executable: false,
|
executable: false,
|
||||||
}),
|
}),
|
||||||
blob_service,
|
blob_service,
|
||||||
gen_directory_service(),
|
directory_service,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("must succeed");
|
.expect("must succeed");
|
||||||
|
@ -159,8 +170,8 @@ async fn single_file() {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_complicated() {
|
async fn test_complicated() {
|
||||||
let blob_service = gen_blob_service();
|
let blob_service: Arc<dyn BlobService> = gen_blob_service().into();
|
||||||
let directory_service = gen_directory_service();
|
let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into();
|
||||||
|
|
||||||
// put all data into the stores.
|
// put all data into the stores.
|
||||||
// insert blob into the store
|
// insert blob into the store
|
||||||
|
|
Loading…
Reference in a new issue