mirror of
https://github.com/zhaofengli/attic.git
synced 2024-12-15 17:50:57 +00:00
server/chunking: Add a couple of test cases on buffer size boundaries
This commit is contained in:
parent
49bd872153
commit
19111317f7
1 changed files with 18 additions and 12 deletions
|
@ -90,21 +90,27 @@ mod tests {
|
|||
/// Chunks and reconstructs a file.
|
||||
#[test]
|
||||
fn test_chunking_basic() {
|
||||
block_on(async move {
|
||||
let test_file = get_data(32 * 1024 * 1024); // 32 MiB
|
||||
let mut reconstructed_file = Vec::new();
|
||||
fn case(size: usize) {
|
||||
block_on(async move {
|
||||
let test_file = get_data(size); // 32 MiB
|
||||
let mut reconstructed_file = Vec::new();
|
||||
|
||||
let cursor = Cursor::new(&test_file);
|
||||
let mut chunks = chunk_stream(cursor, 8 * 1024, 16 * 1024, 32 * 1024);
|
||||
let cursor = Cursor::new(&test_file);
|
||||
let mut chunks = chunk_stream(cursor, 8 * 1024, 16 * 1024, 32 * 1024);
|
||||
|
||||
while let Some(chunk) = chunks.next().await {
|
||||
let chunk = chunk.unwrap();
|
||||
eprintln!("Got a {}-byte chunk", chunk.len());
|
||||
reconstructed_file.extend(chunk);
|
||||
}
|
||||
while let Some(chunk) = chunks.next().await {
|
||||
let chunk = chunk.unwrap();
|
||||
eprintln!("Got a {}-byte chunk", chunk.len());
|
||||
reconstructed_file.extend(chunk);
|
||||
}
|
||||
|
||||
assert_eq!(reconstructed_file, test_file);
|
||||
});
|
||||
assert_eq!(reconstructed_file, test_file);
|
||||
});
|
||||
}
|
||||
|
||||
case(32 * 1024 * 1024 - 1);
|
||||
case(32 * 1024 * 1024);
|
||||
case(32 * 1024 * 1024 + 1);
|
||||
}
|
||||
|
||||
/// Returns some fake data.
|
||||
|
|
Loading…
Reference in a new issue