Skip to content

Commit 4d6b0ae

Browse files
authored
Merge pull request #2791 from PsiACE/meta-tests
[test] apply the new test style to 'common/meta'
2 parents af77199 + ac89f57 commit 4d6b0ae

38 files changed

+143
-97
lines changed

common/meta/api/Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ edition = "2021"
88

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

11+
[lib]
12+
doctest = false
13+
test = false
14+
1115
[dependencies]
1216
common-base = {path = "../../base" }
1317
common-datavalues = {path = "../../datavalues" }
@@ -16,8 +20,6 @@ common-meta-types = {path= "../types" }
1620
common-planners = {path = "../../planners"}
1721
common-tracing = { path = "../../tracing" }
1822

19-
20-
2123
anyhow = "1.0.45"
2224
async-trait = "0.1"
2325
futures = "0.3"

common/meta/embedded/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ license = "Apache-2.0"
77
publish = false
88
edition = "2021"
99

10-
10+
[lib]
11+
doctest = false
12+
test = false
1113

1214
[dependencies]
1315
# Workspace dependencies

common/meta/embedded/src/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,4 @@ mod kv_api_impl;
2424
mod meta_api_impl;
2525
mod meta_embedded;
2626

27-
#[cfg(test)]
28-
mod kv_api_impl_test;
29-
#[cfg(test)]
30-
mod meta_api_impl_test;
31-
3227
pub use meta_embedded::MetaEmbedded;

common/meta/embedded/src/kv_api_impl_test.rs renamed to common/meta/embedded/tests/it/kv_api_impl.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
use common_base::tokio;
1616
use common_meta_api::KVApiTestSuite;
17-
18-
use crate::meta_embedded::MetaEmbedded;
17+
use common_meta_embedded::MetaEmbedded;
1918

