Skip to content

Commit 56f4276

Browse files
authored
Merge pull request #2814 from PsiACE/metasrv-tests
[test] apply the new test style to databend-meta
2 parents de39934 + 7cc8b4a commit 56f4276

28 files changed

+143
-91
lines changed

metasrv/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
[[bin]]
1115
name = "databend-meta"
1216
path = "src/bin/metasrv.rs"

metasrv/src/any_error/mod.rs

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

1515
mod any_error_impl;
1616

17-
#[cfg(test)]
18-
mod any_error_test;
19-
2017
pub use any_error_impl::AnyError;

metasrv/src/api/http/v1/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,3 @@
1414

1515
pub mod config;
1616
pub mod health;
17-
18-
#[cfg(test)]
19-
mod config_test;
20-
#[cfg(test)]
21-
mod health_test;

metasrv/src/api/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@
1515
// The api module only used for internal communication, such as GRPC between cluster and the managed HTTP REST API.
1616

1717
mod flight_server;
18-
mod http;
18+
pub mod http;
1919
mod http_service;
2020
pub mod rpc;
2121

22-
#[cfg(test)]
23-
mod http_service_test;
24-
2522
pub use flight_server::FlightServer;
2623
pub use http_service::HttpService;

metasrv/src/configs/mod.rs

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

1515
pub mod config;
1616

17-
#[cfg(test)]
18-
mod config_test;
19-
2017
pub use config::Config;
18+
pub use config::DATABEND_COMMIT_VERSION;

metasrv/src/lib.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@ pub mod proto {
1919
include!(concat!(env!("OUT_DIR"), concat!("/meta.rs")));
2020
}
2121

22-
#[macro_use]
23-
pub mod tests;
24-
25-
mod any_error;
22+
pub mod any_error;
2623
pub mod api;
2724
pub mod configs;
2825
pub mod errors;
2926
pub mod executor;
3027
pub mod meta_service;
3128
pub mod metrics;
32-
mod store;
29+
pub mod store;
3330

