From 80bba51cae1c1dcb12b7a36133f350333af30e70 Mon Sep 17 00:00:00 2001 From: WenyXu Date: Fri, 5 Jan 2024 13:38:17 +0000 Subject: [PATCH 1/2] feat: add `concurrent` and `buffer` input writer `FuzzInput` --- core/fuzz/fuzz_writer.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/core/fuzz/fuzz_writer.rs b/core/fuzz/fuzz_writer.rs index 866dfb718bb..3c9f003e739 100644 --- a/core/fuzz/fuzz_writer.rs +++ b/core/fuzz/fuzz_writer.rs @@ -32,11 +32,15 @@ const MAX_DATA_SIZE: usize = 16 * 1024 * 1024; #[derive(Debug, Clone)] struct FuzzInput { actions: Vec, + concurrent: usize, + buffer: usize, } impl Arbitrary<'_> for FuzzInput { fn arbitrary(u: &mut Unstructured<'_>) -> arbitrary::Result { let mut actions = vec![]; + let concurrent = u.int_in_range(0..=16)?; + let buffer = u.int_in_range(2 * 1024 * 1024..=8 * 1024 * 1024)?; let count = u.int_in_range(128..=1024)?; @@ -45,7 +49,11 @@ impl Arbitrary<'_> for FuzzInput { actions.push(WriteAction::Write(size)); } - Ok(FuzzInput { actions }) + Ok(FuzzInput { + actions, + concurrent, + buffer, + }) } } @@ -62,7 +70,11 @@ async fn fuzz_writer(op: Operator, input: FuzzInput) -> Result<()> { let checker = WriteChecker::new(total_size); - let mut writer = op.writer_with(&path).buffer(8 * 1024 * 1024).await?; + let mut writer = op + .writer_with(&path) + .buffer(input.buffer) + .concurrent(input.concurrent) + .await?; for chunk in checker.chunks() { writer.write(chunk.clone()).await?; From bee19871240907efde0aaaf0f7c0a271feb82030 Mon Sep 17 00:00:00 2001 From: WenyXu Date: Sat, 6 Jan 2024 04:57:33 +0000 Subject: [PATCH 2/2] chore: apply suggestions from CR --- core/fuzz/fuzz_writer.rs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/core/fuzz/fuzz_writer.rs b/core/fuzz/fuzz_writer.rs index 3c9f003e739..df40e84590a 100644 --- a/core/fuzz/fuzz_writer.rs +++ b/core/fuzz/fuzz_writer.rs @@ -32,15 +32,23 @@ const MAX_DATA_SIZE: usize = 16 * 1024 * 1024; #[derive(Debug, Clone)] struct FuzzInput { actions: Vec, - concurrent: usize, - buffer: usize, + buffer: Option, + concurrent: Option, } impl Arbitrary<'_> for FuzzInput { fn arbitrary(u: &mut Unstructured<'_>) -> arbitrary::Result { let mut actions = vec![]; - let concurrent = u.int_in_range(0..=16)?; - let buffer = u.int_in_range(2 * 1024 * 1024..=8 * 1024 * 1024)?; + let buffer = if u.int_in_range(0..=1)? == 1 { + Some(u.int_in_range(1..=8 * 1024 * 1024)?) + } else { + None + }; + let concurrent = if u.int_in_range(0..=1)? == 1 { + Some(u.int_in_range(0..=16)?) + } else { + None + }; let count = u.int_in_range(128..=1024)?; @@ -51,8 +59,8 @@ impl Arbitrary<'_> for FuzzInput { Ok(FuzzInput { actions, - concurrent, buffer, + concurrent, }) } } @@ -70,11 +78,15 @@ async fn fuzz_writer(op: Operator, input: FuzzInput) -> Result<()> { let checker = WriteChecker::new(total_size); - let mut writer = op - .writer_with(&path) - .buffer(input.buffer) - .concurrent(input.concurrent) - .await?; + let mut writer = op.writer_with(&path); + if let Some(buffer) = input.buffer { + writer = writer.buffer(buffer); + } + if let Some(concurrent) = input.concurrent { + writer = writer.concurrent(concurrent); + } + + let mut writer = writer.await?; for chunk in checker.chunks() { writer.write(chunk.clone()).await?;