2019
#[tokio::test]
2120
async fn test_kv_write_read() -> anyhow::Result<()> {

common/meta/embedded/tests/it/main.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2021 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
mod kv_api_impl;
16+
mod meta_api_impl;

common/meta/embedded/src/meta_api_impl_test.rs renamed to common/meta/embedded/tests/it/meta_api_impl.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
use common_base::tokio;
1616
use common_meta_api::MetaApiTestSuite;
17-
18-
use crate::MetaEmbedded;
17+
use common_meta_embedded::MetaEmbedded;
1918

2019
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
2120
async fn test_meta_embedded_database_create_get_drop() -> anyhow::Result<()> {

common/meta/flight/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ license = "Apache-2.0"
66
publish = false
77
edition = "2021"
88

9+
[lib]
10+
doctest = false
11+
test = false
12+
913
[dependencies] # In alphabetical order
1014
# Workspace dependencies
1115
common-arrow = {path = "../../arrow"}

common/meta/flight/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#[cfg(test)]
16-
mod flight_client_test;
17-
1815
mod flight_client;
1916
#[macro_use]
2017
mod flight_action;
2118
mod flight_client_conf;
22-
pub(crate) mod tests;
2319

2420
pub mod impls;
2521

common/meta/flight/src/tests/mod.rs

-17
This file was deleted.

common/meta/flight/src/flight_client_test.rs renamed to common/meta/flight/tests/it/flight_client.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use std::time::Duration;
1616

1717
use common_base::tokio;
1818
use common_meta_api::MetaApi;
19+
use common_meta_flight::MetaFlightClient;
1920

20-
use crate::tests::start_flight_server;
21-
use crate::MetaFlightClient;
21+
use crate::start_flight_server;
2222

2323
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
2424
async fn test_flight_client_action_timeout() {

common/meta/flight/tests/it/main.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2021 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
mod flight_client;
16+
mod flight_server;
17+
18+
pub use flight_server::start_flight_server;

common/meta/raft-store/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ license = "Apache-2.0"
77
publish = false
88
edition = "2021"
99

10+
[lib]
11+
doctest = false
12+
test = false
13+
1014
[dependencies]
1115
common-arrow = {path = "../../arrow"}
1216
common-exception = {path = "../../exception"}

common/meta/raft-store/src/lib.rs

-7
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,3 @@ pub mod log;
1717
pub mod sled_key_spaces;
1818
pub mod state;
1919
pub mod state_machine;
20-
21-
#[macro_use]
22-
#[cfg(test)]
23-
mod testing;
24-
25-
#[cfg(test)]
26-
mod raft_types_test;

common/meta/raft-store/src/log/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,4 @@
1414

1515
mod raft_log;
1616

17-
#[cfg(test)]
18-
mod raft_log_test;
19-
2017
pub use raft_log::RaftLog;

common/meta/raft-store/src/state/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
mod raft_state;
1717
mod raft_state_kv;
1818

19-
#[cfg(test)]
20-
mod raft_state_test;
21-
2219
pub use raft_state::RaftState;
2320
pub use raft_state_kv::RaftStateKey;
2421
pub use raft_state_kv::RaftStateValue;

common/meta/raft-store/src/state_machine/mod.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,12 @@ pub use table_lookup::TableLookupValue;
2525

2626
pub mod applied_state;
2727
pub mod client_last_resp;
28+
pub mod placement;
2829
pub mod sm;
2930
mod sm_kv_api_impl;
3031
pub mod snapshot;
3132
pub mod state_machine_meta;
3233
pub mod table_lookup;
3334

34-
pub mod placement;
35-
#[cfg(test)]
36-
mod placement_test;
37-
#[cfg(test)]
38-
mod state_machine_test;
39-
4035
// will be accessed by other crate, can not cfg(test)
4136
pub mod testing;

common/meta/raft-store/src/log/raft_log_test.rs renamed to common/meta/raft-store/tests/it/log.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ use async_raft::raft::EntryNormal;
1717
use async_raft::raft::EntryPayload;
1818
use async_raft::LogId;
1919
use common_base::tokio;
20+
use common_meta_raft_store::log::RaftLog;
2021
use common_meta_types::Cmd;
2122
use common_meta_types::LogEntry;
2223

2324
use crate::init_raft_store_ut;
24-
use crate::log::RaftLog;
2525
use crate::testing::new_raft_test_context;
2626

2727
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2021 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
mod log;
16+
#[macro_use]
17+
mod testing;
18+
mod state;
19+
mod state_machine;
20+
mod types;

common/meta/raft-store/src/state/raft_state_test.rs renamed to common/meta/raft-store/tests/it/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
// limitations under the License.
1414
use async_raft::storage::HardState;
1515
use common_base::tokio;
16+
use common_meta_raft_store::state::RaftState;
1617

1718
use crate::init_raft_store_ut;
18-
use crate::state::RaftState;
1919
use crate::testing::new_raft_test_context;
2020

2121
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]

common/meta/raft-store/src/state_machine/state_machine_test.rs renamed to common/meta/raft-store/tests/it/state_machine/mod.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ use async_raft::LogId;
2525
use common_base::tokio;
2626
use common_exception::ErrorCode;
2727
use common_meta_api::KVApi;
28+
use common_meta_raft_store::state_machine::testing::pretty_snapshot;
29+
use common_meta_raft_store::state_machine::testing::pretty_snapshot_iter;
30+
use common_meta_raft_store::state_machine::testing::snapshot_logs;
31+
use common_meta_raft_store::state_machine::AppliedState;
32+
use common_meta_raft_store::state_machine::SerializableSnapshot;
33+
use common_meta_raft_store::state_machine::StateMachine;
2834
use common_meta_types::Change;
2935
use common_meta_types::Cmd;
3036
use common_meta_types::KVMeta;
@@ -39,14 +45,10 @@ use maplit::hashmap;
3945
use pretty_assertions::assert_eq;
4046

4147
use crate::init_raft_store_ut;
42-
use crate::state_machine::testing::pretty_snapshot;
43-
use crate::state_machine::testing::pretty_snapshot_iter;
44-
use crate::state_machine::testing::snapshot_logs;
45-
use crate::state_machine::AppliedState;
46-
use crate::state_machine::SerializableSnapshot;
47-
use crate::state_machine::StateMachine;
4848
use crate::testing::new_raft_test_context;
4949

50+
mod placement;
51+
5052
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
5153
async fn test_state_machine_apply_non_dup_incr_seq() -> anyhow::Result<()> {
5254
let (_log_guards, ut_span) = init_raft_store_ut!();
@@ -86,7 +88,7 @@ async fn test_state_machine_apply_incr_seq() -> anyhow::Result<()> {
8688
let tc = new_raft_test_context();
8789
let mut sm = StateMachine::open(&tc.raft_config, 1).await?;
8890

89-
let cases = crate::state_machine::testing::cases_incr_seq();
91+
let cases = common_meta_raft_store::state_machine::testing::cases_incr_seq();
9092

9193
for (name, txid, k, want) in cases.iter() {
9294
let resp = sm

common/meta/raft-store/src/state_machine/placement_test.rs renamed to common/meta/raft-store/tests/it/state_machine/placement.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use crate::state_machine::placement::rand_n_from_m;
15+
use common_meta_raft_store::state_machine::placement::rand_n_from_m;
1616

1717
#[test]
1818
fn test_rand_n_from_m() -> anyhow::Result<()> {

common/meta/raft-store/src/testing.rs renamed to common/meta/raft-store/tests/it/testing.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
// limitations under the License.
1414

1515
use common_base::GlobalSequence;
16+
use common_meta_raft_store::config::RaftConfig;
1617
use common_meta_sled_store::get_sled_db;
1718
use common_meta_sled_store::sled;
1819

19-
use crate::config::RaftConfig;
20-
2120
pub struct RaftTestContext {
2221
pub raft_config: RaftConfig,
2322
pub db: sled::Db,

common/meta/sled-store/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ license = "Apache-2.0"
77
publish = false
88
edition = "2021"
99

10+
[lib]
11+
doctest = false
12+
test = false
1013

1114
[dependencies]
1215
common-exception = {path = "../../exception"}

common/meta/sled-store/src/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,3 @@ mod db;
3131
mod sled_key_space;
3232
mod sled_serde;
3333
mod sled_tree;
34-
35-
#[cfg(test)]
36-
mod sled_tree_test;
37-
#[cfg(test)]
38-
mod testing;
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2021 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
mod sled_tree;
16+
mod testing;

common/meta/sled-store/src/sled_tree_test.rs renamed to common/meta/sled-store/tests/it/sled_tree.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ use async_raft::raft::EntryNormal;
1717
use async_raft::raft::EntryPayload;
1818
use common_base::tokio;
1919
use common_base::GlobalSequence;
20+
use common_meta_sled_store::get_sled_db;
21+
use common_meta_sled_store::SledTree;
2022
use common_meta_types::Cmd;
2123
use common_meta_types::LogEntry;
2224
use common_meta_types::LogId;
2325
use common_meta_types::LogIndex;
2426
use common_meta_types::SeqV;
2527

26-
use crate::get_sled_db;
2728
use crate::testing::fake_key_spaces::Files;
2829
use crate::testing::fake_key_spaces::GenericKV;
2930
use crate::testing::fake_key_spaces::Logs;
@@ -32,7 +33,6 @@ use crate::testing::fake_key_spaces::StateMachineMeta;
3233
use crate::testing::fake_state_machine_meta::StateMachineMetaKey::Initialized;
3334
use crate::testing::fake_state_machine_meta::StateMachineMetaKey::LastApplied;
3435
use crate::testing::fake_state_machine_meta::StateMachineMetaValue;
35-
use crate::SledTree;
3636

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

45+
common_meta_sled_store::init_temp_sled_db(t);
4646
common_tracing::init_default_ut_tracing();
4747

4848
let name = common_tracing::func_name!();

0 commit comments

Comments
 (0)