From 3c018b63649d1092d3a3c10b06a385bcbbab9a2c Mon Sep 17 00:00:00 2001 From: Yuchen Liang Date: Thu, 10 Oct 2024 14:47:00 +0000 Subject: [PATCH] fix ephemeral file tests Signed-off-by: Yuchen Liang --- pageserver/src/tenant/ephemeral_file.rs | 28 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/pageserver/src/tenant/ephemeral_file.rs b/pageserver/src/tenant/ephemeral_file.rs index d984122502273..60aa2dcb8583c 100644 --- a/pageserver/src/tenant/ephemeral_file.rs +++ b/pageserver/src/tenant/ephemeral_file.rs @@ -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 = @@ -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; @@ -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; } }