You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2023/10/18 13:52:59 UTC
[incubator-opendal] branch main updated: refactor(core/{fuzz,benches}): Migrate to OPENDANL_TEST (#3343)
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
The following commit(s) were added to refs/heads/main by this push:
new bf40d145d refactor(core/{fuzz,benches}): Migrate to OPENDANL_TEST (#3343)
bf40d145d is described below
commit bf40d145d075f562848ac5b8d38709fe2fac57ea
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Wed Oct 18 21:52:54 2023 +0800
refactor(core/{fuzz,benches}): Migrate to OPENDANL_TEST (#3343)
* refactor(core/fuzz): Migrate to OPENDANL_TEST
Signed-off-by: Xuanwo <gi...@xuanwo.io>
* exclude benches/edge/fuzz from behavior test
Signed-off-by: Xuanwo <gi...@xuanwo.io>
* Migrate benches
Signed-off-by: Xuanwo <gi...@xuanwo.io>
---------
Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
.github/scripts/behavior_test/plan.py | 8 +++++++-
core/benches/README.md | 6 ++++++
core/benches/ops/read.rs | 15 ++++-----------
core/benches/ops/utils.rs | 35 +++++++++--------------------------
core/benches/ops/write.rs | 11 ++---------
core/fuzz/README.md | 4 ++--
core/fuzz/fuzz_reader.rs | 2 +-
core/fuzz/fuzz_writer.rs | 2 +-
core/fuzz/utils.rs | 24 ++++++++----------------
9 files changed, 40 insertions(+), 67 deletions(-)
diff --git a/.github/scripts/behavior_test/plan.py b/.github/scripts/behavior_test/plan.py
index ff3f5ae25..69397f67f 100755
--- a/.github/scripts/behavior_test/plan.py
+++ b/.github/scripts/behavior_test/plan.py
@@ -104,7 +104,13 @@ def calculate_hint(changed_files):
hint.all_service = True
# core affected
- if p.startswith("core/") and not p.startswith("core/src/services/"):
+ if (
+ p.startswith("core/")
+ and not p.startswith("core/benches/")
+ and not p.startswith("core/edge/")
+ and not p.startswith("core/fuzz/")
+ and not p.startswith("core/src/services/")
+ ):
hint.core = True
hint.binding_java = True
hint.all_service = True
diff --git a/core/benches/README.md b/core/benches/README.md
index e3ab65f6e..5161962a7 100644
--- a/core/benches/README.md
+++ b/core/benches/README.md
@@ -1,5 +1,11 @@
# OpenDAL Benchmarks
+Running benchmark
+
+```shell
+OPENDAL_TEST=memory cargo bench
+```
+
Build flamegraph:
```shell
diff --git a/core/benches/ops/read.rs b/core/benches/ops/read.rs
index e33db0b50..3be87ce38 100644
--- a/core/benches/ops/read.rs
+++ b/core/benches/ops/read.rs
@@ -25,17 +25,10 @@ use size::Size;
use super::utils::*;
pub fn bench(c: &mut Criterion) {
- for case in services() {
- if case.1.is_none() {
- println!("{} not set, ignore", case.0);
- continue;
- }
-
- let op = case.1.unwrap();
-
- bench_read_full(c, case.0, op.clone());
- bench_read_part(c, case.0, op.clone());
- bench_read_parallel(c, case.0, op.clone());
+ if let Some(op) = init_service() {
+ bench_read_full(c, op.info().scheme().into_static(), op.clone());
+ bench_read_part(c, op.info().scheme().into_static(), op.clone());
+ bench_read_parallel(c, op.info().scheme().into_static(), op.clone());
}
}
diff --git a/core/benches/ops/utils.rs b/core/benches/ops/utils.rs
index f8d9af2d7..4c6aa866a 100644
--- a/core/benches/ops/utils.rs
+++ b/core/benches/ops/utils.rs
@@ -16,6 +16,7 @@
// under the License.
use std::env;
+use std::str::FromStr;
use bytes::Bytes;
use once_cell::sync::Lazy;
@@ -25,13 +26,15 @@ use rand::prelude::*;
pub static TOKIO: Lazy<tokio::runtime::Runtime> =
Lazy::new(|| tokio::runtime::Runtime::new().expect("build tokio runtime"));
-fn service<AB: Builder>() -> Option<Operator> {
- let test_key = format!("opendal_{}_test", AB::SCHEME).to_uppercase();
- if env::var(test_key).unwrap_or_default() != "on" {
+pub fn init_service() -> Option<Operator> {
+ let scheme = if let Ok(v) = env::var("OPENDAL_TEST") {
+ v
+ } else {
return None;
- }
+ };
+ let scheme = Scheme::from_str(&scheme).unwrap();
- let prefix = format!("opendal_{}_", AB::SCHEME);
+ let prefix = format!("opendal_{scheme}_");
let envs = env::vars()
.filter_map(move |(k, v)| {
k.to_lowercase()
@@ -40,27 +43,7 @@ fn service<AB: Builder>() -> Option<Operator> {
})
.collect();
- Some(
- Operator::from_map::<AB>(envs)
- .unwrap_or_else(|_| panic!("init {} must succeed", AB::SCHEME))
- .finish(),
- )
-}
-
-pub fn services() -> Vec<(&'static str, Option<Operator>)> {
- let _ = dotenvy::dotenv();
-
- vec![
- ("fs", service::<services::Fs>()),
- ("s3", service::<services::S3>()),
- ("memory", service::<services::Memory>()),
- #[cfg(feature = "services-mini-moka")]
- ("mini-moka", service::<services::MiniMoka>()),
- #[cfg(feature = "services-moka")]
- ("moka", service::<services::Moka>()),
- #[cfg(feature = "services-redis")]
- ("redis", service::<services::Redis>()),
- ]
+ Some(Operator::via_map(scheme, envs).unwrap_or_else(|_| panic!("init {scheme} must succeed")))
}
pub fn gen_bytes(rng: &mut ThreadRng, size: usize) -> Bytes {
diff --git a/core/benches/ops/write.rs b/core/benches/ops/write.rs
index 8b56f9fc6..2d9d98fd6 100644
--- a/core/benches/ops/write.rs
+++ b/core/benches/ops/write.rs
@@ -23,15 +23,8 @@ use size::Size;
use super::utils::*;
pub fn bench(c: &mut Criterion) {
- for case in services() {
- if case.1.is_none() {
- println!("{} not set, ignore", case.0);
- continue;
- }
-
- let op = case.1.unwrap();
-
- bench_write_once(c, case.0, op.clone());
+ if let Some(op) = init_service() {
+ bench_write_once(c, op.info().scheme().into_static(), op.clone());
}
}
diff --git a/core/fuzz/README.md b/core/fuzz/README.md
index a5b9add79..fc7d33b58 100644
--- a/core/fuzz/README.md
+++ b/core/fuzz/README.md
@@ -11,14 +11,14 @@ To run the fuzz tests, please copy the `.env.example`, which is at project root,
Take `fs` for example, we need to change to enable fuzz test on `fs` on `/tmp`.
```dotenv
-OPENDAL_FS_TEST=false
+OPENDAL_TEST=fs
OPENDAL_FS_ROOT=/path/to/dir
```
into
```dotenv
-OPENDAL_FS_TEST=on
+OPENDAL_TEST=fs
OPENDAL_FS_ROOT=/tmp
```
diff --git a/core/fuzz/fuzz_reader.rs b/core/fuzz/fuzz_reader.rs
index 7b13207bf..d6eb19c1c 100644
--- a/core/fuzz/fuzz_reader.rs
+++ b/core/fuzz/fuzz_reader.rs
@@ -257,7 +257,7 @@ fuzz_target!(|input: FuzzInput| {
let runtime = tokio::runtime::Runtime::new().expect("init runtime must succeed");
- for op in utils::init_services() {
+ if let Some(op) = utils::init_service() {
runtime.block_on(async {
fuzz_reader(op, input.clone())
.await
diff --git a/core/fuzz/fuzz_writer.rs b/core/fuzz/fuzz_writer.rs
index ff1eb0bdb..edd25ac26 100644
--- a/core/fuzz/fuzz_writer.rs
+++ b/core/fuzz/fuzz_writer.rs
@@ -128,7 +128,7 @@ fuzz_target!(|input: FuzzInput| {
let runtime = tokio::runtime::Runtime::new().expect("init runtime must succeed");
- for op in utils::init_services() {
+ if let Some(op) = utils::init_service() {
runtime.block_on(async {
fuzz_writer(op, input.clone())
.await
diff --git a/core/fuzz/utils.rs b/core/fuzz/utils.rs
index 8a6501843..37598fdb3 100644
--- a/core/fuzz/utils.rs
+++ b/core/fuzz/utils.rs
@@ -16,12 +16,18 @@
// under the License.
use std::env;
+use std::str::FromStr;
use opendal::Operator;
use opendal::Scheme;
-fn service(scheme: Scheme) -> Option<Operator> {
- let test_key = format!("opendal_{}_test", scheme).to_uppercase();
+pub fn init_service() -> Option<Operator> {
+ let scheme = if let Ok(v) = env::var("OPENDAL_TEST") {
+ v
+ } else {
+ return None;
+ };
+ let scheme = Scheme::from_str(&scheme).unwrap();
let args: Vec<String> = env::args().collect();
if args[0].ends_with(&scheme.to_string()) {
@@ -29,10 +35,6 @@ fn service(scheme: Scheme) -> Option<Operator> {
let _ = dotenvy::from_filename_override(format!(".{scheme}.env"));
}
- if env::var(test_key).unwrap_or_default() != "on" {
- return None;
- }
-
let prefix = format!("opendal_{}_", scheme);
let envs = env::vars()
.filter_map(move |(k, v)| {
@@ -44,13 +46,3 @@ fn service(scheme: Scheme) -> Option<Operator> {
Some(Operator::via_map(scheme, envs).unwrap_or_else(|_| panic!("init {} must succeed", scheme)))
}
-
-pub fn init_services() -> Vec<Operator> {
- let ops = vec![
- service(Scheme::Memory),
- service(Scheme::Fs),
- service(Scheme::S3),
- ];
-
- ops.into_iter().flatten().collect()
-}