Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement test harness via libtest-mimic instead #2517

Merged
merged 9 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bindings/haskell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ crate-type = ["cdylib"]
doc = false

[dependencies]
chrono = "0.4"
opendal.workspace = true
chrono = "0.4"
1 change: 0 additions & 1 deletion bindings/lua/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ license.workspace = true
repository.workspace = true
rust-version.workspace = true


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
Expand Down
7 changes: 6 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ services-cos = [
"reqsign?/reqwest_request",
]
services-dashmap = ["dep:dashmap"]
services-dropbox = []
services-fs = ["tokio/fs"]
services-ftp = ["dep:suppaftp", "dep:lazy-regex", "dep:bb8", "dep:async-tls"]
services-gcs = [
"dep:reqsign",
"reqsign?/services-google",
"reqsign?/reqwest_request",
]
services-dropbox = []
services-gdrive = []
services-ghac = []
services-hdfs = ["dep:hdrs"]
Expand Down Expand Up @@ -165,6 +165,10 @@ bench = false
harness = false
name = "ops"

[[test]]
harness = false
name = "behavior"

[dependencies]
anyhow = { version = "1.0.30", features = ["std"] }
async-compat = "0.2"
Expand Down Expand Up @@ -228,6 +232,7 @@ uuid = { version = "1", features = ["serde", "v4"] }
[dev-dependencies]
criterion = { version = "0.4", features = ["async", "async_tokio"] }
dotenvy = "0.15"
libtest-mimic = "0.6"
opentelemetry = { version = "0.19", default-features = false, features = [
"trace",
] }
Expand Down
9 changes: 8 additions & 1 deletion core/src/services/memory/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use std::collections::BTreeMap;
use std::collections::HashMap;
use std::fmt::Debug;
use std::sync::Arc;

use async_trait::async_trait;
Expand Down Expand Up @@ -64,11 +65,17 @@ impl Builder for MemoryBuilder {
/// Backend is used to serve `Accessor` support in memory.
pub type MemoryBackend = typed_kv::Backend<Adapter>;

#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Adapter {
inner: Arc<Mutex<BTreeMap<String, typed_kv::Value>>>,
}

impl Debug for Adapter {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("MemoryBackend").finish_non_exhaustive()
}
}

