2222#include < gen_cpp/Types_types.h>
2323#include < glog/logging.h>
2424#include < gtest/gtest.h>
25+ #include < unistd.h>
2526
27+ #include < chrono>
2628#include < cmath>
27- #include < cstdlib >
29+ #include < filesystem >
2830#include < memory>
31+ #include < sstream>
2932
3033#include " common/config.h"
3134#include " common/status.h"
@@ -44,10 +47,22 @@ class WorkloadGroupManagerTest : public testing::Test {
4447protected:
4548 void SetUp () override {
4649 _wg_manager = std::make_unique<WorkloadGroupMgr>();
47- EXPECT_EQ (system (" rm -rf ./wg_test_run && mkdir -p ./wg_test_run" ), 0 );
50+ // generate a unique test directory to avoid conflicts between parallel runs
51+ std::ostringstream _oss;
52+ _oss << " ./wg_test_run_" << std::chrono::system_clock::now ().time_since_epoch ().count ()
53+ << " _" << getpid ();
54+ _test_dir = _oss.str ();
55+
56+ std::error_code ec;
57+ std::filesystem::remove_all (_test_dir, ec);
58+ if (ec) {
59+ FAIL () << " Failed to remove " << _test_dir << " : " << ec.message ();
60+ }
61+ std::filesystem::create_directories (_test_dir, ec);
62+ ASSERT_FALSE (ec) << " Failed to create " << _test_dir << " : " << ec.message ();
4863
4964 std::vector<doris::StorePath> paths;
50- std::string path = std::filesystem::absolute (" ./wg_test_run " ).string ();
65+ std::string path = std::filesystem::absolute (_test_dir ).string ();
5166 auto olap_res = doris::parse_conf_store_paths (path, &paths);
5267 EXPECT_TRUE (olap_res.ok ()) << olap_res.to_string ();
5368
@@ -76,7 +91,9 @@ class WorkloadGroupManagerTest : public testing::Test {
7691 ExecEnv::GetInstance ()->_runtime_query_statistics_mgr ->stop_report_thread ();
7792 SAFE_DELETE (ExecEnv::GetInstance ()->_runtime_query_statistics_mgr );
7893
79- EXPECT_EQ (system (" rm -rf ./wg_test_run" ), 0 );
94+ std::error_code ec;
95+ std::filesystem::remove_all (_test_dir, ec);
96+ EXPECT_FALSE (ec) << " Failed to remove " << _test_dir << " : " << ec.message ();
8097 config::spill_in_paused_queue_timeout_ms = _spill_in_paused_queue_timeout_ms;
8198 doris::ExecEnv::GetInstance ()->set_memtable_memory_limiter (nullptr );
8299 }
@@ -115,6 +132,7 @@ class WorkloadGroupManagerTest : public testing::Test {
115132 }
116133
117134 std::unique_ptr<WorkloadGroupMgr> _wg_manager;
135+ std::string _test_dir;
118136 const int64_t _spill_in_paused_queue_timeout_ms = config::spill_in_paused_queue_timeout_ms;
119137};
120138
0 commit comments