Skip to content

Commit

Permalink
chore: add logging for embedded meta test (#16384)
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer authored Sep 4, 2024
1 parent bfab76d commit 0ad9fdc
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions src/meta/embedded/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/meta/embedded/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@

mod kv_api_impl;
mod schema_api_impl;
mod testing;
8 changes: 6 additions & 2 deletions src/meta/embedded/tests/it/schema_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -33,7 +35,9 @@ impl kvapi::ApiBuilder<MetaEmbedded> 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?;
Expand Down
59 changes: 59 additions & 0 deletions src/meta/embedded/tests/it/testing.rs
Original file line number Diff line number Diff line change
@@ -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<F, Fut>(test: F)
where
F: FnOnce() -> Fut + 'static,
Fut: std::future::Future<Output = anyhow::Result<()>> + 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::<F>(), 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();
}
2 changes: 2 additions & 0 deletions src/meta/kvapi/src/kvapi/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ pub trait KVApi: Send + Sync {
);
}

debug!("mget: keys: {:?}; values: {:?}", keys, seq_values);

Ok(seq_values)
}

Expand Down
5 changes: 3 additions & 2 deletions src/meta/raft-store/src/state_machine/sm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,10 @@ impl StateMachine {
condition: &Vec<TxnCondition>,
) -> Result<bool, MetaStorageError> {
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);
}
}
Expand Down

0 comments on commit 0ad9fdc

Please sign in to comment.