Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix CommonConfigProviderUnittest #2020

Merged
merged 5 commits into from
Jan 10, 2025
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions core/unittest/config/CommonConfigProviderUnittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@
// limitations under the License.


#include "json/json.h"
#include <json/json.h>
quzard marked this conversation as resolved.
Show resolved Hide resolved

#include "AppConfig.h"
#include "common/FileSystemUtil.h"
#include "common/version.h"
#include "config/ConfigDiff.h"
#include "config/InstanceConfigManager.h"
#include "config/common_provider/CommonConfigProvider.h"
#ifdef __ENTERPRISE__
#include "config/provider/EnterpriseConfigProvider.h"
#endif
#include "config/watcher/InstanceConfigWatcher.h"
#include "config/watcher/PipelineConfigWatcher.h"
#include "file_server/FileServer.h"
#include "gmock/gmock.h"
#include "monitor/Monitor.h"
#include "pipeline/PipelineManager.h"
#include "unittest/Unittest.h"
#ifdef __ENTERPRISE__
#include "config/provider/EnterpriseConfigProvider.h"
#endif

DECLARE_FLAG_BOOL(logtail_mode);

Expand Down Expand Up @@ -470,14 +470,22 @@ void CommonConfigProviderUnittest::TestGetConfigUpdateAndConfigWatcher() {
APSARA_TEST_TRUE(!instanceConfigDiff.IsEmpty());
APSARA_TEST_EQUAL(1U, instanceConfigDiff.mAdded.size());
APSARA_TEST_EQUAL(instanceConfigDiff.mAdded[0].mConfigName, "instanceconfig1");
APSARA_TEST_EQUAL(InstanceConfigManager::GetInstance()->GetAllConfigNames().size(), 2);
if (BOOL_FLAG(logtail_mode)) {
APSARA_TEST_EQUAL(InstanceConfigManager::GetInstance()->GetAllConfigNames().size(), 1);
} else {
APSARA_TEST_EQUAL(InstanceConfigManager::GetInstance()->GetAllConfigNames().size(), 2);
}
APSARA_TEST_EQUAL(InstanceConfigManager::GetInstance()->GetAllConfigNames()[0], "instanceconfig1");
// 再次处理 instanceconfig
instanceConfigDiff = InstanceConfigWatcher::GetInstance()->CheckConfigDiff();
InstanceConfigManager::GetInstance()->UpdateInstanceConfigs(instanceConfigDiff);
APSARA_TEST_TRUE(instanceConfigDiff.IsEmpty());
APSARA_TEST_TRUE(instanceConfigDiff.mAdded.empty());
APSARA_TEST_EQUAL(InstanceConfigManager::GetInstance()->GetAllConfigNames().size(), 2);
if (BOOL_FLAG(logtail_mode)) {
APSARA_TEST_EQUAL(InstanceConfigManager::GetInstance()->GetAllConfigNames().size(), 1);
} else {
APSARA_TEST_EQUAL(InstanceConfigManager::GetInstance()->GetAllConfigNames().size(), 2);
}
APSARA_TEST_EQUAL(InstanceConfigManager::GetInstance()->GetAllConfigNames()[0], "instanceconfig1");

provider.Stop();
Expand Down Expand Up @@ -681,14 +689,24 @@ void CommonConfigProviderUnittest::TestGetConfigUpdateAndConfigWatcher() {
// 处理instanceConfigDiff
InstanceConfigDiff instanceConfigDiff = InstanceConfigWatcher::GetInstance()->CheckConfigDiff();
InstanceConfigManager::GetInstance()->UpdateInstanceConfigs(instanceConfigDiff);
APSARA_TEST_TRUE(!InstanceConfigManager::GetInstance()->GetAllConfigNames().empty());
if (BOOL_FLAG(logtail_mode)) {
APSARA_TEST_EQUAL(InstanceConfigManager::GetInstance()->GetAllConfigNames().size(), 0);
} else {
APSARA_TEST_EQUAL(InstanceConfigManager::GetInstance()->GetAllConfigNames().size(), 1);
APSARA_TEST_EQUAL(InstanceConfigManager::GetInstance()->GetAllConfigNames()[0], "loongcollector_config");
}
APSARA_TEST_EQUAL(1U, instanceConfigDiff.mRemoved.size());
APSARA_TEST_EQUAL(instanceConfigDiff.mRemoved[0], "instanceconfig1");

// 再次处理instanceConfigDiff
instanceConfigDiff = InstanceConfigWatcher::GetInstance()->CheckConfigDiff();
InstanceConfigManager::GetInstance()->UpdateInstanceConfigs(instanceConfigDiff);
APSARA_TEST_TRUE(!InstanceConfigManager::GetInstance()->GetAllConfigNames().empty());
if (BOOL_FLAG(logtail_mode)) {
APSARA_TEST_EQUAL(InstanceConfigManager::GetInstance()->GetAllConfigNames().size(), 0);
} else {
APSARA_TEST_EQUAL(InstanceConfigManager::GetInstance()->GetAllConfigNames().size(), 1);
APSARA_TEST_EQUAL(InstanceConfigManager::GetInstance()->GetAllConfigNames()[0], "loongcollector_config");
}
APSARA_TEST_TRUE(instanceConfigDiff.IsEmpty());
APSARA_TEST_TRUE(instanceConfigDiff.mRemoved.empty());

Expand Down
Loading