Skip to content

Commit bf17bcd

Browse files
authored
chore: refine the unit test framework (#13902)
* chore: refine the unit test framework * TestFixture new and destroy * add Drop for TestFixture * try change to let _fixture * Drop session first * do nothing for the teardown of TestFixture * rename TestFixture create -> setup * add singleton drop in TestFixture drop * revert to TestGuard * fix storage fs local path to default in system unit test * global service InnerConfig -> &InnerConfig * try to remove create random database in the TestFixture init * create default database to some fuse engine unit test * fix some unit test forgot to create default database * fix test_last_snapshot_hintsome unit test
1 parent 3111235 commit bf17bcd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+837
-731
lines changed

Cargo.lock

Lines changed: 137 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/setup/dev_setup.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,8 @@ if [[ "$INSTALL_BUILD_TOOLS" == "true" ]]; then
533533
cargo quickinstall cargo-binstall
534534
cargo binstall -y sccache
535535
cargo binstall -y cargo-zigbuild
536+
cargo install cargo-nextest
537+
536538
fi
537539

538540
if [[ "$INSTALL_CHECK_TOOLS" == "true" ]]; then

src/bendpy/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn databend(_py: Python, m: &PyModule) -> PyResult<()> {
5454
MetaEmbedded::init_global_meta_store(meta_dir.to_string_lossy().to_string())
5555
.await
5656
.unwrap();
57-
GlobalServices::init(conf.clone()).await.unwrap();
57+
GlobalServices::init(&conf).await.unwrap();
5858

5959
// init oss license manager
6060
OssLicenseManager::init(conf.query.tenant_id.clone()).unwrap();

src/binaries/query/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub async fn init_services(conf: &InnerConfig) -> Result<()> {
7878
));
7979
}
8080
// Make sure global services have been inited.
81-
GlobalServices::init(conf.clone()).await
81+
GlobalServices::init(conf).await
8282
}
8383

8484
async fn precheck_services(conf: &InnerConfig) -> Result<()> {

src/binaries/tool/table_meta_inspector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async fn parse_input_data(config: &InspectorConfig) -> Result<Vec<u8>> {
8787
builder = builder.collect(from_file(Toml, config_file));
8888
let read_config = builder.build()?;
8989
let inner_config: InnerConfig = read_config.clone().try_into()?;
90-
GlobalServices::init(inner_config).await?;
90+
GlobalServices::init(&inner_config).await?;
9191
let storage_config: StorageConfig = read_config.storage.try_into()?;
9292
init_operator(&storage_config.params)?
9393
}

src/query/config/src/global.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use crate::InnerConfig;
2222
pub struct GlobalConfig;
2323

2424
impl GlobalConfig {
25-
pub fn init(config: InnerConfig) -> Result<()> {
26-
GlobalInstance::set(Arc::new(config));
25+
pub fn init(config: &InnerConfig) -> Result<()> {
26+
GlobalInstance::set(Arc::new(config.clone()));
2727
Ok(())
2828
}
2929

src/query/ee/src/test_kits/context.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ use common_meta_app::storage::StorageFsConfig;
1919
use common_meta_app::storage::StorageParams;
2020
use databend_query::test_kits::ConfigBuilder;
2121
use databend_query::test_kits::Setup;
22-
use databend_query::test_kits::TestGuard;
2322
use jwt_simple::algorithms::ECDSAP256KeyPairLike;
2423
use jwt_simple::prelude::Claims;
2524
use jwt_simple::prelude::Duration;
2625
use jwt_simple::prelude::ES256KeyPair;
2726
use tempfile::TempDir;
2827

29-
use crate::test_kits::sessions::TestGlobalServices;
28+
use crate::test_kits::setup::TestFixture;
3029

3130
fn build_custom_claims(license_type: String, org: String) -> LicenseInfo {
3231
LicenseInfo {
@@ -74,10 +73,8 @@ impl Default for EESetup {
7473

7574
#[async_trait::async_trait]
7675
impl Setup for EESetup {
77-
async fn setup(&self) -> Result<(TestGuard, InnerConfig)> {
78-
Ok((
79-
TestGlobalServices::setup(&self.config, self.pk.clone()).await?,
80-
self.config.clone(),
81-
))
76+
async fn setup(&self) -> Result<InnerConfig> {
77+
TestFixture::setup(&self.config, self.pk.clone()).await?;
78+
Ok(self.config.clone())
8279
}
8380
}

src/query/ee/src/test_kits/mock_services.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::virtual_column::RealVirtualColumnHandler;
2929
pub struct MockServices;
3030
impl MockServices {
3131
#[async_backtrace::framed]
32-
pub async fn init(cfg: InnerConfig, public_key: String) -> Result<()> {
32+
pub async fn init(cfg: &InnerConfig, public_key: String) -> Result<()> {
3333
let rm = RealLicenseManager::new(cfg.query.tenant_id.clone(), public_key);
3434
let wrapper = LicenseManagerWrapper {
3535
manager: Box::new(rm),

src/query/ee/src/test_kits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
pub mod context;
1616
pub mod mock_services;
17-
pub mod sessions;
17+
pub mod setup;

src/query/ee/src/test_kits/sessions.rs renamed to src/query/ee/src/test_kits/setup.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,25 @@ use common_config::InnerConfig;
1616
use common_exception::Result;
1717
use common_tracing::set_panic_hook;
1818
use databend_query::clusters::ClusterDiscovery;
19-
use databend_query::test_kits::TestGuard;
2019
use databend_query::GlobalServices;
2120
use log::info;
2221

2322
use crate::test_kits::mock_services::MockServices;
2423

25-
pub struct TestGlobalServices;
24+
pub struct TestFixture;
2625

27-
unsafe impl Send for TestGlobalServices {}
28-
29-
unsafe impl Sync for TestGlobalServices {}
30-
31-
impl TestGlobalServices {
32-
pub async fn setup(config: &InnerConfig, public_key: String) -> Result<TestGuard> {
26+
impl TestFixture {
27+
pub async fn setup(config: &InnerConfig, public_key: String) -> Result<()> {
3328
set_panic_hook();
3429
std::env::set_var("UNIT_TEST", "TRUE");
3530

36-
let thread_name = match std::thread::current().name() {
37-
None => panic!("thread name is none"),
38-
Some(thread_name) => thread_name.to_string(),
39-
};
31+
let thread_name = std::thread::current().name().unwrap().to_string();
4032

4133
#[cfg(debug_assertions)]
4234
common_base::base::GlobalInstance::init_testing(&thread_name);
4335

44-
GlobalServices::init_with(config.clone()).await?;
45-
MockServices::init(config.clone(), public_key).await?;
36+
GlobalServices::init_with(config).await?;
37+
MockServices::init(config, public_key).await?;
4638

4739
// Cluster register.
4840
{
@@ -55,6 +47,13 @@ impl TestGlobalServices {
5547
);
5648
}
5749

58-
Ok(TestGuard::new(thread_name.to_string()))
50+
Ok(())
51+
}
52+
53+
/// Teardown the test environment.
54+
pub async fn teardown() -> Result<()> {
55+
// Nothing to do.
56+
57+
Ok(())
5958
}
6059
}

0 commit comments

Comments
 (0)