From 6b599b3763a58d0cedb4205229cb042893f24f3d Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 22 Jun 2023 15:31:40 +0200 Subject: feat(tvix/store/fuse): add test reading large file Change-Id: Ic705d05909c59c764d68a730169e9cc2b2538d60 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8847 Autosubmit: flokli Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/store/src/fuse/tests.rs | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'tvix') diff --git a/tvix/store/src/fuse/tests.rs b/tvix/store/src/fuse/tests.rs index 6350c8fba482..1a53b9f5ddd1 100644 --- a/tvix/store/src/fuse/tests.rs +++ b/tvix/store/src/fuse/tests.rs @@ -15,6 +15,7 @@ use crate::tests::utils::{gen_blob_service, gen_directory_service, gen_pathinfo_ use crate::{proto, FUSE}; const BLOB_A_NAME: &str = "00000000000000000000000000000000-test"; +const BLOB_B_NAME: &str = "55555555555555555555555555555555-test"; const SYMLINK_NAME: &str = "11111111111111111111111111111111-test"; const SYMLINK_NAME2: &str = "44444444444444444444444444444444-test"; const DIRECTORY_WITH_KEEP_NAME: &str = "22222222222222222222222222222222-test"; @@ -67,6 +68,32 @@ fn populate_blob_a( path_info_service.put(path_info).expect("must succeed"); } +fn populate_blob_b( + blob_service: Arc, + _directory_service: Arc, + path_info_service: Arc, +) { + // Upload BLOB_B + let mut bw = blob_service.open_write(); + std::io::copy(&mut Cursor::new(fixtures::BLOB_B.to_vec()), &mut bw) + .expect("must succeed uploading"); + bw.close().expect("must succeed closing"); + + // Create a PathInfo for it + let path_info = PathInfo { + node: Some(proto::Node { + node: Some(proto::node::Node::File(FileNode { + name: BLOB_B_NAME.to_string(), + digest: fixtures::BLOB_B_DIGEST.to_vec(), + size: fixtures::BLOB_B.len() as u32, + executable: false, + })), + }), + ..Default::default() + }; + path_info_service.put(path_info).expect("must succeed"); +} + fn populate_symlink( _blob_service: Arc, _directory_service: Arc, @@ -301,6 +328,38 @@ fn read_file_at_root() { fuser_session.join() } +/// Ensure we can read a large file at the root +#[test] +fn read_large_file_at_root() { + // https://plume.benboeckel.net/~/JustAnotherBlog/skipping-tests-in-rust + if !std::path::Path::new("/dev/fuse").exists() { + eprintln!("skipping test"); + return; + } + let tmpdir = TempDir::new().unwrap(); + + let fuser_session = setup_and_mount(tmpdir.path(), populate_blob_b).expect("must succeed"); + + let p = tmpdir.path().join(BLOB_B_NAME); + { + // peek at the file metadata + let metadata = fs::metadata(&p).expect("must succeed"); + + assert!(metadata.is_file()); + assert!(metadata.permissions().readonly()); + assert_eq!(fixtures::BLOB_B.len() as u64, metadata.len()); + } + + // read the file contents + let data = fs::read(p).expect("must succeed"); + + // ensure size and contents match + assert_eq!(fixtures::BLOB_B.len(), data.len()); + assert_eq!(fixtures::BLOB_B.to_vec(), data); + + fuser_session.join() +} + /// Read the target of a symlink #[test] fn symlink_readlink() { -- cgit 1.4.1