Skip to content

[test] apply the new test style to 'common/meta' #2791

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

Merged
merged 6 commits into from
Nov 16, 2021
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
6 changes: 4 additions & 2 deletions common/meta/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ edition = "2021"

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

[lib]
doctest = false
test = false

[dependencies]
common-base = {path = "../../base" }
common-datavalues = {path = "../../datavalues" }
Expand All @@ -16,8 +20,6 @@ common-meta-types = {path= "../types" }
common-planners = {path = "../../planners"}
common-tracing = { path = "../../tracing" }



anyhow = "1.0.45"
async-trait = "0.1"
futures = "0.3"
Expand Down
4 changes: 3 additions & 1 deletion common/meta/embedded/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ license = "Apache-2.0"
publish = false
edition = "2021"


[lib]
doctest = false
test = false

[dependencies]
# Workspace dependencies
Expand Down
5 changes: 0 additions & 5 deletions common/meta/embedded/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,4 @@ mod kv_api_impl;
mod meta_api_impl;
mod meta_embedded;

#[cfg(test)]
mod kv_api_impl_test;
#[cfg(test)]
mod meta_api_impl_test;

pub use meta_embedded::MetaEmbedded;
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

use common_base::tokio;
use common_meta_api::KVApiTestSuite;

use crate::meta_embedded::MetaEmbedded;
use common_meta_embedded::MetaEmbedded;

