A fork of attic a self-hostable Nix Binary Cache server
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

server/chunking: Add a couple of test cases on buffer size boundaries

+18 -12
+18 -12
server/src/chunking/mod.rs
··· 90 90 /// Chunks and reconstructs a file. 91 91 #[test] 92 92 fn test_chunking_basic() { 93 - block_on(async move { 94 - let test_file = get_data(32 * 1024 * 1024); // 32 MiB 95 - let mut reconstructed_file = Vec::new(); 93 + fn case(size: usize) { 94 + block_on(async move { 95 + let test_file = get_data(size); // 32 MiB 96 + let mut reconstructed_file = Vec::new(); 96 97 97 - let cursor = Cursor::new(&test_file); 98 - let mut chunks = chunk_stream(cursor, 8 * 1024, 16 * 1024, 32 * 1024); 98 + let cursor = Cursor::new(&test_file); 99 + let mut chunks = chunk_stream(cursor, 8 * 1024, 16 * 1024, 32 * 1024); 99 100 100 - while let Some(chunk) = chunks.next().await { 101 - let chunk = chunk.unwrap(); 102 - eprintln!("Got a {}-byte chunk", chunk.len()); 103 - reconstructed_file.extend(chunk); 104 - } 101 + while let Some(chunk) = chunks.next().await { 102 + let chunk = chunk.unwrap(); 103 + eprintln!("Got a {}-byte chunk", chunk.len()); 104 + reconstructed_file.extend(chunk); 105 + } 106 + 107 + assert_eq!(reconstructed_file, test_file); 108 + }); 109 + } 105 110 106 - assert_eq!(reconstructed_file, test_file); 107 - }); 111 + case(32 * 1024 * 1024 - 1); 112 + case(32 * 1024 * 1024); 113 + case(32 * 1024 * 1024 + 1); 108 114 } 109 115 110 116 /// Returns some fake data.