diff --git a/Cargo.lock b/Cargo.lock index 8cb0c51cbc08..0547f2ed6388 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3634,7 +3634,6 @@ dependencies = [ "databend-common-meta-stoerr", "databend-common-meta-types", "databend-common-proto-conv", - "enumflags2", "fastrace", "futures", "log", @@ -3729,9 +3728,11 @@ dependencies = [ "databend-common-meta-sled-store", "databend-common-meta-stoerr", "databend-common-meta-types", + "databend-common-tracing", "fastrace", "log", "tempfile", + "test-harness", ] [[package]] diff --git a/src/meta/embedded/Cargo.toml b/src/meta/embedded/Cargo.toml index 409f65faa64b..3a8c26de6e06 100644 --- a/src/meta/embedded/Cargo.toml +++ b/src/meta/embedded/Cargo.toml @@ -23,12 +23,14 @@ databend-common-meta-raft-store = { workspace = true } databend-common-meta-sled-store = { workspace = true } databend-common-meta-stoerr = { workspace = true } databend-common-meta-types = { workspace = true } +databend-common-tracing = { workspace = true } fastrace = { workspace = true } log = { workspace = true } tempfile = "3.4.0" [dev-dependencies] anyhow = { workspace = true } +test-harness = "0.1.1" [lints] workspace = true diff --git a/src/meta/embedded/tests/it/main.rs b/src/meta/embedded/tests/it/main.rs index ad20d7e03657..7b742d84e580 100644 --- a/src/meta/embedded/tests/it/main.rs +++ b/src/meta/embedded/tests/it/main.rs @@ -16,3 +16,4 @@ mod kv_api_impl; mod schema_api_impl; +mod testing; diff --git a/src/meta/embedded/tests/it/schema_api_impl.rs b/src/meta/embedded/tests/it/schema_api_impl.rs index 0baf123f63ea..0df52bbdb762 100644 --- a/src/meta/embedded/tests/it/schema_api_impl.rs +++ b/src/meta/embedded/tests/it/schema_api_impl.rs @@ -13,12 +13,14 @@ // limitations under the License. use async_trait::async_trait; -use databend_common_base::base::tokio; use databend_common_meta_api::BackgroundApiTestSuite; use databend_common_meta_api::SchemaApiTestSuite; use databend_common_meta_api::ShareApiTestSuite; use databend_common_meta_embedded::MetaEmbedded; use databend_common_meta_kvapi::kvapi; +use test_harness::test; + +use crate::testing::embedded_meta_test_harness; #[derive(Clone)] pub struct MetaEmbeddedBuilder {} @@ -33,7 +35,9 @@ impl kvapi::ApiBuilder for MetaEmbeddedBuilder { unimplemented!("embedded meta does not support cluster mode") } } -#[tokio::test(flavor = "multi_thread", worker_threads = 1)] + +#[test(harness = embedded_meta_test_harness)] +#[fastrace::trace] async fn test_meta_embedded() -> anyhow::Result<()> { SchemaApiTestSuite::test_single_node(MetaEmbeddedBuilder {}).await?; ShareApiTestSuite::test_single_node_share(MetaEmbeddedBuilder {}).await?; diff --git a/src/meta/embedded/tests/it/testing.rs b/src/meta/embedded/tests/it/testing.rs new file mode 100644 index 000000000000..789d531c889d --- /dev/null +++ b/src/meta/embedded/tests/it/testing.rs @@ -0,0 +1,59 @@ +// Copyright 2021 Datafuse Labs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use std::collections::BTreeMap; +use std::sync::Once; + +use databend_common_base::base::tokio; +use databend_common_tracing::closure_name; +use databend_common_tracing::init_logging; +use databend_common_tracing::Config; +use fastrace::prelude::*; + +pub fn embedded_meta_test_harness(test: F) +where + F: FnOnce() -> Fut + 'static, + Fut: std::future::Future> + Send + 'static, +{ + setup_test(); + + let rt = tokio::runtime::Builder::new_multi_thread() + .worker_threads(3) + .enable_all() + .build() + .unwrap(); + let root = Span::root(closure_name::(), SpanContext::random()); + let test = test().in_span(root); + rt.block_on(test).unwrap(); + + shutdown_test(); +} + +fn setup_test() { + static INIT: Once = Once::new(); + INIT.call_once(|| { + let t = tempfile::tempdir().expect("create temp dir to sled db"); + databend_common_meta_sled_store::init_temp_sled_db(t); + + let mut config = Config::new_testing(); + config.file.prefix_filter = "".to_string(); + + let guards = init_logging("embedded_meta_unittests", &config, BTreeMap::new()); + Box::leak(Box::new(guards)); + }); +} + +fn shutdown_test() { + fastrace::flush(); +} diff --git a/src/meta/kvapi/src/kvapi/api.rs b/src/meta/kvapi/src/kvapi/api.rs index 4370defe4186..45aff27edeb5 100644 --- a/src/meta/kvapi/src/kvapi/api.rs +++ b/src/meta/kvapi/src/kvapi/api.rs @@ -92,6 +92,8 @@ pub trait KVApi: Send + Sync { ); } + debug!("mget: keys: {:?}; values: {:?}", keys, seq_values); + Ok(seq_values) } diff --git a/src/meta/raft-store/src/state_machine/sm.rs b/src/meta/raft-store/src/state_machine/sm.rs index 75d1672d62a4..58e25cd5fa68 100644 --- a/src/meta/raft-store/src/state_machine/sm.rs +++ b/src/meta/raft-store/src/state_machine/sm.rs @@ -476,9 +476,10 @@ impl StateMachine { condition: &Vec, ) -> Result { for cond in condition { - debug!(condition :% =(cond); "txn_execute_condition"); + let res = self.txn_execute_one_condition(txn_tree, cond)?; + debug!(condition :% =(cond), res=res; "txn_execute_condition"); - if !self.txn_execute_one_condition(txn_tree, cond)? { + if !res { return Ok(false); } }