about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-06-22T13·31+0200
committerclbot <clbot@tvl.fyi>2023-06-30T12·35+0000
commit6b599b3763a58d0cedb4205229cb042893f24f3d (patch)
treef4c8432d6731f62f7e6d43c692f2a92c8291c6c7 /tvix
parent7fbf874f1c530db159b24859050a6d3e5fcd8075 (diff)
feat(tvix/store/fuse): add test reading large file r/6371
Change-Id: Ic705d05909c59c764d68a730169e9cc2b2538d60
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8847
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix')
-rw-r--r--tvix/store/src/fuse/tests.rs59
1 files changed, 59 insertions, 0 deletions
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<dyn BlobService>,
+    _directory_service: Arc<dyn DirectoryService>,
+    path_info_service: Arc<dyn PathInfoService>,
+) {
+    // 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<dyn BlobService>,
     _directory_service: Arc<dyn DirectoryService>,
@@ -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() {