3431
pub trait Opened {
3532
/// Return true if it is opened from a previous persistent state.

metasrv/src/meta_service/mod.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@ pub use network::Network;
2020
pub use raftmeta::MetaNode;
2121

2222
mod message;
23-
mod meta_leader;
23+
pub mod meta_leader;
2424
mod meta_node_kv_api_impl;
2525
pub mod meta_service_impl;
2626
pub mod network;
2727
pub mod raftmeta;
28-
29-
#[cfg(test)]
30-
mod meta_service_impl_test;
31-
#[cfg(test)]
32-
pub mod raftmeta_test;

metasrv/src/store/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,5 @@
1313
// limitations under the License.
1414

1515
mod meta_raft_store;
16-
#[cfg(test)]
17-
mod meta_raft_store_test;
1816

1917
pub use meta_raft_store::MetaRaftStore;

metasrv/src/any_error/any_error_test.rs renamed to metasrv/tests/it/any_error.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use std::error::Error;
1616
use std::fmt;
1717

1818
use anyhow::Context;
19-
20-
use crate::any_error::AnyError;
19+
use databend_meta::any_error::AnyError;
2120

2221
#[test]
2322
fn test_any_error() -> anyhow::Result<()> {

metasrv/src/api/http/v1/config_test.rs renamed to metasrv/tests/it/api/http/config.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*
1616
*/
1717
use common_base::tokio;
18+
use databend_meta::api::http::v1::config::config_handler;
19+
use databend_meta::configs::Config;
1820
use poem::get;
1921
use poem::http::Method;
2022
use poem::http::StatusCode;
@@ -25,9 +27,6 @@ use poem::Request;
2527
use poem::Route;
2628
use pretty_assertions::assert_eq;
2729

28-
use crate::api::http::v1::config::config_handler;
29-
use crate::configs::Config;
30-
3130
#[tokio::test]
3231
async fn test_config() -> common_exception::Result<()> {
3332
let conf = Config::empty();

metasrv/src/api/http/v1/health_test.rs renamed to metasrv/tests/it/api/http/health.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*
1616
*/
1717
use common_base::tokio;
18+
use databend_meta::api::http::v1::health::health_handler;
1819
use poem::get;
1920
use poem::http::Method;
2021
use poem::http::StatusCode;
@@ -24,8 +25,6 @@ use poem::Request;
2425
use poem::Route;
2526
use pretty_assertions::assert_eq;
2627

27-
use crate::api::http::v1::health::health_handler;
28-
2928
#[tokio::test]
3029
async fn test_health() -> common_exception::Result<()> {
3130
let cluster_router = Route::new().at("/v1/health", get(health_handler));

metasrv/tests/it/api/http/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2020 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+
pub mod config;
16+
pub mod health;

metasrv/src/api/http_service_test.rs renamed to metasrv/tests/it/api/http_service.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use std::io::Read;
1818
use common_base::tokio;
1919
use common_base::Stoppable;
2020
use common_exception::Result;
21+
use databend_meta::api::HttpService;
22+
use databend_meta::configs::Config;
2123

22-
use crate::api::HttpService;
23-
use crate::configs::Config;
2424
use crate::tests::tls_constants::TEST_CA_CERT;
2525
use crate::tests::tls_constants::TEST_CN_NAME;
2626
use crate::tests::tls_constants::TEST_SERVER_CERT;

metasrv/tests/it/api/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2020 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 http;
16+
mod http_service;

metasrv/src/configs/config_test.rs renamed to metasrv/tests/it/configs.rs

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

15-
use crate::configs::Config;
15+
use databend_meta::configs::Config;
1616

1717
#[test]
1818
fn test_fuse_commit_version() -> anyhow::Result<()> {
19-
let v = &crate::configs::config::DATABEND_COMMIT_VERSION;
19+
let v = &databend_meta::configs::DATABEND_COMMIT_VERSION;
2020
assert!(v.len() > 0);
2121
Ok(())
2222
}

metasrv/tests/flight/metasrv_flight_api.rs renamed to metasrv/tests/it/flight/metasrv_flight_api.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ use common_meta_types::SeqV;
2424
use common_meta_types::UpsertKVAction;
2525
use common_meta_types::UpsertKVActionReply;
2626
use common_tracing::tracing;
27-
use databend_meta::init_meta_ut;
28-
use databend_meta::tests::service::new_test_context;
29-
use databend_meta::tests::start_metasrv_with_context;
3027
use pretty_assertions::assert_eq;
3128
use tokio::time::Duration;
3229

30+
use crate::init_meta_ut;
31+
use crate::tests::service::new_test_context;
32+
use crate::tests::start_metasrv_with_context;
33+
3334
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
3435
async fn test_restart() -> anyhow::Result<()> {
3536
// Fix: Issue 1134 https://github.com/datafuselabs/databend/issues/1134
@@ -41,7 +42,7 @@ async fn test_restart() -> anyhow::Result<()> {
4142
let (_log_guards, ut_span) = init_meta_ut!();
4243
let _ent = ut_span.enter();
4344

44-
let (mut tc, addr) = databend_meta::tests::start_metasrv().await?;
45+
let (mut tc, addr) = crate::tests::start_metasrv().await?;
4546

4647
let client = MetaFlightClient::try_create(addr.as_str(), "root", "xxx").await?;
4748

@@ -99,7 +100,7 @@ async fn test_restart() -> anyhow::Result<()> {
99100

100101
// restart by opening existent meta db
101102
tc.config.raft_config.boot = false;
102-
databend_meta::tests::start_metasrv_with_context(&mut tc).await?;
103+
crate::tests::start_metasrv_with_context(&mut tc).await?;
103104
}
104105

105106
tokio::time::sleep(Duration::from_millis(10_000)).await;

metasrv/tests/flight/metasrv_flight_kv_api.rs renamed to metasrv/tests/it/flight/metasrv_flight_kv_api.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
use common_base::tokio;
1616
use common_meta_api::KVApiTestSuite;
1717
use common_meta_flight::MetaFlightClient;
18-
use databend_meta::init_meta_ut;
18+
19+
use crate::init_meta_ut;
1920

2021
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
2122
async fn test_kv_api_mget() -> anyhow::Result<()> {
2223
let (_log_guards, ut_span) = init_meta_ut!();
2324
let _ent = ut_span.enter();
2425

25-
let (_tc, addr) = databend_meta::tests::start_metasrv().await?;
26+
let (_tc, addr) = crate::tests::start_metasrv().await?;
2627

2728
let client = MetaFlightClient::try_create(addr.as_str(), "root", "xxx").await?;
2829

@@ -34,7 +35,7 @@ async fn test_kv_api_list() -> anyhow::Result<()> {
3435
let (_log_guards, ut_span) = init_meta_ut!();
3536
let _ent = ut_span.enter();
3637

37-
let (_tc, addr) = databend_meta::tests::start_metasrv().await?;
38+
let (_tc, addr) = crate::tests::start_metasrv().await?;
3839

3940
let client = MetaFlightClient::try_create(addr.as_str(), "root", "xxx").await?;
4041

@@ -46,7 +47,7 @@ async fn test_kv_api_delete() -> anyhow::Result<()> {
4647
let (_log_guards, ut_span) = init_meta_ut!();
4748
let _ent = ut_span.enter();
4849

49-
let (_tc, addr) = databend_meta::tests::start_metasrv().await?;
50+
let (_tc, addr) = crate::tests::start_metasrv().await?;
5051

5152
let client = MetaFlightClient::try_create(addr.as_str(), "root", "xxx").await?;
5253

@@ -58,7 +59,7 @@ async fn test_kv_api_update() -> anyhow::Result<()> {
5859
let (_log_guards, ut_span) = init_meta_ut!();
5960
let _ent = ut_span.enter();
6061

61-
let (_tc, addr) = databend_meta::tests::start_metasrv().await?;
62+
let (_tc, addr) = crate::tests::start_metasrv().await?;
6263

6364
let client = MetaFlightClient::try_create(addr.as_str(), "root", "xxx").await?;
6465

@@ -72,7 +73,7 @@ async fn test_kv_api_update_meta() -> anyhow::Result<()> {
7273
let (_log_guards, ut_span) = init_meta_ut!();
7374
let _ent = ut_span.enter();
7475

75-
let (_tc, addr) = databend_meta::tests::start_metasrv().await?;
76+
let (_tc, addr) = crate::tests::start_metasrv().await?;
7677

7778
let client = MetaFlightClient::try_create(addr.as_str(), "root", "xxx").await?;
7879

@@ -84,7 +85,7 @@ async fn test_kv_api_timeout() -> anyhow::Result<()> {
8485
let (_log_guards, ut_span) = init_meta_ut!();
8586
let _ent = ut_span.enter();
8687

87-
let (_tc, addr) = databend_meta::tests::start_metasrv().await?;
88+
let (_tc, addr) = crate::tests::start_metasrv().await?;
8889

8990
let client = MetaFlightClient::try_create(addr.as_str(), "root", "xxx").await?;
9091

@@ -96,7 +97,7 @@ async fn test_kv_api_write_read() -> anyhow::Result<()> {
9697
let (_log_guards, ut_span) = init_meta_ut!();
9798
let _ent = ut_span.enter();
9899

99-
let (_tc, addr) = databend_meta::tests::start_metasrv().await?;
100+
let (_tc, addr) = crate::tests::start_metasrv().await?;
100101

101102
let client = MetaFlightClient::try_create(addr.as_str(), "root", "xxx").await?;
102103

metasrv/tests/flight/metasrv_flight_meta_api.rs renamed to metasrv/tests/it/flight/metasrv_flight_meta_api.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
use common_base::tokio;
1616
use common_meta_api::MetaApiTestSuite;
1717
use common_meta_flight::MetaFlightClient;
18-
use databend_meta::init_meta_ut;
18+
19+
use crate::init_meta_ut;
1920

2021
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
2122
async fn test_meta_api_database_create_get_drop() -> anyhow::Result<()> {
2223
let (_log_guards, ut_span) = init_meta_ut!();
2324
let _ent = ut_span.enter();
2425

25-
let (_tc, addr) = databend_meta::tests::start_metasrv().await?;
26+
let (_tc, addr) = crate::tests::start_metasrv().await?;
2627

2728
let client = MetaFlightClient::try_create(addr.as_str(), "root", "xxx").await?;
2829

@@ -34,7 +35,7 @@ async fn test_meta_api_database_list() -> anyhow::Result<()> {
3435
let (_log_guards, ut_span) = init_meta_ut!();
3536
let _ent = ut_span.enter();
3637

37-
let (_tc, addr) = databend_meta::tests::start_metasrv().await?;
38+
let (_tc, addr) = crate::tests::start_metasrv().await?;
3839

3940
let client = MetaFlightClient::try_create(addr.as_str(), "root", "xxx").await?;
4041

@@ -46,7 +47,7 @@ async fn test_meta_api_table_create_get_drop() -> anyhow::Result<()> {
4647
let (_log_guards, ut_span) = init_meta_ut!();
4748
let _ent = ut_span.enter();
4849

49-
let (_tc, addr) = databend_meta::tests::start_metasrv().await?;
50+
let (_tc, addr) = crate::tests::start_metasrv().await?;
5051

5152
let client = MetaFlightClient::try_create(addr.as_str(), "root", "xxx").await?;
5253

@@ -58,7 +59,7 @@ async fn test_meta_api_table_list() -> anyhow::Result<()> {
5859
let (_log_guards, ut_span) = init_meta_ut!();
5960
let _ent = ut_span.enter();
6061

61-
let (_tc, addr) = databend_meta::tests::start_metasrv().await?;
62+
let (_tc, addr) = crate::tests::start_metasrv().await?;
6263

6364
let client = MetaFlightClient::try_create(addr.as_str(), "root", "xxx").await?;
6465

@@ -73,7 +74,7 @@ async fn test_meta_api_table_list() -> anyhow::Result<()> {
7374
async fn test_meta_api_flight_get_database_meta_ddl_table() -> anyhow::Result<()> {
7475
let (_log_guards, ut_span) = init_meta_ut!();
7576
let _ent = ut_span.enter();
76-
let (_tc, addr) = databend_meta::tests::start_metasrv().await?;
77+
let (_tc, addr) = crate::tests::start_metasrv().await?;
7778
let client = MetaFlightClient::try_create(addr.as_str(), "root", "xxx").await?;
7879
7980
let test_db = "db1";
@@ -151,7 +152,7 @@ async fn test_meta_api_flight_get_database_meta_ddl_table() -> anyhow::Result<()
151152
async fn test_meta_api_flight_get_database_meta_empty_db() -> anyhow::Result<()> {
152153
let (_log_guards, ut_span) = init_meta_ut!();
153154
let _ent = ut_span.enter();
154-
let (_tc, addr) = databend_meta::tests::start_metasrv().await?;
155+
let (_tc, addr) = crate::tests::start_metasrv().await?;
155156
let client = MetaFlightClient::try_create(addr.as_str(), "root", "xxx").await?;
156157
157158
// Empty Database
@@ -165,7 +166,7 @@ async fn test_meta_api_flight_get_database_meta_empty_db() -> anyhow::Result<()>
165166
async fn test_meta_api_flight_get_database_meta_ddl_db() -> anyhow::Result<()> {
166167
let (_log_guards, ut_span) = init_meta_ut!();
167168
let _ent = ut_span.enter();
168-
let (_tc, addr) = databend_meta::tests::start_metasrv().await?;
169+
let (_tc, addr) = crate::tests::start_metasrv().await?;
169170
let client = MetaFlightClient::try_create(addr.as_str(), "root", "xxx").await?;
170171
171172
// create-db operation will increases meta_version

0 commit comments

Comments
 (0)