#[tokio::test]
async fn test_kv_write_read() -> anyhow::Result<()> {
Expand Down
16 changes: 16 additions & 0 deletions common/meta/embedded/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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.

mod kv_api_impl;
mod meta_api_impl;
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

use common_base::tokio;
use common_meta_api::MetaApiTestSuite;

use crate::MetaEmbedded;
use common_meta_embedded::MetaEmbedded;

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_meta_embedded_database_create_get_drop() -> anyhow::Result<()> {
Expand Down
4 changes: 4 additions & 0 deletions common/meta/flight/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ license = "Apache-2.0"
publish = false
edition = "2021"

[lib]
doctest = false
test = false

[dependencies] # In alphabetical order
# Workspace dependencies
common-arrow = {path = "../../arrow"}
Expand Down
4 changes: 0 additions & 4 deletions common/meta/flight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#[cfg(test)]
mod flight_client_test;

mod flight_client;
#[macro_use]
mod flight_action;
mod flight_client_conf;
pub(crate) mod tests;

pub mod impls;

Expand Down
17 changes: 0 additions & 17 deletions common/meta/flight/src/tests/mod.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use std::time::Duration;

use common_base::tokio;
use common_meta_api::MetaApi;
use common_meta_flight::MetaFlightClient;

use crate::tests::start_flight_server;
use crate::MetaFlightClient;
use crate::start_flight_server;

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_flight_client_action_timeout() {
Expand Down
18 changes: 18 additions & 0 deletions common/meta/flight/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.

mod flight_client;
mod flight_server;

pub use flight_server::start_flight_server;
4 changes: 4 additions & 0 deletions common/meta/raft-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ license = "Apache-2.0"
publish = false
edition = "2021"

[lib]
doctest = false
test = false

[dependencies]
common-arrow = {path = "../../arrow"}
common-exception = {path = "../../exception"}
Expand Down
7 changes: 0 additions & 7 deletions common/meta/raft-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,3 @@ pub mod log;
pub mod sled_key_spaces;
pub mod state;
pub mod state_machine;

#[macro_use]
#[cfg(test)]
mod testing;

#[cfg(test)]
mod raft_types_test;
3 changes: 0 additions & 3 deletions common/meta/raft-store/src/log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@

mod raft_log;

#[cfg(test)]
mod raft_log_test;

pub use raft_log::RaftLog;
3 changes: 0 additions & 3 deletions common/meta/raft-store/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
mod raft_state;
mod raft_state_kv;

#[cfg(test)]
mod raft_state_test;

pub use raft_state::RaftState;
pub use raft_state_kv::RaftStateKey;
pub use raft_state_kv::RaftStateValue;
7 changes: 1 addition & 6 deletions common/meta/raft-store/src/state_machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,12 @@ pub use table_lookup::TableLookupValue;

pub mod applied_state;
pub mod client_last_resp;
pub mod placement;
pub mod sm;
mod sm_kv_api_impl;
pub mod snapshot;
pub mod state_machine_meta;
pub mod table_lookup;

pub mod placement;
#[cfg(test)]
mod placement_test;
#[cfg(test)]
mod state_machine_test;

// will be accessed by other crate, can not cfg(test)
pub mod testing;
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ use async_raft::raft::EntryNormal;
use async_raft::raft::EntryPayload;
use async_raft::LogId;
use common_base::tokio;
use common_meta_raft_store::log::RaftLog;
use common_meta_types::Cmd;
use common_meta_types::LogEntry;

use crate::init_raft_store_ut;
use crate::log::RaftLog;
use crate::testing::new_raft_test_context;

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
Expand Down
20 changes: 20 additions & 0 deletions common/meta/raft-store/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.

mod log;
#[macro_use]
mod testing;
mod state;
mod state_machine;
mod types;
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
// limitations under the License.
use async_raft::storage::HardState;
use common_base::tokio;
use common_meta_raft_store::state::RaftState;

use crate::init_raft_store_ut;
use crate::state::RaftState;
use crate::testing::new_raft_test_context;

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ use async_raft::LogId;
use common_base::tokio;
use common_exception::ErrorCode;
use common_meta_api::KVApi;
use common_meta_raft_store::state_machine::testing::pretty_snapshot;
use common_meta_raft_store::state_machine::testing::pretty_snapshot_iter;
use common_meta_raft_store::state_machine::testing::snapshot_logs;
use common_meta_raft_store::state_machine::AppliedState;
use common_meta_raft_store::state_machine::SerializableSnapshot;
use common_meta_raft_store::state_machine::StateMachine;
use common_meta_types::Change;
use common_meta_types::Cmd;
use common_meta_types::KVMeta;
Expand All @@ -39,14 +45,10 @@ use maplit::hashmap;
use pretty_assertions::assert_eq;

use crate::init_raft_store_ut;
use crate::state_machine::testing::pretty_snapshot;
use crate::state_machine::testing::pretty_snapshot_iter;
use crate::state_machine::testing::snapshot_logs;
use crate::state_machine::AppliedState;
use crate::state_machine::SerializableSnapshot;
use crate::state_machine::StateMachine;
use crate::testing::new_raft_test_context;

mod placement;

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_state_machine_apply_non_dup_incr_seq() -> anyhow::Result<()> {
let (_log_guards, ut_span) = init_raft_store_ut!();
Expand Down Expand Up @@ -86,7 +88,7 @@ async fn test_state_machine_apply_incr_seq() -> anyhow::Result<()> {
let tc = new_raft_test_context();
let mut sm = StateMachine::open(&tc.raft_config, 1).await?;

let cases = crate::state_machine::testing::cases_incr_seq();
let cases = common_meta_raft_store::state_machine::testing::cases_incr_seq();

for (name, txid, k, want) in cases.iter() {
let resp = sm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::state_machine::placement::rand_n_from_m;
use common_meta_raft_store::state_machine::placement::rand_n_from_m;

#[test]
fn test_rand_n_from_m() -> anyhow::Result<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
// limitations under the License.

use common_base::GlobalSequence;
use common_meta_raft_store::config::RaftConfig;
use common_meta_sled_store::get_sled_db;
use common_meta_sled_store::sled;

use crate::config::RaftConfig;

pub struct RaftTestContext {
pub raft_config: RaftConfig,
pub db: sled::Db,
Expand Down
3 changes: 3 additions & 0 deletions common/meta/sled-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ license = "Apache-2.0"
publish = false
edition = "2021"

[lib]
doctest = false
test = false

[dependencies]
common-exception = {path = "../../exception"}
Expand Down
5 changes: 0 additions & 5 deletions common/meta/sled-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,3 @@ mod db;
mod sled_key_space;
mod sled_serde;
mod sled_tree;

#[cfg(test)]
mod sled_tree_test;
#[cfg(test)]
mod testing;
16 changes: 16 additions & 0 deletions common/meta/sled-store/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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.

mod sled_tree;
mod testing;
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ use async_raft::raft::EntryNormal;
use async_raft::raft::EntryPayload;
use common_base::tokio;
use common_base::GlobalSequence;
use common_meta_sled_store::get_sled_db;
use common_meta_sled_store::SledTree;
use common_meta_types::Cmd;
use common_meta_types::LogEntry;
use common_meta_types::LogId;
use common_meta_types::LogIndex;
use common_meta_types::SeqV;

use crate::get_sled_db;
use crate::testing::fake_key_spaces::Files;
use crate::testing::fake_key_spaces::GenericKV;
use crate::testing::fake_key_spaces::Logs;
Expand All @@ -32,7 +33,6 @@ use crate::testing::fake_key_spaces::StateMachineMeta;
use crate::testing::fake_state_machine_meta::StateMachineMetaKey::Initialized;
use crate::testing::fake_state_machine_meta::StateMachineMetaKey::LastApplied;
use crate::testing::fake_state_machine_meta::StateMachineMetaValue;
use crate::SledTree;

/// 1. Open a temp sled::Db for all tests.
/// 2. Initialize a global tracing.
Expand All @@ -41,8 +41,8 @@ use crate::SledTree;
macro_rules! init_sled_ut {
() => {{
let t = tempfile::tempdir().expect("create temp dir to sled db");
$crate::init_temp_sled_db(t);

common_meta_sled_store::init_temp_sled_db(t);
common_tracing::init_default_ut_tracing();

let name = common_tracing::func_name!();
Expand Down
Loading