Skip to content

Commit

Permalink
fix ephemeral file tests
Browse files Browse the repository at this point in the history
Signed-off-by: Yuchen Liang <[email protected]>
  • Loading branch information
yliang412 committed Oct 10, 2024
1 parent 37aa047 commit 3c018b6
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions pageserver/src/tenant/ephemeral_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,22 @@ mod tests {
}

assert!(file.len() as usize == write_nbytes);
for i in 0..write_nbytes {
let align = virtual_file::get_io_buffer_alignment();

for i in (0..write_nbytes).step_by(align) {
assert_eq!(value_offsets[i], i.into_u64());
let buf = IoBufferMut::with_capacity(1);
let buf = IoBufferMut::with_capacity(align);
let (buf_slice, nread) = file
.read_exact_at_eof_ok(i.into_u64(), buf.slice_full(), &ctx)
.await
.unwrap();
let buf = buf_slice.into_inner();
assert_eq!(nread, 1);
assert_eq!(&buf, &content[i..i + 1]);
if i + align > write_nbytes {
assert_eq!(nread, i % align);
} else {
assert_eq!(nread, align);
}
assert_eq!(&buf, &content[i..(i + align).min(write_nbytes)]);
}

let file_contents =
Expand Down Expand Up @@ -436,6 +442,7 @@ mod tests {
file.write_raw(&content, &ctx).await.unwrap();

let test_read = |start: usize, len: usize| {
println!("cap={cap}, start={start}, len={len}");
let file = &file;
let ctx = &ctx;
let content = &content;
Expand All @@ -453,16 +460,17 @@ mod tests {
}
};

let align = virtual_file::get_io_buffer_alignment();
// completely within the file range
assert!(20 < cap, "test assumption");
test_read(10, 10).await;
assert!(align * 2 < cap, "test assumption");
test_read(align, align).await;
// border onto edge of file
test_read(cap - 10, 10).await;
test_read(cap - align, align).await;
// read across file and buffer
test_read(cap - 10, 20).await;
test_read(cap - align, align * 2).await;
// stay from start of buffer
test_read(cap, 10).await;
test_read(cap, align).await;
// completely within buffer
test_read(cap + 10, 10).await;
test_read(cap + align, align).await;
}
}

0 comments on commit 3c018b6

Please sign in to comment.