From 7704fddb28d6d74004fbf9ea1c94bbe5393beb9a Mon Sep 17 00:00:00 2001 From: evenyag Date: Mon, 31 Jul 2023 20:25:34 +0800 Subject: [PATCH] test: add TestEnv::new --- src/mito2/src/engine/tests.rs | 13 ++++--------- src/mito2/src/manifest/manager.rs | 6 +++--- src/mito2/src/test_util.rs | 9 ++++++++- src/mito2/src/worker.rs | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/mito2/src/engine/tests.rs b/src/mito2/src/engine/tests.rs index 18b8d076ef02..5bd934abbcdd 100644 --- a/src/mito2/src/engine/tests.rs +++ b/src/mito2/src/engine/tests.rs @@ -22,7 +22,7 @@ use crate::test_util::{CreateRequestBuilder, TestEnv}; #[tokio::test] async fn test_engine_new_stop() { - let env = TestEnv::new("engine-stop"); + let env = TestEnv::with_prefix("engine-stop"); let engine = env.create_engine(MitoConfig::default()).await; engine.stop().await.unwrap(); @@ -37,7 +37,7 @@ async fn test_engine_new_stop() { #[tokio::test] async fn test_engine_create_new_region() { - let env = TestEnv::new("new-region"); + let env = TestEnv::with_prefix("new-region"); let engine = env.create_engine(MitoConfig::default()).await; let region_id = RegionId::new(1, 1); @@ -49,7 +49,7 @@ async fn test_engine_create_new_region() { #[tokio::test] async fn test_engine_create_region_if_not_exists() { - let env = TestEnv::new("create-not-exists"); + let env = TestEnv::with_prefix("create-not-exists"); let engine = env.create_engine(MitoConfig::default()).await; let builder = CreateRequestBuilder::new(RegionId::new(1, 1)).create_if_not_exists(true); @@ -61,7 +61,7 @@ async fn test_engine_create_region_if_not_exists() { #[tokio::test] async fn test_engine_create_existing_region() { - let env = TestEnv::new("create-existing"); + let env = TestEnv::with_prefix("create-existing"); let engine = env.create_engine(MitoConfig::default()).await; let builder = CreateRequestBuilder::new(RegionId::new(1, 1)); @@ -74,8 +74,3 @@ async fn test_engine_create_existing_region() { "unexpected err: {err}" ); } - -#[tokio::test] -async fn test_engine_open_empty() { - let env = TestEnv::new("open-empty"); -} diff --git a/src/mito2/src/manifest/manager.rs b/src/mito2/src/manifest/manager.rs index 40d90ed0f417..e7e719b20724 100644 --- a/src/mito2/src/manifest/manager.rs +++ b/src/mito2/src/manifest/manager.rs @@ -377,7 +377,7 @@ mod test { #[tokio::test] async fn create_manifest_manager() { let metadata = Arc::new(basic_region_metadata()); - let env = TestEnv::new(""); + let env = TestEnv::new(); let manager = env .create_manifest_manager(CompressionType::Uncompressed, 10, Some(metadata.clone())) .await @@ -389,7 +389,7 @@ mod test { #[tokio::test] async fn open_manifest_manager() { - let env = TestEnv::new(""); + let env = TestEnv::new(); // Try to opens an empty manifest. assert!(env .create_manifest_manager(CompressionType::Uncompressed, 10, None) @@ -420,7 +420,7 @@ mod test { #[tokio::test] async fn region_change_add_column() { let metadata = Arc::new(basic_region_metadata()); - let env = TestEnv::new(""); + let env = TestEnv::new(); let manager = env .create_manifest_manager(CompressionType::Uncompressed, 10, Some(metadata.clone())) .await diff --git a/src/mito2/src/test_util.rs b/src/mito2/src/test_util.rs index 71244f6a1945..e6f6247fa375 100644 --- a/src/mito2/src/test_util.rs +++ b/src/mito2/src/test_util.rs @@ -43,8 +43,15 @@ pub struct TestEnv { } impl TestEnv { + /// Returns a new env with empty prefix for test. + pub fn new() -> TestEnv { + TestEnv { + data_home: create_temp_dir(""), + } + } + /// Returns a new env with specific `prefix` for test. - pub fn new(prefix: &str) -> TestEnv { + pub fn with_prefix(prefix: &str) -> TestEnv { TestEnv { data_home: create_temp_dir(prefix), } diff --git a/src/mito2/src/worker.rs b/src/mito2/src/worker.rs index a2fd326f7dba..200f1131bd66 100644 --- a/src/mito2/src/worker.rs +++ b/src/mito2/src/worker.rs @@ -400,7 +400,7 @@ mod tests { #[tokio::test] async fn test_worker_group_start_stop() { - let env = TestEnv::new("group-stop"); + let env = TestEnv::with_prefix("group-stop"); let group = env .create_worker_group(MitoConfig { num_workers: 4,