2010YOUY01 commented on code in PR #27325:
URL: https://github.com/apache/datafusion/pull/27325#discussion_r4572323158
##########
datafusion/fuzz/tests/suites/limit.rs:
##########
@@ -10,54 +10,85 @@ use arrow::datatypes::SchemaRef;
use arrow::util::pretty::pretty_format_batches;
use datafusion::datasource::MemTable;
use datafusion::prelude::SessionContext;
+use datafusion_common::Result;
use datafusion_common::assert_contains;
-use rand::{Rng, rng};
+use rand::rngs::StdRng;
+use rand::{Rng, SeedableRng};
use std::sync::Arc;
+use test_utils::fuzz::{FuzzTest, RunConfig};
use test_utils::stagger_batch;
-#[tokio::test]
-async fn test_sort_topk_i32() {
- run_limit_fuzz_test(SortedData::new_i32).await
-}
+const SIZES: [usize; 4] = [10, 1_0000, 10_000, 100_000];
-#[tokio::test]
-async fn test_sort_topk_f64() {
- run_limit_fuzz_test(SortedData::new_f64).await
+/// Runs TopK on random data of one type. Case seed `k` selects the input size
+/// `SIZES[k % SIZES.len()]` and the data seed `k / SIZES.len()`.
+pub(crate) struct LimitFuzzer {
+ name: &'static str,
+ make_data: fn(usize, &mut StdRng) -> SortedData,
}
-#[tokio::test]
-async fn test_sort_topk_str() {
- run_limit_fuzz_test(SortedData::new_str).await
+impl LimitFuzzer {
+ /// Runs each input size once. Each run uses a new random run seed.
+ pub(crate) fn run_config(&self) -> RunConfig {
+ RunConfig {
+ run_seed: None,
+ max_cases: Some(SIZES.len()),
Review Comment:
This can be some constant like 100, as long as total run time for this test
is reasonable
##########
datafusion/fuzz/tests/fuzz.rs:
##########
@@ -20,15 +20,20 @@ mod suites;
#[tokio::test(flavor = "multi_thread")]
async fn fuzz_tests() -> Result<()> {
let spill_pool = suites::spill_pool::SpillPoolFuzzer;
- let suites = [Suite::new(
+ let suites = std::iter::once(Suite::new(
Review Comment:
Let's break them into separate UTs, so the test runner can schedule them on
multiple threads:
```
// Fuzz test runners.
//
// Each suite is a separate test so the test runner can schedule suites in
parallel.
#[tokio::test(flavor = "multi_thread")]
async fn spill_pool_scenario() -> Result<()> {
run_suite(
&suites::spill_pool::SpillPoolFuzzer,
RunConfig {
run_seed: Some(0),
max_cases: Some(1000),
time_limit: None,
cases_per_dataset: 1000,
},
)
.await
}
#[tokio::test]
async fn key_range_bitmap_union() -> Result<()> {
run_suite(
&suites::key_range_bitmap::KeyRangeBitmapFuzzer,
RunConfig {
run_seed: Some(0),
max_cases: Some(10000),
time_limit: None,
cases_per_dataset: 10000,
},
)
.await
}
```
##########
datafusion/fuzz/tests/suites/limit.rs:
##########
@@ -10,54 +10,85 @@ use arrow::datatypes::SchemaRef;
use arrow::util::pretty::pretty_format_batches;
use datafusion::datasource::MemTable;
use datafusion::prelude::SessionContext;
+use datafusion_common::Result;
use datafusion_common::assert_contains;
-use rand::{Rng, rng};
+use rand::rngs::StdRng;
+use rand::{Rng, SeedableRng};
use std::sync::Arc;
+use test_utils::fuzz::{FuzzTest, RunConfig};
use test_utils::stagger_batch;
-#[tokio::test]
-async fn test_sort_topk_i32() {
- run_limit_fuzz_test(SortedData::new_i32).await
-}
+const SIZES: [usize; 4] = [10, 1_0000, 10_000, 100_000];
-#[tokio::test]
-async fn test_sort_topk_f64() {
- run_limit_fuzz_test(SortedData::new_f64).await
+/// Runs TopK on random data of one type. Case seed `k` selects the input size
+/// `SIZES[k % SIZES.len()]` and the data seed `k / SIZES.len()`.
+pub(crate) struct LimitFuzzer {
+ name: &'static str,
+ make_data: fn(usize, &mut StdRng) -> SortedData,
}
-#[tokio::test]
-async fn test_sort_topk_str() {
- run_limit_fuzz_test(SortedData::new_str).await
+impl LimitFuzzer {
+ /// Runs each input size once. Each run uses a new random run seed.
+ pub(crate) fn run_config(&self) -> RunConfig {
+ RunConfig {
+ run_seed: None,
+ max_cases: Some(SIZES.len()),
+ time_limit: None,
+ cases_per_dataset: SIZES.len(),
+ }
+ }
}
-#[tokio::test]
-async fn test_sort_topk_i64str() {
- run_limit_fuzz_test(SortedData::new_i64str).await
-}
+impl FuzzTest for LimitFuzzer {
+ type Dataset = ();
+
+ fn name(&self) -> &str {
+ self.name
+ }
+
+ fn prepare_dataset(&self, _: u64) -> impl Future<Output = Result<()>> {
+ std::future::ready(Ok(()))
+ }
-/// Run TopK fuzz tests the specified input data with different
-/// different test functions so they can run in parallel)
-async fn run_limit_fuzz_test<F>(make_data: F)
-where
- F: Fn(usize) -> SortedData,
-{
- let mut rng = rng();
- for size in [10, 1_0000, 10_000, 100_000] {
- let data = make_data(size);
+ async fn run_case(&self, _: &(), case_seed: u64) -> Result<()> {
Review Comment:
I think this function's implementation should be:
1. use `case_seed` to choose random args
2. call `run_limit_test` with args generated in step 1
So we can simplify/remove many structures in the old implementation, that
was implemented as fuzzing driver, like
SIZES= [10, 100, 1000]
MAKE_DATA=[SortedData::new_i32,...]
And the `run_case` can sample them and run the validation.
##########
datafusion/fuzz/tests/suites/limit.rs:
##########
@@ -10,54 +10,85 @@ use arrow::datatypes::SchemaRef;
use arrow::util::pretty::pretty_format_batches;
use datafusion::datasource::MemTable;
use datafusion::prelude::SessionContext;
+use datafusion_common::Result;
use datafusion_common::assert_contains;
-use rand::{Rng, rng};
+use rand::rngs::StdRng;
+use rand::{Rng, SeedableRng};
use std::sync::Arc;
+use test_utils::fuzz::{FuzzTest, RunConfig};
use test_utils::stagger_batch;
-#[tokio::test]
-async fn test_sort_topk_i32() {
- run_limit_fuzz_test(SortedData::new_i32).await
-}
+const SIZES: [usize; 4] = [10, 1_0000, 10_000, 100_000];
-#[tokio::test]
-async fn test_sort_topk_f64() {
- run_limit_fuzz_test(SortedData::new_f64).await
+/// Runs TopK on random data of one type. Case seed `k` selects the input size
+/// `SIZES[k % SIZES.len()]` and the data seed `k / SIZES.len()`.
+pub(crate) struct LimitFuzzer {
+ name: &'static str,
+ make_data: fn(usize, &mut StdRng) -> SortedData,
}
-#[tokio::test]
-async fn test_sort_topk_str() {
- run_limit_fuzz_test(SortedData::new_str).await
+impl LimitFuzzer {
+ /// Runs each input size once. Each run uses a new random run seed.
+ pub(crate) fn run_config(&self) -> RunConfig {
+ RunConfig {
+ run_seed: None,
+ max_cases: Some(SIZES.len()),
+ time_limit: None,
+ cases_per_dataset: SIZES.len(),
+ }
+ }
}
-#[tokio::test]
-async fn test_sort_topk_i64str() {
- run_limit_fuzz_test(SortedData::new_i64str).await
-}
+impl FuzzTest for LimitFuzzer {
+ type Dataset = ();
+
+ fn name(&self) -> &str {
+ self.name
+ }
+
+ fn prepare_dataset(&self, _: u64) -> impl Future<Output = Result<()>> {
+ std::future::ready(Ok(()))
+ }
-/// Run TopK fuzz tests the specified input data with different
-/// different test functions so they can run in parallel)
-async fn run_limit_fuzz_test<F>(make_data: F)
-where
- F: Fn(usize) -> SortedData,
-{
- let mut rng = rng();
- for size in [10, 1_0000, 10_000, 100_000] {
- let data = make_data(size);
+ async fn run_case(&self, _: &(), case_seed: u64) -> Result<()> {
+ let n_sizes = SIZES.len() as u64;
+ let size = SIZES[(case_seed % n_sizes) as usize];
+ let mut rng = StdRng::seed_from_u64(case_seed / n_sizes);
+ let data = (self.make_data)(size, &mut rng);
// test various limits including some random ones
for limit in [1, 3, 7, 17, 10000, rng.random_range(1..size * 2)] {
// limit can be larger than the number of rows in the input
run_limit_test(limit, &data).await;
}
+ Ok(())
}
}
+pub(crate) static FUZZERS: [LimitFuzzer; 4] = [
Review Comment:
We can remove this as explained above.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]