#[async_trait]
impl typed_kv::Adapter for Adapter {
fn info(&self) -> typed_kv::Info {
Expand Down
75 changes: 21 additions & 54 deletions core/tests/behavior/append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,35 @@
// specific language governing permissions and limitations
// under the License.

use std::vec;

use anyhow::Result;
use futures::io::BufReader;
use futures::io::Cursor;
use log::warn;
use opendal::EntryMode;
use opendal::ErrorKind;
use opendal::Operator;
use sha2::Digest;
use sha2::Sha256;

use super::utils::*;

/// Test services that meet the following capability:
///
/// - can_read
/// - can_write
/// - can_append
macro_rules! behavior_append_test {
($service:ident, $($(#[$meta:meta])* $test:ident),*,) => {
paste::item! {
$(
#[test]
$(
#[$meta]
)*
fn [<append_ $test >]() -> anyhow::Result<()> {
match OPERATOR.as_ref() {
Some(op) if op.info().can_read()
&& op.info().can_write()
&& op.info().can_append() => RUNTIME.block_on($crate::append::$test(op.clone())),
Some(_) => {
log::warn!("service {} doesn't support append, ignored", opendal::Scheme::$service);
Ok(())
},
None => {
Ok(())
}
}
}
)*
}
};
}
use crate::*;

#[macro_export]
macro_rules! behavior_append_tests {
($($service:ident),*) => {
$(
behavior_append_test!(
$service,

test_append_create_append,
test_append_with_dir_path,
test_append_with_cache_control,
test_append_with_content_type,
test_append_with_content_disposition,

test_appender_futures_copy,
test_fuzz_appender,
);
)*
};
pub fn behavior_append_tests(runtime: &Runtime, op: &Operator) -> Vec<Trial> {
let cap = op.info().capability();

if !(cap.read && cap.write && cap.append) {
return vec![];
}

async_trials!(
runtime,
op,
test_append_create_append,
test_append_with_dir_path,
test_append_with_cache_control,
test_append_with_content_type,
test_append_with_content_disposition,
test_appender_futures_copy,
test_fuzz_appender
)
}

/// Test append to a file must success.
Expand Down
88 changes: 26 additions & 62 deletions core/tests/behavior/blocking_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,30 @@
// under the License.

use anyhow::Result;
use opendal::BlockingOperator;
use opendal::ErrorKind;

use super::utils::*;

/// Test services that meet the following capability:
///
/// - can_read
/// - can_write
/// - can_copy
/// - can_blocking
macro_rules! behavior_blocking_copy_test {
($service:ident, $($(#[$meta:meta])* $test:ident),*,) => {
paste::item! {
$(
#[test]
$(
#[$meta]
)*
fn [<blocking_copy_ $test >]() -> anyhow::Result<()> {
match OPERATOR.as_ref() {
Some(op) if op.info().can_read()
&& op.info().can_write()
&& op.info().can_copy()
&& op.info().can_blocking() => $crate::blocking_copy::$test(op.blocking()),
Some(_) => {
log::warn!("service {} doesn't support blocking_copy, ignored", opendal::Scheme::$service);
Ok(())
},
None => {
Ok(())
}
}
}
)*
}
};
}

#[macro_export]
macro_rules! behavior_blocking_copy_tests {
($($service:ident),*) => {
$(
behavior_blocking_copy_test!(
$service,

test_copy_file,
test_copy_non_existing_source,
test_copy_source_dir,
test_copy_target_dir,
test_copy_self,
test_copy_nested,
test_copy_overwrite,
);
)*
};
use crate::*;

pub fn behavior_blocking_copy_tests(op: &Operator) -> Vec<Trial> {
let cap = op.info().capability();

if !(cap.read && cap.write && cap.copy && cap.blocking) {
return vec![];
}

blocking_trials!(
op,
test_blocking_copy_file,
test_blocking_copy_non_existing_source,
test_blocking_copy_source_dir,
test_blocking_copy_target_dir,
test_blocking_copy_self,
test_blocking_copy_nested,
test_blocking_copy_overwrite
)
}

/// Copy a file and test with stat.
pub fn test_copy_file(op: BlockingOperator) -> Result<()> {
pub fn test_blocking_copy_file(op: BlockingOperator) -> Result<()> {
let source_path = uuid::Uuid::new_v4().to_string();
let (source_content, _) = gen_bytes();

Expand All @@ -94,7 +58,7 @@ pub fn test_copy_file(op: BlockingOperator) -> Result<()> {
}

/// Copy a nonexistent source should return an error.
pub fn test_copy_non_existing_source(op: BlockingOperator) -> Result<()> {
pub fn test_blocking_copy_non_existing_source(op: BlockingOperator) -> Result<()> {
let source_path = uuid::Uuid::new_v4().to_string();
let target_path = uuid::Uuid::new_v4().to_string();

Expand All @@ -106,7 +70,7 @@ pub fn test_copy_non_existing_source(op: BlockingOperator) -> Result<()> {
}

/// Copy a dir as source should return an error.
pub fn test_copy_source_dir(op: BlockingOperator) -> Result<()> {
pub fn test_blocking_copy_source_dir(op: BlockingOperator) -> Result<()> {
let source_path = format!("{}/", uuid::Uuid::new_v4());
let target_path = uuid::Uuid::new_v4().to_string();

Expand All @@ -120,7 +84,7 @@ pub fn test_copy_source_dir(op: BlockingOperator) -> Result<()> {
}

/// Copy to a dir should return an error.
pub fn test_copy_target_dir(op: BlockingOperator) -> Result<()> {
pub fn test_blocking_copy_target_dir(op: BlockingOperator) -> Result<()> {
let source_path = uuid::Uuid::new_v4().to_string();
let (source_content, _) = gen_bytes();

Expand All @@ -141,7 +105,7 @@ pub fn test_copy_target_dir(op: BlockingOperator) -> Result<()> {
}

/// Copy a file to self should return an error.
pub fn test_copy_self(op: BlockingOperator) -> Result<()> {
pub fn test_blocking_copy_self(op: BlockingOperator) -> Result<()> {
let source_path = uuid::Uuid::new_v4().to_string();
let (source_content, _size) = gen_bytes();

Expand All @@ -157,7 +121,7 @@ pub fn test_copy_self(op: BlockingOperator) -> Result<()> {
}

/// Copy to a nested path, parent path should be created successfully.
pub fn test_copy_nested(op: BlockingOperator) -> Result<()> {
pub fn test_blocking_copy_nested(op: BlockingOperator) -> Result<()> {
let source_path = uuid::Uuid::new_v4().to_string();
let (source_content, _) = gen_bytes();

Expand All @@ -181,7 +145,7 @@ pub fn test_copy_nested(op: BlockingOperator) -> Result<()> {
}

/// Copy to a exist path should overwrite successfully.
pub fn test_copy_overwrite(op: BlockingOperator) -> Result<()> {
pub fn test_blocking_copy_overwrite(op: BlockingOperator) -> Result<()> {
let source_path = uuid::Uuid::new_v4().to_string();
let (source_content, _) = gen_bytes();

Expand Down
Loading