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 all 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
4 changes: 2 additions & 2 deletions .github/workflows/service_test_hdfs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
working-directory: core
run: |
export CLASSPATH=$(find $HADOOP_HOME -iname "*.jar" | xargs echo | tr ' ' ':')
cargo nextest run services_hdfs --features services-hdfs
cargo test services_hdfs --features services-hdfs
env:
HADOOP_HOME: "/home/runner/hadoop-3.3.5"
LD_LIBRARY_PATH: ${{ env.JAVA_HOME }}/lib/server:${{ env.LD_LIBRARY_PATH }}
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
run: |
export CLASSPATH=$(find $HADOOP_HOME -iname "*.jar" | xargs echo | tr ' ' ':')

cargo nextest run services_hdfs --features services-hdfs
cargo test services_hdfs --features services-hdfs
env:
HADOOP_HOME: "/home/runner/hadoop-3.1.3"
LD_LIBRARY_PATH: ${{ env.JAVA_HOME }}/lib/server:${{ env.LD_LIBRARY_PATH }}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/service_test_rocksdb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ jobs:
uses: ./.github/actions/setup
with:
need-rocksdb: true
need-nextest: true

- name: Test
shell: bash
working-directory: core
run: cargo nextest run rocksdb --features services-rocksdb -j=1
run: cargo test rocksdb --features services-rocksdb -j=1
env:
OPENDAL_ROCKSDB_TEST: on
OPENDAL_ROCKSDB_ROOT: /
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/service_test_sled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ jobs:
- uses: actions/checkout@v3
- name: Setup Rust toolchain
uses: ./.github/actions/setup
with:
need-nextest: true
- name: Test
shell: bash
working-directory: core
run: cargo nextest run sled --features services-sled -j=1
run: cargo test sled --features services-sled -j=1
env:
RUST_BACKTRACE: full
RUST_LOG: debug
Expand Down
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
74 changes: 20 additions & 54 deletions core/tests/behavior/append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,34 @@
// 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(op: &Operator) -> Vec<Trial> {
let cap = op.info().capability();

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

async_trials!(
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
Loading