Skip to content

Commit

Permalink
fix ut (alibaba#1974)
Browse files Browse the repository at this point in the history
  • Loading branch information
Takuka0311 authored Dec 17, 2024
1 parent 5f9ce93 commit 3906305
Show file tree
Hide file tree
Showing 2 changed files with 321 additions and 268 deletions.
36 changes: 18 additions & 18 deletions core/unittest/config/ConfigUpdateUnittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class ConfigUpdateUnittest : public testing::Test {
void SetUp() override {
filesystem::create_directories(configDir);
PipelineConfigWatcher::GetInstance()->AddSource(configDir.string());
#ifdef __ENTERPRISE__
builtinPipelineCnt = EnterpriseConfigProvider::GetInstance()->GetAllBuiltInPipelineConfigs().size();
#endif
}

void TearDown() override {
Expand All @@ -75,6 +78,7 @@ class ConfigUpdateUnittest : public testing::Test {
void PrepareInitialSettings() const;
void GenerateInitialConfigs() const;

size_t builtinPipelineCnt = 0;
filesystem::path configDir = "./continuous_pipeline_config";
vector<filesystem::path> pipelineConfigPaths = {configDir / "pipeline_invalid_format.json",
configDir / "pipeline_invalid_detail.json",
Expand Down Expand Up @@ -236,10 +240,6 @@ class ConfigUpdateUnittest : public testing::Test {

void ConfigUpdateUnittest::OnStartUp() const {
auto diff = PipelineConfigWatcher::GetInstance()->CheckConfigDiff();
size_t builtinPipelineCnt = 0;
#ifdef __ENTERPRISE__
builtinPipelineCnt += EnterpriseConfigProvider::GetInstance()->GetAllBuiltInPipelineConfigs().size();
#endif
APSARA_TEST_EQUAL(0U + builtinPipelineCnt, diff.first.mAdded.size());
APSARA_TEST_TRUE(diff.second.IsEmpty());

Expand All @@ -255,7 +255,7 @@ void ConfigUpdateUnittest::OnStartUp() const {
APSARA_TEST_TRUE(diff.second.mRemoved.empty());

PipelineManagerMock::GetInstance()->UpdatePipelines(diff.first);
APSARA_TEST_EQUAL(1U, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U + builtinPipelineCnt, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
TaskPipelineManager::GetInstance()->UpdatePipelines(diff.second);
APSARA_TEST_EQUAL(1U, TaskPipelineManager::GetInstance()->GetAllPipelineNames().size());
auto& ptr = TaskPipelineManager::GetInstance()->FindPipelineByName("task_enabled_valid");
Expand All @@ -266,7 +266,7 @@ void ConfigUpdateUnittest::OnStartUp() const {

void ConfigUpdateUnittest::OnConfigDelete() const {
PrepareInitialSettings();
APSARA_TEST_EQUAL(1U, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U + builtinPipelineCnt, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U, TaskPipelineManager::GetInstance()->GetAllPipelineNames().size());

filesystem::remove_all(configDir);
Expand All @@ -281,14 +281,14 @@ void ConfigUpdateUnittest::OnConfigDelete() const {
APSARA_TEST_EQUAL(1U, diff.second.mRemoved.size());

PipelineManagerMock::GetInstance()->UpdatePipelines(diff.first);
APSARA_TEST_TRUE(PipelineManagerMock::GetInstance()->GetAllConfigNames().empty());
APSARA_TEST_EQUAL(builtinPipelineCnt, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
TaskPipelineManager::GetInstance()->UpdatePipelines(diff.second);
APSARA_TEST_TRUE(TaskPipelineManager::GetInstance()->GetAllPipelineNames().empty());
}

void ConfigUpdateUnittest::OnConfigToInvalidFormat() const {
PrepareInitialSettings();
APSARA_TEST_EQUAL(1U, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U + builtinPipelineCnt, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U, TaskPipelineManager::GetInstance()->GetAllPipelineNames().size());

for (const auto& path : pipelineConfigPaths) {
Expand All @@ -306,7 +306,7 @@ void ConfigUpdateUnittest::OnConfigToInvalidFormat() const {

void ConfigUpdateUnittest::OnConfigToInvalidDetail() const {
PrepareInitialSettings();
APSARA_TEST_EQUAL(1U, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U + builtinPipelineCnt, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U, TaskPipelineManager::GetInstance()->GetAllPipelineNames().size());

for (const auto& path : pipelineConfigPaths) {
Expand All @@ -328,7 +328,7 @@ void ConfigUpdateUnittest::OnConfigToInvalidDetail() const {
APSARA_TEST_TRUE(diff.second.mRemoved.empty());

PipelineManagerMock::GetInstance()->UpdatePipelines(diff.first);
APSARA_TEST_EQUAL(1U, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U + builtinPipelineCnt, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
auto& ptr = TaskPipelineManager::GetInstance()->FindPipelineByName("task_enabled_valid");
TaskPipelineManager::GetInstance()->UpdatePipelines(diff.second);
APSARA_TEST_EQUAL(1U, TaskPipelineManager::GetInstance()->GetAllPipelineNames().size());
Expand All @@ -340,7 +340,7 @@ void ConfigUpdateUnittest::OnConfigToInvalidDetail() const {

void ConfigUpdateUnittest::OnConfigToEnabledValid() const {
PrepareInitialSettings();
APSARA_TEST_EQUAL(1U, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U + builtinPipelineCnt, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U, TaskPipelineManager::GetInstance()->GetAllPipelineNames().size());

for (const auto& path : pipelineConfigPaths) {
Expand All @@ -362,7 +362,7 @@ void ConfigUpdateUnittest::OnConfigToEnabledValid() const {
APSARA_TEST_TRUE(diff.second.mRemoved.empty());

PipelineManagerMock::GetInstance()->UpdatePipelines(diff.first);
APSARA_TEST_EQUAL(4U, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(4U + builtinPipelineCnt, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
TaskPipelineManager::GetInstance()->UpdatePipelines(diff.second);
APSARA_TEST_EQUAL(4U, TaskPipelineManager::GetInstance()->GetAllPipelineNames().size());
{
Expand Down Expand Up @@ -393,7 +393,7 @@ void ConfigUpdateUnittest::OnConfigToEnabledValid() const {

void ConfigUpdateUnittest::OnConfigToDisabledValid() const {
PrepareInitialSettings();
APSARA_TEST_EQUAL(1U, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U + builtinPipelineCnt, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U, TaskPipelineManager::GetInstance()->GetAllPipelineNames().size());

for (const auto& path : pipelineConfigPaths) {
Expand All @@ -411,14 +411,14 @@ void ConfigUpdateUnittest::OnConfigToDisabledValid() const {
APSARA_TEST_EQUAL(1U, diff.first.mRemoved.size());

PipelineManagerMock::GetInstance()->UpdatePipelines(diff.first);
APSARA_TEST_TRUE(PipelineManagerMock::GetInstance()->GetAllConfigNames().empty());
APSARA_TEST_EQUAL(builtinPipelineCnt, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
TaskPipelineManager::GetInstance()->UpdatePipelines(diff.second);
APSARA_TEST_TRUE(TaskPipelineManager::GetInstance()->GetAllPipelineNames().empty());
}

void ConfigUpdateUnittest::OnConfigUnchanged() const {
PrepareInitialSettings();
APSARA_TEST_EQUAL(1U, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U + builtinPipelineCnt, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U, TaskPipelineManager::GetInstance()->GetAllPipelineNames().size());

auto diff = PipelineConfigWatcher::GetInstance()->CheckConfigDiff();
Expand Down Expand Up @@ -446,7 +446,7 @@ void ConfigUpdateUnittest::OnConfigUnchanged() const {
APSARA_TEST_TRUE(diff.second.mRemoved.empty());

PipelineManagerMock::GetInstance()->UpdatePipelines(diff.first);
APSARA_TEST_EQUAL(1U, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U + builtinPipelineCnt, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
auto& ptr = TaskPipelineManager::GetInstance()->FindPipelineByName("task_enabled_valid");
TaskPipelineManager::GetInstance()->UpdatePipelines(diff.second);
APSARA_TEST_EQUAL(1U, TaskPipelineManager::GetInstance()->GetAllPipelineNames().size());
Expand All @@ -458,7 +458,7 @@ void ConfigUpdateUnittest::OnConfigUnchanged() const {

void ConfigUpdateUnittest::OnConfigAdded() const {
PrepareInitialSettings();
APSARA_TEST_EQUAL(1U, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U + builtinPipelineCnt, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(1U, TaskPipelineManager::GetInstance()->GetAllPipelineNames().size());

{
Expand Down Expand Up @@ -504,7 +504,7 @@ void ConfigUpdateUnittest::OnConfigAdded() const {
APSARA_TEST_TRUE(diff.second.mRemoved.empty());

PipelineManagerMock::GetInstance()->UpdatePipelines(diff.first);
APSARA_TEST_EQUAL(2U, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
APSARA_TEST_EQUAL(2U + builtinPipelineCnt, PipelineManagerMock::GetInstance()->GetAllConfigNames().size());
auto& ptr = TaskPipelineManager::GetInstance()->FindPipelineByName("task_enabled_valid");
TaskPipelineManager::GetInstance()->UpdatePipelines(diff.second);
APSARA_TEST_EQUAL(2U, TaskPipelineManager::GetInstance()->GetAllPipelineNames().size());
Expand Down
Loading

0 comments on commit 3906305

Please sign in to comment.